Skip to content

fix(browser): enable offscreen painting for headless pages - #26139

Closed
oliver-mee wants to merge 6 commits into
stablyai:mainfrom
oliver-mee:fix/headless-browser-capture
Closed

oliver-mee wants to merge 6 commits into
stablyai:mainfrom
oliver-mee:fix/headless-browser-capture

Conversation

@oliver-mee

@oliver-mee oliver-mee commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

A browser page on a headless server can load correctly but return an empty screenshot. The backend now uses Electron's offscreen rendering instead of relying on a hidden desktop window to paint.

What Changed

Enable webPreferences.offscreen: true when creating server-owned browser windows. Add a lifecycle regression checking that offscreen rendering stays hidden and retains the profile partition, sandbox, context isolation and disabled Node integration, then destroys the owned window on close.

Why

Hiding a normal window is not the same as offscreen rendering. Enabling the rendering mode at creation fixes the producer rather than rejecting valid blank pages, showing windows, waking a monitor or enlarging empty output.

Linked Issue

Fixes #26138

Visual Proof

Same synthetic HTTP fixture on Linux ARM64. The failed capture is natively 1x1; the successful capture is 1280x800. No private page contents or account data are shown.

Hidden-window control Offscreen enabled
Before: one-colour capture After: heading and coloured fixture rendered

Testing

  • I manually tested these changes locally using isolated application scenarios and inspected the resulting images.
  • Automated tests added/updated.

On submitted head d234ee14c, refreshed against upstream ba6599eab: all 32 focused tests pass on macOS, including the real backend-owned hidden Electron page capture. The fixture verifies coloured pixels, dimensions and destruction/retirement. Node typecheck with --compiler=native, scoped Oxlint and whitespace checks pass. The capture harness now imports the current process-host API and handles a page that finished loading before listener registration.

Earlier fix-disabled regression evidence on upstream 385fe8ab remains historical negative-control evidence, not a new negative control on the refreshed head.

ORCA_BACKGROUND_LAUNCH=1 HOME=$(mktemp -d) pnpm exec vitest run --config config/vitest.config.ts src/main/browser/offscreen-browser-backend-lifecycle.test.ts src/main/browser/cdp-screenshot.test.ts

Real application evidence uses the earlier rebuilt source branch at 4de9f9f8 with this preference added. On Linux ARM64/Electron 43.7.5, disabling only the compiled preference gives four one-colour 1x1 failures out of five fresh runs; restoring it gives three passing runs with detailed 1280x800 captures, reload and full-page capture. An initial additional control passed, confirming intermittency. Earlier repeated macOS application scenarios also passed with the preference enabled.

These are source-build tests, not signed/package installation tests. The earlier application branch also contained independent cookie-diagnostic and keyboard-admission changes; its control alters only the rendering preference. The latest macOS Electron fixture runs directly from this submitted head. Windows, remote streaming/reconnection, GPU memory under many tabs and the full repository matrix are not claimed.

AI Disclosure

OpenAI GPT-6.1 Sol assisted implementation, testing and preparation.

Review

Self-review: one Electron preference in the existing headless backend, no desktop-webview conversion. The execution host retains page/profile ownership for local and SSH/remote use; no new wire fields or capabilities. Sandbox and isolation remain enabled. No agent, integration or Git provider behavior changes. Offscreen painting can change CPU/GPU use and scheduling, so sustained multi-tab resource testing remains a limitation. Synthetic screenshots demonstrate correct output; legitimate blank pages remain allowed.

Agent skill upstream boundary

  • Not applicable; no skill-installer material changed.

Notes

Upstream validation for d234ee14ce is waiting for maintainer approval: PR Checks. Focused local evidence above remains unchanged; no substantive current-head CI pass is claimed.

Related #24761 is opt-in high-density rendering and leaves the default path unchanged. This fixes default headless painting at the existing viewport size; it introduces no density option. If that PR lands, its explicit offscreen options should override this default. #14987's close-cleanup changes are separate. No install, service restart or account-profile mutation performed.

X/Twitter handle: not supplied.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots attached
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • Full pnpm lint, pnpm typecheck, pnpm test, and pnpm build matrix (focused checks above; CI required)

🤖 Generated with GPT-6.1 Sol
🧑‍💻 Ideated, directed and reviewed by a human, @oliver-mee

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: af1b9d96-e8e2-49bb-bdf1-6d1bedcb59f2
📥 Commits

Reviewing files that changed from the base of the PR and between 28056bc and d234ee1.

📒 Files selected for processing: 1
  • src/main/browser/offscreen-browser-backend-capture.electron.test.ts
🚧 Files skipped from review as they are similar to previous changes: 1
  • src/main/browser/offscreen-browser-backend-capture.electron.test.ts

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

📝 Walkthrough

The backend now enables Electron offscreen rendering for hidden browser windows. A lifecycle test checks window visibility, security preferences, profile partition, and destruction after tab closure. An Electron integration test captures fixture content, validates screenshot dimensions and pixels, and verifies cleanup.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to d234e

The hidden-page capture regression checks for visible content and rejects blank or 1x1 screenshots. No identified issue currently prevents merging after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the primary change: enabling offscreen painting for headless browser pages.
Linked Issues check Passed For [#26138], offscreen-browser-backend.ts sets webPreferences.offscreen: true for server-owned windows. The existing hidden state, persistent partition, sandbox, context isolation, and disabled N…
Out of Scope Changes check Passed The changes are limited to the backend rendering preference and focused lifecycle and Electron capture tests. These changes directly support the default headless painting fix in [#26138]. No unrelated…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
Description check Passed The pull request description follows the repository template. It explains the change, motivation, linked issue, visual proof, testing, AI disclosure, review considerations, scope limitations, and chec…
Full details: Linked Issues check

Explanation

For [#26138], offscreen-browser-backend.ts sets webPreferences.offscreen: true for server-owned windows. The existing hidden state, persistent partition, sandbox, context isolation, and disabled Node integration remain configured. The lifecycle test checks these settings and window destruction. The Electron test captures fixture pixels from a real hidden backend page and checks image dimensions and pixel content.

Full details: Out of Scope Changes check

Explanation

The changes are limited to the backend rendering preference and focused lifecycle and Electron capture tests. These changes directly support the default headless painting fix in [#26138]. No unrelated behavior is demonstrated.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3 files.

Full details: Description check

Explanation

The pull request description follows the repository template. It explains the change, motivation, linked issue, visual proof, testing, AI disclosure, review considerations, scope limitations, and checklist status. It also clearly states that full-matrix, packaged-install, Windows, remote reconnection, and sustained resource testing remain unverified.

  • Autopilot · 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

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.

🧹 Nitpick comments (1)
src/main/browser/offscreen-browser-backend-lifecycle.test.ts (1)

105-126: 🎯 Functional Correctness | 🔵 Trivial | 🏗️ Heavy lift

Assert rendered pixels in the offscreen regression test.

The lifecycle test checks mocked window preferences and cleanup, but it does not capture a screenshot. The screenshot tests use mocked capture results. These tests can pass when a backend-created hidden page produces an empty frame. Add a focused test that loads fixture content through the offscreen backend and asserts that the captured frame contains non-empty pixels.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8c95fb20-f55d-4f30-b53b-5450cb6fe68c
📥 Commits

Reviewing files that changed from the base of the PR and between 385fe8a and 8bb8bba.

📒 Files selected for processing (2)
  • src/main/browser/offscreen-browser-backend-lifecycle.test.ts
  • src/main/browser/offscreen-browser-backend.ts

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

@oliver-mee

Copy link
Copy Markdown
Contributor Author

Thanks for the pixel-test suggestion. Added a real Electron regression in d3ad571. It bundles the actual backend, creates a hidden page with synthetic red/cyan content, captures it through CDP and checks substantial red and cyan pixel areas, dimensions and cleanup. Only profile metadata and guest registration are fixture substitutes; BrowserWindow, rendering and capture are real.

It passes on macOS and Linux ARM64. Disabling the preference makes the Linux control fail at the fixture deadline. All 30 focused tests, lint and Node typecheck pass on the contribution checkout. This adds current-backend coverage rather than relying only on the earlier application screenshots.

@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
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4e680fca-699a-4e6f-a866-72317477670a
📥 Commits

Reviewing files that changed from the base of the PR and between 8bb8bba and d3ad571.

📒 Files selected for processing (1)
  • src/main/browser/offscreen-browser-backend-capture.electron.test.ts

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

@oliver-mee

Copy link
Copy Markdown
Contributor Author

The three workflows for the current head, bc6df3e, have no jobs and explicitly say they are awaiting maintainer approval. For example: https://github.com/stablyai/orca/actions/runs/37597302995

Could a maintainer approve the workflows on this existing PR? The real Electron regression and focused checks are recorded above; the full upstream matrix has not run. No replacement PR is needed to address the approval gate.

@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
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0ba89b14-a03c-46fa-9e76-64c32f840b28
📥 Commits

Reviewing files that changed from the base of the PR and between bc6df3e and 28056bc.

📒 Files selected for processing: 3
  • src/main/browser/offscreen-browser-backend-capture.electron.test.ts
  • src/main/browser/offscreen-browser-backend-lifecycle.test.ts
  • src/main/browser/offscreen-browser-backend.ts

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

@AmoabaKelvin

Copy link
Copy Markdown
Collaborator

Thanks for this, and for the careful A/B runs. They're why we're confident in the fix. Your branch needed a rebase onto the moved backend file, so #42676 carries your commits over from fresh main, with you as their author. It adds one thing on top: stopPainting(), because nothing reads offscreen paint frames, and delivering them cost about 2 GB of browser-process memory for 5 animated tabs. It also lets the extension observers accept the new offscreen contents type. Your Electron capture test was dropped: CI doesn't run .electron.test.ts files that aren't listed in the workflow, and on macOS it passes either way.

@AmoabaKelvin

Copy link
Copy Markdown
Collaborator

Thanks @oliver-mee. Your commits landed in #42676, which adds stopPainting() on top so offscreen pages don't copy every frame back to the main process (2.9 GB down to about 0.8 GB with 5 animated tabs).

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