Skip to content

fix(browser): give CDP-attached guests an opaque base background - #11192

Closed
iamcardimage wants to merge 2 commits into
stablyai:mainfrom
iamcardimage:fix/browser-dark-scheme-guest-background
Closed

iamcardimage wants to merge 2 commits into
stablyai:mainfrom
iamcardimage:fix/browser-dark-scheme-guest-background

Conversation

@iamcardimage

@iamcardimage iamcardimage commented Jul 28, 2026 •

Copy link
Copy Markdown

Fixes #11190.

Summary

application/json responses rendered as a blank white page in the embedded browser with the dark theme. Chromium's JSON viewer document declares color-scheme: light dark, so its text goes white in dark mode, but it paints no background. Webview guests have a transparent base background and the pane forces a white CSS fallback, so the page came out white-on-white. Details and repro in the issue.

This adds Emulation.setDefaultBackgroundColorOverride (opaque white) where the guest debugger gets bootstrapped: injectAntiDetection in browser-manager, plus cdp-bridge and cdp-ws-proxy so the override survives takeovers, same way ANTI_DETECTION_SCRIPT is kept alive. With an opaque base Blink picks the canvas color per document color scheme: JSON pages get a dark canvas in dark mode, CSS-less pages keep the white one. The white CSS fallback on the <webview> element stays for guests where debugger.attach fails (DevTools open).

Screenshots

Before/after screenshots are in #11190: the blank white page vs a dark canvas with readable JSON, plus a CSS-less page that keeps its white background with the fix applied.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test — ran the affected suite vitest run src/main/browser/: 526 passed. Updated command-sequence expectations in cdp-ws-proxy.test.ts / cdp-ws-proxy-focus-replay.test.ts; the cdp-bridge-integration.test.ts mock now handles the new command and rejects an out-of-range RGBA alpha so it can't regress
  • pnpm build
  • Behavior check in a standalone Electron 43.1.0 repro: JSON page → dark canvas + white text; plain no-CSS page → white canvas + black text

AI Review Report

Ran an AI-assisted review of the change. Risks checked: regressions for pages that paint no background (the case the white CSS fallback was originally added for) — verified a CSS-less page still renders white with black text; override survival across bridge/proxy debugger takeovers — the override is installed at all three bootstrap sites, mirroring how ANTI_DETECTION_SCRIPT is kept alive; behavior when no debugger can attach (DevTools open) — the CSS fallback keeps today's behavior for that guest. The review also flagged an out-of-spec RGBA alpha (a: 255 instead of the 0–1 float the protocol defines), fixed to a: 1. Cross-platform: the change is a CDP command with a constant payload — no shortcuts, labels, paths, or shell behavior involved; the call sites are shared (not platform-gated) code, so macOS/Linux/Windows behave the same, and headless orca serve gets the same override through cdp-bridge / cdp-ws-proxy.

Security Audit

No input handling, command execution, path handling, auth, secrets, or dependency changes. The added CDP command sends a constant color payload to already-attached debugger sessions over the existing internal channel; no page- or user-controlled data flows into it. IPC surfaces are unchanged.

Notes

  • The override only applies while a debugger is attached. If debugger.attach fails (e.g. DevTools open on the tab), the white CSS fallback preserves the current behavior for that guest.
  • pnpm build was not run locally; the change is main-process/renderer TypeScript only, no build-config or asset changes.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Debugger attachment flows now issue Emulation.setDefaultBackgroundColorOverride with an opaque white color after anti-detection script injection. CDP mocks and proxy tests were updated to account for the additional initialization command across focus replay, lifecycle priming, navigation, reload, and evaluation scenarios. The guest webview background rationale comment was also revised.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes match #11190 by adding the CDP background override where guests are attached and preserving the fallback behavior.
Out of Scope Changes check ✅ Passed The changes are focused on the browser background fix and supporting tests/comments, with no clear unrelated additions.
Title check ✅ Passed The title is concise, specific, and matches the main change: adding an opaque base background for CDP-attached guests.
Description check ✅ Passed The description covers all required sections with substantive details, including summary, screenshots, testing, review, security, and notes.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/browser/cdp-bridge-integration.test.ts (1)

178-179: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Validate the new CDP payload in the mock.

Returning {} unconditionally lets an out-of-range alpha pass unnoticed. Assert a: 1 here so this test catches the production regression. CDP 1.3 defines alpha in [0, 1]. (chromedevtools.github.io)


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2b5fd4a3-5e04-4f17-912d-56e23daa93d5

📥 Commits

Reviewing files that changed from the base of the PR and between 0404f27 and 3e0ea92.

📒 Files selected for processing (7)
  • src/main/browser/browser-manager.ts
  • src/main/browser/cdp-bridge-integration.test.ts
  • src/main/browser/cdp-bridge.ts
  • src/main/browser/cdp-ws-proxy-focus-replay.test.ts
  • src/main/browser/cdp-ws-proxy.test.ts
  • src/main/browser/cdp-ws-proxy.ts
  • src/renderer/src/components/browser-pane/browser-page-webview.ts

Comment thread src/main/browser/cdp-bridge.ts Resolved
@AmoabaKelvin

Copy link
Copy Markdown
Collaborator

Thanks for digging into this and for the clear write-up in #11190. We're closing this in favour of #32975.

Browser tabs already show JSON and plain-text pages properly on main. #18738 (shipped in v1.4.198) made the page's background opaque with a webview setting, and Chromium then draws its dark background for dark-scheme pages. That gives the same result as Emulation.setDefaultBackgroundColorOverride without attaching a debugger to every page. #32975 applies the same setting to the last place still showing white text on white, the HTML doc preview.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: JSON responses show up as a blank white page in the embedded browser (dark theme)

3 participants