Skip to content

fix(browser): render serve pages offscreen so headless screenshots show the page - #42676

Merged
AmoabaKelvin merged 8 commits into
mainfrom
fix/serve-page-blank-screenshots
Nov 15, 2026
Merged

AmoabaKelvin merged 8 commits into
mainfrom
fix/serve-page-blank-screenshots

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Carries over #26139 by @oliver-mee.

ELI5

On a headless Linux server, orca serve browser pages loaded fine, but their screenshots came back as a 1x1 image or a frame of one solid colour. Server pages now render offscreen, so they draw without a window on screen. Captures show the page again, and an animated page costs less than before.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​5

What Changed

  • @oliver-mee's fix: serve pages (OffscreenBrowserBackend) are created with webPreferences.offscreen: true.
  • On top: webContents.stopPainting() right after creation. Nothing in Orca reads Electron's offscreen paint frames, because CDP captures and screencasts copy straight from the compositor. Left on, Electron copies every animation frame into the main process.
  • An offscreen page reports getType() === 'offscreen', so the extension observer (browser-extension-startup.ts) now accepts that type too. Without it, serve pages with extensions enabled would lose webNavigation events and DNR frame state. The trusted-renderer checks that require 'window' keep excluding serve pages, as they should.
  • Their real-Electron capture test is removed. CI doesn't run it (.electron.test.ts files are listed in the workflow), and on macOS it passes with or without the fix. Their lifecycle test that asserted the preference was a constant check, and it was dropped when the file moved.

Why

A hidden native window on a headless X display has no surface to present to. Reporters saw XGetWindowAttributes failed from the software presenter, and the page's layers were never drawn into what the capture reads. Three reporters measured the same result on 1.4.219 to 1.4.247: offscreen rendering fixed every capture, and a plain hidden window did not.

Offscreen rendering is the root fix: the page no longer depends on a native window to draw. Mapping the window with showInactive() also worked on a private Xvfb, but that would pop real windows onto any desktop that runs orca serve.

Measured on macOS, 5 hidden serve-style windows each showing a CSS + requestAnimationFrame animation, averaged over 20 s:

Mode CPU (all processes) Memory (working set)
hidden window (main today) 3.7% 867 MB
offscreen, painting (#26139 as is) 3.4% 2,880 MB (2,184 MB in the browser process)
offscreen + stopPainting() (this PR) 1.5% 791 MB

With painting stopped, Page.captureScreenshot, CDP mouse clicks and text input, and Page.startScreencast frames all still work. The stopped state also survives cross-site navigations (new renderer processes), reloads and a renderer crash.

Linked Issue

Fixes #26138

Visual Proof

N/A. There's no UI change. The capture evidence is the reporters' before/after images in #26139 and #26138, plus the measurements above.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

  • I wrote a Linux e2e (real orca serve on Xvfb, browser.tabCreate, then pixel checks on browser.screenshot and browser.fullScreenshot) and ran it on Ubuntu through the E2E workflow. With this change it passed (run), so offscreen pages with painting stopped capture correctly on Linux. On origin/main it also passed, 10 of 10 captures right after load (run), so CI's Xvfb doesn't reproduce the reporters' failure. Because a test that passes without the fix proves nothing, it isn't included.

  • A standalone Electron 43.8.7 harness on macOS measured the cost table above. It also checked captures, input, screencast frames and that the paint state survives navigation.

  • offscreen-browser-backend-lifecycle.test.ts still passes. Its mock gained stopPainting.

Risk

Serve pages now render offscreen on every platform. On a macOS or Windows orca serve, pages render at device scale factor 1 instead of the display's scale. orca screenshot already returns CSS pixels, so only orca full-screenshot on such a host gets lower resolution. Phone screencasts are scaled to the phone either way. Offscreen windows can also deliver the very first CDP click after a cold load slightly late: 1 of 9 local runs missed a click right after load, and none did with a short settle. Desktop <webview> tabs are untouched. To back it out, revert the PR.

Level: Medium

AI Disclosure

Review

Two review-loop rounds. In round 1, Codex found that the extension observer rejected the new offscreen type (fixed). Round 2 came back clean from both reviewers. They checked every getType() branch, the capture and screencast routes, agent input, popups (which inherit only security preferences, not offscreen) and the lifecycle.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The offscreen browser backend now enables offscreen rendering for its hidden browser windows and calls stopPainting() after window creation. The lifecycle test double adds a no-op stopPainting() method. The browser extension startup observer now accepts offscreen contents alongside webview and window contents. Existing filters remain unchanged.

Severity of issue fixed: Medium

Merge Risk: Low · up to b672d

Serve pages now render offscreen to fix blank Linux screenshots. External CDP clients that use synthetic scroll gestures on serve tabs may find them failing or ineffective. Orca's own input is unaffected. The risk is narrow and bounded, so follow-up is advisable.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: serve pages now render offscreen so headless screenshots show the page. It follows the conventional commit form and matches the objectives and the offscreen backend, e…
Description check Passed The description follows the template closely. It has ELI5, What Changed, Why, Linked Issue (Fixes #26138), Visual Proof marked N/A with a reason, Testing with checkboxes and detail, Risk with a level …
Linked Issues check Passed Directly linked issue #26138 requires genuine offscreen rendering for default headless server pages, while keeping hidden windows, the profile partition, sandbox, context isolation, and disabled Node …
Out of Scope Changes check Passed All changed files relate to the offscreen serve-page fix for #26138. The offscreen-browser-backend.ts change adds the offscreen preference and stopPainting() to the same window creation path. The brow…
Full details: Title check

Explanation

The title names the main change: serve pages now render offscreen so headless screenshots show the page. It follows the conventional commit form and matches the objectives and the offscreen backend, extension observer, and test changes in the summary. It is a single, specific sentence with no file lists or vague terms.

Full details: Description check

Explanation

The description follows the template closely. It has ELI5, What Changed, Why, Linked Issue (Fixes #26138), Visual Proof marked N/A with a reason, Testing with checkboxes and detail, Risk with a level and a backout plan, AI Disclosure, Review, the upstream boundary checkbox, Notes, and Checklist. The Risk section names the riskiest parts (device scale factor on macOS/Windows, first CDP click timing). The AI Disclosure section is left empty, which the template allows for maintainers, but the author's team status is not stated. The Notes section does not explicitly say that security, cross-platform, mobile, and performance concerns were checked, though it covers SSH, mobile, and cross-platform points. These are minor gaps.

Full details: Linked Issues check

Explanation

Directly linked issue #26138 requires genuine offscreen rendering for default headless server pages, while keeping hidden windows, the profile partition, sandbox, context isolation, and disabled Node integration. The diff to src/main/browser/backends/offscreen-browser-backend.ts adds offscreen: true to the BrowserWindow webPreferences. The existing partition, sandbox: true, contextIsolation: true, and nodeIntegration: false entries appear unchanged in the same hunk. The PR does not change the hidden-window path. The PR also calls webContents.stopPainting() after creation. That call does not conflict with the issue. The extension observer change in src/main/browser/extensions/browser-extension-startup.ts accepts the new 'offscreen' type so serve pages keep extension events. The reproduction and the capture evidence in the PR description support the fix. Limit: the PR removes the real-Electron capture test and the lifecycle test that asserted the preference. No automated test in the reviewed diff now checks the offscreen preference. The issue does not list a test as an explicit acceptance criterion, so this does not fail the requirement.

Full details: Out of Scope Changes check

Explanation

All changed files relate to the offscreen serve-page fix for #26138. The offscreen-browser-backend.ts change adds the offscreen preference and stopPainting() to the same window creation path. The browser-extension-startup.ts change is needed because an offscreen page reports getType() === 'offscreen'. Without it, serve pages lose extension observation. The lifecycle test file change only adds a no-op stopPainting mock method so the existing test still runs. The stopPainting() call is justified in the PR as a memory and CPU cost reduction for the new offscreen mode. It is a direct consequence of the offscreen change, not unrelated work. The trusted-renderer checks that require 'window' are not changed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@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

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5dd32caf-d3a7-49ef-9433-4b328f205410
Commits

Reviewing files that changed from the base of the PR and between fbeb88d and b672d71.

Files selected for processing: 3

  • src/main/browser/backends/offscreen-browser-backend-lifecycle.test.ts
  • src/main/browser/backends/offscreen-browser-backend.ts
  • src/main/browser/extensions/browser-extension-startup.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@AmoabaKelvin
AmoabaKelvin merged commit e3a3b0d into main Nov 15, 2026
41 checks passed
@AmoabaKelvin
AmoabaKelvin deleted the fix/serve-page-blank-screenshots branch November 15, 2026 09:20
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]: Headless browser pages intermittently return empty screenshots

2 participants