Repository navigation
fix(browser): let pixel capture hold its own page drawn, without the desktop window - #22534
Conversation
There was a problem hiding this comment.
ℹ️ No critical issues — two minor diagnostics nits inline.
Reviewed changes
- One-way capture hold replaces the paint lease.
holdPaintForCaptureref-counts holds per page, tells the renderer's existing automation-visibility store to keep the page drawn (browser:capturePaintHold), and holds the now-sharedrendererPublicationThrottleso the renderer stays unthrottled for the hold's duration. - Pixel capture retries until the page draws.
captureUntilDrawnre-asksPage.captureScreenshotat fixed offsets up to an 8 s deadline, keeping earlier requests live so a slow full-page capture can still win; a CDP rejection fails the capture at once. pdf/execdrop the paint requirement.printToPDFlays out afresh, so theneedsPaintoption, the global screenshot lock, the two-way renderer bridge,restartSessionForTarget/refreshTargetAfterAutomationVisibility, and both 2 s timeouts are deleted.- New
CdpWsProxyhold hook scopes the helper proxy's hold to its page; tests were moved/added for the hold lifecycle, the renderer store, and the retry behavior.
I traced the removed symbols across the repo (no stale references), confirmed requireTargetWebContents exists, and checked the retention census still classifies every term-store export. Two independent passes over the retry loop and the process-swap/session lifecycle found no unhandled-rejection, debugger-concurrency, or stale-target regression — the removed target refresh was only ever wired to the deleted needsPaint paths.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No new issues in the incremental changes. Two prior diagnostics nits in
cdp-screenshot.tsremain open, so this is not an approval.
Reviewed changes
- Queued commands bind to the page at enqueue, to the guest at execution.
enqueueTargetedCommandnow resolves only the page id to pick the queue, andexecuteQueuedCommandre-resolves the page's current guest and ensures its session when the job starts, so a command queued behind another runs against the guest current at execution rather than the one captured at enqueue. The queue's per-command paint lease is gone in the same path. - Two session-lifecycle tests added. One asserts a command queued behind a running command rejects with
browser_tab_closedwhen the page swaps guests; the other asserts saved intercept routes are replayed onto the new guest after a swap.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…desktop window Screenshots were the last browser commands that still borrowed the desktop window: they took the per-page automation-visibility lease, which waits for two desktop-window animation frames (capped at 2 s) and never arrives when the window is minimized or throttled. Only pixel capture actually needs a page drawn — input, scripts, layout, the accessibility tree and PDF all work on a hidden page. Capture now takes a main-owned paint hold: a synchronous, per-page ref-count that tells the renderer one way (no reply awaited) to keep the page drawn and keeps the desktop renderer unthrottled while held. Both Orca's full-page capture and the agent-browser helper's screenshots take it in cdp-screenshot.ts and retry on a bounded schedule until the page answers with a frame; a CDP error fails fast. Deleted: the queue's needsPaint lease, the executeJavaScript acquire path and its two racing 2 s timeouts and late-token cleanup, the renderer's rAF wait and window bridge, the capture commands' own leases, the fixed 300/500 ms settle waits, and the global one-screenshot-at-a-time lock. Rebased onto main after #22528 landed; content identical to the reviewed branch head 7b390ed.
7b390ed to
75afc27
Compare
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe change replaces renderer-driven automation-visibility acquisition with reference-counted capture paint holds. A new preload and renderer IPC path tracks these holds. CDP screenshot capture now uses promise-based retries, paint holds, and fallback capture. Browser commands remove Priority: ➖ Normal Merge Risk: 🔵 Low · up to A hidden-page screenshot can time out if its renderer listener restarts during capture. This is a narrow, recoverable risk that can be followed up after merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: d46fa444-aa49-4f2e-aeb9-ed42cae2f0a5
📒 Files selected for processing (34)
config/scripts/ci-shard-timings.jsonsrc/main/browser/agent-browser-bridge-automation-visibility.test.tssrc/main/browser/agent-browser-bridge-capture-commands.tssrc/main/browser/agent-browser-bridge-capture-paint-hold.test.tssrc/main/browser/agent-browser-bridge-interaction-commands.tssrc/main/browser/agent-browser-bridge-lifecycle.tssrc/main/browser/agent-browser-bridge-queue.tssrc/main/browser/agent-browser-bridge-session-lifecycle.test.tssrc/main/browser/agent-browser-bridge-state-commands.tssrc/main/browser/agent-browser-bridge-state.tssrc/main/browser/agent-browser-bridge-test-harness.tssrc/main/browser/agent-browser-bridge-types.tssrc/main/browser/browser-manager-guest-visibility.test.tssrc/main/browser/browser-manager-types.tssrc/main/browser/browser-manager-visibility.tssrc/main/browser/cdp-page-capture-commands.tssrc/main/browser/cdp-screenshot.test.tssrc/main/browser/cdp-screenshot.tssrc/main/browser/cdp-ws-proxy-focus-replay.test.tssrc/main/browser/cdp-ws-proxy-test-harness.tssrc/main/browser/cdp-ws-proxy.test.tssrc/main/browser/cdp-ws-proxy.tssrc/main/runtime/orca-runtime-close-mobile-session-tab.tssrc/main/runtime/orca-runtime-run-create-mobile-session-terminal.tssrc/main/runtime/orca-runtime-runtime-id.tssrc/main/window/renderer-publication-throttle.tssrc/preload/api/browser-api.tssrc/preload/api/browser-bridge-page-interaction-and-sessions.tssrc/renderer/src/components/browser-pane/host-guest/browser-automation-visibility.test.tssrc/renderer/src/components/browser-pane/host-guest/browser-automation-visibility.tssrc/renderer/src/components/browser-pane/host-guest/browser-guest-retention-site-census.test.tssrc/renderer/src/hooks/ipc-events/browser-state-capture-paint-hold.test.tssrc/renderer/src/hooks/ipc-events/browser-state-ipc-bridge.tssrc/renderer/src/hooks/useIpcEvents-lifecycle.test.ts
💤 Files with no reviewable changes (7)
- src/main/runtime/orca-runtime-runtime-id.ts
- src/main/browser/agent-browser-bridge-state.ts
- src/main/browser/browser-manager-types.ts
- src/main/browser/agent-browser-bridge-automation-visibility.test.ts
- src/main/browser/agent-browser-bridge-types.ts
- src/main/browser/agent-browser-bridge-test-harness.ts
- src/renderer/src/components/browser-pane/host-guest/browser-automation-visibility.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Retrying a capture resent the caller's full request, so on an already drawn tall page (a full-page capture takes ~0.5 s) the 250 ms retry started a second full beyond-viewport capture while the first was still running. Measured on Electron 43: any later request makes a held page produce a frame, and that frame answers every pending capture with a full, correct image. So the capture is sent once and 1x1 probes follow until it answers; their results are ignored. Also report a detached debugger as detached rather than destroyed, and give the layout-metrics timeout its own "did not respond" message, since that request doesn't need a drawn page.
There was a problem hiding this comment.
ℹ️ No critical issues — one defer-able observation inline. Both prior diagnostics nits are addressed and their threads resolved.
Reviewed changes
- Pixel capture probes instead of re-capturing.
captureUntilDrawnnow sends the caller'sPage.captureScreenshotonce, then follows it with 1x1jpegclipprobes at 250/750/1750/3750 ms whose results and errors are ignored, resolvingnullat the 8 s deadline. This stops a slow full-page capture from being started a second time while the first is still running. - Diagnostics corrections.
sendreportsDebugger detachedseparately fromWebContents destroyed, andwithTimeoutnow takes a per-call message so the layout-metrics timeout says the page "did not respond" rather than "did not draw a frame". - Tests updated for the exact probe call sequence, the slow-capture-in-flight case, the deadline, the detached debugger, and the layout-metrics message.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| // Why: a 1x1 request is cheap; the frame it makes the page produce also answers the pending capture. | ||
| const FRAME_PROBE_PARAMS = { | ||
| format: 'jpeg', | ||
| quality: 1, | ||
| clip: { x: 0, y: 0, width: 1, height: 1, scale: 1 } | ||
| } |
There was a problem hiding this comment.
This design rests on a measured Electron 43 behavior: that a concurrent 1x1 probe makes the held page draw a frame, and that frame answers the pending full-page capture with a correct image. In Chromium each Page.captureScreenshot mutates per-target view size/emulation params and restores them only in the async completion callback, and a size mismatch is silently tiled rather than errored — so a probe that resizes the view while the capture is still pending is a plausible way to get wrong pixels. Your macOS/Electron 43 measurements in exactly that window came back complete and correct, so this is likely a non-issue on the pinned Electron; flagging it only because the premise is load-bearing, covered by no automated test, and not obviously carried across Electron versions.
Technical details
# Concurrent 1x1 probe vs in-flight full capture
## Affected sites
- `src/main/browser/cdp-screenshot.ts:9` — the comment asserts the premise as fact.
- `src/main/browser/cdp-screenshot.ts:10-14` — `FRAME_PROBE_PARAMS` (1x1 clip), the geometry that differs from the caller's request.
- `src/main/browser/cdp-screenshot.ts:175-177` — probes are scheduled while the initial capture is still in flight, by construction.
## Evidence (`content/browser/devtools/protocol/page_handler.cc`)
- `CaptureScreenshot` snapshots `original_view_size` / `original_emulation_params` per request, calls `SetDeviceEmulationParams(modified_params)` and `widget_host->GetView()->SetSize(clip size)`, then snapshots asynchronously.
- Restoration happens only in `ScreenshotCaptured`; nothing serializes concurrent captures.
- On a size mismatch, `ScreenshotCaptured` calls `SkBitmapOperations::CreateTiledBitmap(...)` — wrong pixels, no error.
- Puppeteer serializes all screenshots behind a per-`BrowserContext` mutex (`BrowserContext.startScreenshot`), corroborating that concurrent captures are not assumed safe in general.
## Required outcome
Either make the probe unable to alter the geometry that answers the initial capture, or document the reliance on the pinned Electron version's measured behavior so an Electron bump re-verifies it.
## Open questions for the human
- Do you still get correct images when the initial full-page capture is slower than the first probe (a tall page)? The 20,000 px run suggests yes, but that is the window where the race would show.
- Is the isolation guaranteed by Electron's snapshot path being decoupled from view size, rather than by timing luck?
ELI5
To take a picture of a browser tab you aren't looking at, Orca used to ask the desktop window to "switch the tab on" and then wait for that window to redraw twice. If the window was minimized or busy, it never redrew, so every screenshot sat through a 2-second wait (plus fixed pauses) first. Now the screenshot code itself asks for the tab to be drawn, doesn't wait for the desktop window to answer, and just keeps trying to take the picture until the tab has drawn a frame.
What Changed
Before: for a screenshot of a hidden tab, the main process ran a script in the desktop window that marked the tab "keep drawn" and waited for two desktop-window frames (2 s cap), while main raced its own 2 s timeout, then slept a fixed 300 ms (viewport) or 500 ms (full page) before capturing. Only one screenshot could run at a time, across all tabs.
execandpdfwent through the same wait before running.After:
browserManager.holdPaintForCapture(guestId)returns a release function right away. On a page's first hold it sendsbrowser:capturePaintHold {held: true}to the desktop window without waiting for a reply, and sends{held: false}on the last release. The desktop window turns that into the same "keep this page drawn" signal the new-tab bootstrap hold already uses, so the pane is parked "invisible but drawn" and is protected from eviction the same way as before. No new paint rule was added. While any hold exists, the desktop window runs unthrottled. This uses the existingRendererPublicationThrottle, now one shared instance so the runtime and the browser code can't undo each other's setting.cdp-screenshot.ts, both Orca's full-page screenshot and the agent-browser helper'sPage.captureScreenshot(intercepted by the CDP proxy) take the hold and release it infinally. The proxy is given a hold function scoped to its page when the bridge creates it.capturePagefallback.webContents.printToPDFreturns the same correct PDF for a drawn page, a page hidden withdisplay:noneafter it was first drawn, and a page that was never drawn (50–150 ms each). Sopdfandexecjust run.Deleted: the
needsPaintqueue option and the optional paint lease around each queued command. The queue now runs each job as admission check, then look up the page's current target, thenensureSession, then execute (the lookup-at-run-time shape comes from #22528). Also deleted: the bridge-level screenshot leases, the fixed 300/500 ms waits, the global one-screenshot-at-a-time lock (it existed because the old screenshot prep switched the visible tab; holds only add drawing for one page, so screenshots of different pages can't interfere), theexecuteJavaScriptacquire path, both 2 s timeouts and the late-token cleanup helpers, and the renderer's frame wait andwindow.__orcaBrowserAutomationVisibilitybridge. Non-test source files, measured against #22528: +242 / −445.Why
Measurements show that only pixel capture needs a drawn page. Input, scripts, layout and the accessibility tree all work on a page hidden with
display:none(#22528). So only capture asks for drawing, and it asks in a way a minimized or throttled desktop window can't stall.Alternatives considered:
Not handled here (unchanged from before): screen recording started through
execwas never kept drawn by the old lease either, because recording outlives the command.Linked Issue
https://linear.app/stably/issue/STA-8024/bug-android-app-browser-issues
Builds on #22528 (merged); rebased onto main.
Visual Proof
N/A: no UI change. Live timings from a background dev build (window never shown). Tab on a worktree that isn't active, pane confirmed
display:none, 3 runs each, times in ms. "Before" is the head of #22528:orca screenshotorca full-screenshotorca pdforca mouse move(run right afterorca pdf)Desktop renderer frozen (
Page.setWebLifecycleState frozen):orca screenshotorca full-screenshotorca pdforca mouse moveThis PR doesn't change mouse move itself. On #22528,
pdfstill held paint, so the mouse move that ran right after it most likely hit the page while it was switching from drawn back to hidden (not measured on #22528). Herepdftakes no hold.Mouse move right after a capture on this PR (3 runs each, ms): after
screenshot160 / 163 / 146; afterfull-screenshot141 / 167 / 161; afterpdf151 / 161 / 145. Mouse move on its own: 201 / 188 / 153. A capture adds no measurable cost to the next command.Screenshots from the after run are real images of the page, not blank. A frozen renderer can't apply any parking change, so capturing a hidden page can't succeed then. Before and after both fail, but after fails at the bounded deadline instead of after two stacked timeouts.
orca tab listbaseline: ~100 ms.Testing
I manually tested these changes locally (macOS, background dev build, see above)
Automated tests added/updated
cdp-screenshot.test.ts: the hold is taken and released once even when the capture throws or the page can't be measured; retries until the page returns a frame; a slow earlier request still wins; retries stop at the deadline after 5 attempts; a CDP error fails at once with no retry and no fallback; retries stop once the page is destroyed; the fallback cases are kept.browser-manager-guest-visibility.test.ts:holdPaintForCaptureis synchronous, never callsexecuteJavaScript, sends one hold and one release per page across nested holds, and unthrottles and then re-throttles the renderer.agent-browser-bridge-capture-paint-hold.test.ts: snapshot, click, mouse, exec and pdf take no hold; full-page capture holds its page and releases it; the helper proxy gets a hold scoped to its page.browser-state-capture-paint-hold.test.ts: the renderer keeps the page drawn from the hold until the release, ignores repeated messages, and releases an active hold when the listener is disposed.I confirmed key tests fail when the fix is broken on purpose: removing the retry fails the retry test and the destroyed-page test; removing the release fails both hold-release tests; never clearing the retry timer fails the deadline test; ignoring CDP errors fails the fail-fast test; skipping the release on dispose fails the dispose test.
pnpm tc,pnpm run check:code-quality:changedand oxlint pass. Browser, pane, hooks, pane-manager, window and runtime suites pass, except the existingbrowser-manager-viewport-ownership.test.tsfailures (12, also failing on the base). Two lineage tests inorca-runtime.test.tsfailed once under full-suite load and pass alone.Not tested: a real on-screen minimized window; Windows and Linux; an SSH-routed page. SSH pages hold paint locally and nothing crosses the connection.
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
browser:capturePaintHoldgoes from main to the renderer inside one app, never across a paired connection. The renderer subscribes with optional chaining, like its other newer browser channels.ensureWebviewVisible): it touches the same file,browser-manager-visibility.ts, in the section right above this change.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (typecheck and targeted suites pass locally; CI covers the rest)