Skip to content

Commit 3e60fec

Browse files
shivamhwpPR Batch Testerclaude
authored
fix(desktop): markdown pages no longer render invisible in the dark-mode browser (pingdotgg#14601)
Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 2731929 commit 3e60fec

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎apps/desktop/src/preview/Manager.test.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ describe("PreviewManager", () => {
16011601
),
16021602
);
16031603

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

1653+
// Guests start with a transparent base; dark-scheme pages need an opaque
1654+
// one or Chromium skips their dark canvas.
1655+
const opaqueBase = {
1656+
color: { r: 255, g: 255, b: 255, a: 1 },
1657+
};
1658+
expect(first.sendCommand).toHaveBeenCalledWith(
1659+
"Emulation.setDefaultBackgroundColorOverride",
1660+
opaqueBase,
1661+
);
1662+
16531663
yield* manager.setColorScheme("tab_scheme", "dark");
16541664

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

1675+
expect(replacement.sendCommand).toHaveBeenCalledWith(
1676+
"Emulation.setDefaultBackgroundColorOverride",
1677+
opaqueBase,
1678+
);
16651679
expect(replacement.sendCommand).toHaveBeenCalledWith("Emulation.setEmulatedMedia", {
16661680
features: [{ name: "prefers-color-scheme", value: "dark" }],
16671681
});

‎apps/desktop/src/preview/Manager.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,19 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
14181418
),
14191419
{ concurrency: "unbounded", discard: true },
14201420
);
1421+
// Electron gives `<webview>` guests a transparent base background, and
1422+
// Chromium only paints a dark canvas for dark color-scheme pages over an
1423+
// opaque base. Without this, dark-scheme pages with no background of
1424+
// their own (text/plain, e.g. .md files) render white text on white.
1425+
// White matches the webview's existing white backing, so light pages look
1426+
// the same; Chromium still swaps in its dark canvas for dark-scheme pages.
1427+
yield* attemptPromise(
1428+
{ operation: "initializeDebugger.defaultBackground", webContentsId: wc.id },
1429+
() =>
1430+
wcDebugger.sendCommand("Emulation.setDefaultBackgroundColorOverride", {
1431+
color: { r: 255, g: 255, b: 255, a: 1 },
1432+
}),
1433+
);
14211434
return [
14221435
control,
14231436
replaceMap(sessions, (copy) => {

0 commit comments

Comments
 (0)