Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion apps/desktop/src/preview/Manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ describe("PreviewManager", () => {
),
);

effectIt.effect("emulates prefers-color-scheme and re-applies it across webview swaps", () =>
effectIt.effect("re-applies opaque base and color scheme across webview swaps", () =>
withManager((manager) =>
Effect.gen(function* () {
const makeWebContents = (id: number) => {
Expand Down Expand Up @@ -1650,6 +1650,16 @@ describe("PreviewManager", () => {
yield* manager.registerWebview("tab_scheme", 42);
yield* Effect.yieldNow;

// Guests start with a transparent base; dark-scheme pages need an opaque
// one or Chromium skips their dark canvas.
const opaqueBase = {
color: { r: 255, g: 255, b: 255, a: 1 },
};
expect(first.sendCommand).toHaveBeenCalledWith(
"Emulation.setDefaultBackgroundColorOverride",
opaqueBase,
);

yield* manager.setColorScheme("tab_scheme", "dark");

expect(first.sendCommand).toHaveBeenCalledWith("Emulation.setEmulatedMedia", {
Expand All @@ -1662,6 +1672,10 @@ describe("PreviewManager", () => {
yield* manager.registerWebview("tab_scheme", 43);
yield* Effect.yieldNow;

expect(replacement.sendCommand).toHaveBeenCalledWith(
"Emulation.setDefaultBackgroundColorOverride",
opaqueBase,
);
expect(replacement.sendCommand).toHaveBeenCalledWith("Emulation.setEmulatedMedia", {
features: [{ name: "prefers-color-scheme", value: "dark" }],
});
Expand Down
13 changes: 13 additions & 0 deletions apps/desktop/src/preview/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,19 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
),
{ concurrency: "unbounded", discard: true },
);
// Electron gives `<webview>` guests a transparent base background, and
// Chromium only paints a dark canvas for dark color-scheme pages over an
// opaque base. Without this, dark-scheme pages with no background of
// their own (text/plain, e.g. .md files) render white text on white.
// White matches the webview's existing white backing, so light pages look
// the same; Chromium still swaps in its dark canvas for dark-scheme pages.
yield* attemptPromise(
Comment thread
shivamhwp marked this conversation as resolved.
{ operation: "initializeDebugger.defaultBackground", webContentsId: wc.id },
() =>
wcDebugger.sendCommand("Emulation.setDefaultBackgroundColorOverride", {
color: { r: 255, g: 255, b: 255, a: 1 },
Comment thread
shivamhwp marked this conversation as resolved.
}),
);
return [
control,
replaceMap(sessions, (copy) => {
Expand Down
Loading