Repository navigation
fix(browser): only pixel-capturing commands wait for the page to be drawn - #22528
Conversation
…rawn Every targeted browser command used to take an automation-visibility lease, which waits for two desktop-window animation frames (capped at 2 s). When the desktop window is minimized or throttled, that wait always hits the cap, so each phone tap or agent command stalled for up to 2 s (STA-8024). Input, page JavaScript, layout and accessibility snapshots all work on a hidden page; only pixel capture needs it drawn. The lease is now opt-in via `needsPaint` on the two commands that can capture pixels through this path (`exec` passthrough and `pdf`); `ensureVisible` is removed. Screenshots keep managing their own lease. (Commits 24821ae and 07b4a09 carry this change under WIP messages.)
…mands used Only exec and pdf take the automation-visibility lease now, and both create an agent-browser session, so the lease's re-registration path always recreates the session. Remove the `recreate` option from restartSessionForTarget and the options passthrough that fed it. Also fix the keypress test comment that still counted the lease's extra page lookup, and note that screenshots lease inside the screenshot lock.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughThe browser bridge now uses Merge Risk: 🔵 Low · up to Only screenshot, PDF and generic exec commands now wait for the page to be drawn, which speeds up ordinary input on hidden pages. Queued commands look up the current page when they start. Standard page re-registration still tears down the old session and rejects stale commands. The remaining gap is test-only: the intercept-route test cannot tell the replacement proxy from the old one. This does not block merging. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 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: 78e9adcc-8f80-46e2-b597-4f9dbe9ba4d8
📒 Files selected for processing (10)
src/main/browser/agent-browser-bridge-automation-visibility.test.tssrc/main/browser/agent-browser-bridge-capture-commands.tssrc/main/browser/agent-browser-bridge-interaction-commands.tssrc/main/browser/agent-browser-bridge-keypress-input.test.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-types.tssrc/main/browser/browser-manager-visibility.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — two rough edges worth a look.
Reviewed changes
Read the complete 10-file diff at head 724d69d7 for the switch from a default-on visibility lease to an opt-in needsPaint flag in main-process browser command routing.
- Lease becomes opt-in —
EnqueueTargetedCommandOptions.ensureVisible(default on) is replaced byneedsPaint(default off);executeWithVisibleTargetshort-circuits unless a command opts in. - Only pixel capture opts in —
exec(agent-browser-bridge-state-commands.ts:269) andpdf(agent-browser-bridge-interaction-commands.ts:257);screenshot/fullPageScreenshotkeep their internal lease and drop the now-redundantensureVisible: false. - Session recreation simplified —
restartSessionForTargetdrops{ recreate }and always callsensureSession, which is valid because after the change onlyexec/pdfstill reach the refresh path, and both use the defaultensureSession. - Tests retargeted — new negative test for ordinary commands, an
exec-lease test, apdfre-registration test; the snapshot-lease and stale-session-after-re-registration tests removed; keypress page-lookup counts 3→2.
ℹ️ The "works while hidden" claim rests on manual measurement, not coverage
The lease's prior rationale, named in the comment this PR deletes, was lazy-loading sites (browser-manager-visibility.ts:232 before the change). The replacement comment asserts input, JS, layout, lazy loading, and the accessibility tree all work on a display:none page. The new does not lease test only proves routing changed — it never exercises a hidden page. The PR's manual table measures mousemove and scrollY, not lazy-loaded content or accessibility-tree completeness, which are the terms the old rationale named and the ones most plausibly sensitive to display:none.
Technical details
# Add coverage (or recorded evidence) for ordinary commands on a hidden page
## Affected sites
- `src/main/browser/agent-browser-bridge-automation-visibility.test.ts:82-96` — the new test asserts `acquireAutomationVisibility` is not called; it would also pass if `snapshot` returned nothing on a real hidden page.
- `src/main/browser/browser-manager-visibility.ts:232` — the lease-purpose comment this PR rewrites.
## Required outcome
- Evidence that the claim holds for the specific terms the old rationale named, or a scope note making the residual risk explicit. A focused test or captured transcript for a lazy-loaded page and for the accessibility tree on a parked pane is the strongest form.
- `wait --selector`, `scrollintoview`, and `snapshot` are the commands whose correctness depends on the claim most directly.
## Open questions for the human
- On a page hidden with `display:none` at the *embedder* (the `<webview>` element), does Chromium's guest still deliver `IntersectionObserver` callbacks and include nodes outside the visual viewport in `Accessibility.getFullAXTree`? The guest's own document is not `display:none`, so the answer is not obvious from the code.ℹ️ Ordinary commands no longer re-resolve a re-registered guest
Before this PR every command took the lease and then ran refreshTargetAfterAutomationVisibility, which re-resolved the target and restarted the session when the page's webContentsId had changed. Now only exec/pdf do. The standard re-registration paths look covered — browser:registerGuest fires onProcessSwap, which destroys the session and rejects queued commands, and the runtime awaits waitForTabRegistration before routing — but one writer bypasses that door: the client-hosted page guest binding calls browserManager.registerGuest/unregisterGuest directly.
Technical details
# Confirm or cover the client-hosted guest-binding re-registration path
## Affected sites
- `src/main/browser/agent-browser-bridge-queue.ts:99` — ordinary commands now skip `refreshTargetAfterAutomationVisibility`.
- `src/main/browser/browser-client-page-guest-binding.ts:34,55` — `bind`/`release` call `browserManager.registerGuest`/`unregisterGuest` directly, so neither `onProcessSwap` nor `onTabClosed` fires.
- `src/main/browser/browser-client-page-automation-runtime.ts:57-77` — the bridge is notified on retire only when the automation runtime holds a matching registration.
## Required outcome
- Either confirm that local ordinary agent-browser commands never target a purely user-driven client-hosted page (no change needed), or add a regression test that an ordinary command routes to the replacement registration after such a page re-registers.
## Open questions for the human
- Can `browser-client-page-guest-binding.bind` replace a page's guest while an ordinary (non-`needsPaint`) command is already resolved or queued on that page id?DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…ueued Enqueue resolved the page's guest webContents and created its session up front. Before this PR every command re-resolved after its lease, which hid that; now a command queued behind exec/pdf, whose lease can re-register the page with a new guest webContents, would run against the old one. Enqueue now only picks the page (and so the queue). The webContents lookup and session setup move into the queued job and run when the command starts, after the lease for exec/pdf. The lease path's refresh collapses into that step. Resolving after the lease already sees a re-registration that happens during the lease, so the only thing left from the refresh is the case where the page's existing session is bound to an older guest: that session is restarted on the new one (keeping intercept routes) and the active-tab pointers move with it. That check now covers every session-backed command, not only leased ones. Admission is still checked at enqueue and again when the job starts.
Every renderer re-registration of a page with a different guest goes through browser:registerGuest, which calls onProcessSwap in the same tick. That destroys the page's session and rejects its queued commands, so by the time a queued command runs, no session can still be bound to an older guest. The reconcile in the queue and restartSessionForTarget, its only caller, are removed along with the two tests that called it directly. A queued command now resolves the page's current guest, ensures its session, and runs. The re-registration tests now report the swap through onProcessSwap, as production does: commands queued behind the swapping lease are rejected with browser_tab_closed, the leased pdf runs on the new guest, and intercept routes survive the swap.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review at 724d69d7 — commit 9de773e resolves each command's page when it runs, so commands queued behind a pixel-capturing command no longer run against a pre-re-registration webContents.
- Target resolved at run time —
enqueueTargetedCommandcaptures only thebrowserPageId;executeQueuedCommand(renamed fromexecuteWithVisibleTarget) resolves the full target inside its queue slot, after anyneedsPaintlease. - Session reconciliation moved into the run path —
refreshTargetAfterAutomationVisibilitybecomesresolveSessionTarget, comparing the session's boundwebContentsIdto the freshly resolved target, moving the active-tab pointers, and restarting the session on the new guest;ensureSession: falsecommands get the fresh target without session work. - Regression tests added — a click and a snapshot queued behind a
pdfwhose lease re-registers the page dispatch to the new webContents, and thepdflease test now asserts the old guest never gets a proxy ([200]). Both assertions fail on the previous head.
Verified locally: pnpm tc:node passes; the affected test files pass (42 tests); the src/main/browser suite fails only in browser-manager-viewport-ownership.test.ts, which the PR body notes fails identically on main.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review at 9de773e — commit 11bd99b removes the session-restart reconcile and routes guest swaps through onProcessSwap.
- Session-restart reconcile deleted —
resolveSessionTarget,refreshTargetAfterAutomationVisibility, andrestartSessionForTargetare gone;executeQueuedCommandresolves the current target at execution time and callsensureSessiondirectly, relying ononProcessSwapto retire a page's session when its guest changes. - Guest swaps modelled the production way — the leased-swap test reports the swap through
onProcessSwapin the same tick as the mapping change; the click queued behind the lease is rejected withbrowser_tab_closed, thepdfruns on the new guest, and the intercept-route test keeps its patterns across the swap. - Test surface trimmed — the
restartSessionForTargetunit tests are deleted with the method.
Verified locally: pnpm tc:node passes; the affected test files pass (40 tests); the src/main/browser suite fails only in browser-manager-viewport-ownership.test.ts, which the PR body notes fails identically on main.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
#22528 now resolves a queued command's page and session when the job starts and lets onProcessSwap reject commands queued behind a guest swap. Kept that shape and dropped its optional paint lease, since captures hold paint in cdp-screenshot.ts: a job is admission check, resolve target, ensureSession, execute. Its lease tests go with the deleted lease test file; the swap-while-queued case moves to the session lifecycle tests, driven by a running command instead of a lease.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/browser/agent-browser-bridge-automation-visibility.test.ts (1)
245-245: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDistinguish the replacement proxy in the intercept-route test.
The mock reports port
9222for both proxies. The later assertions check two route calls to that port, so they cannot detect a restored route sent to the old proxy instead of webContents 200. Give the proxies distinct ports and assert that the second route uses the replacement proxy’s port. (raw.githubusercontent.com)Based on learnings: a test must distinguish mock instances when both can produce the same observable output.
Source: Learnings
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: fdbd03db-2a32-40ef-b216-02ce62bfe35e
📒 Files selected for processing (4)
src/main/browser/agent-browser-bridge-automation-visibility.test.tssrc/main/browser/agent-browser-bridge-lifecycle.tssrc/main/browser/agent-browser-bridge-queue.tssrc/main/browser/agent-browser-bridge-session-lifecycle.test.ts
💤 Files with no reviewable changes (2)
- src/main/browser/agent-browser-bridge-session-lifecycle.test.ts
- src/main/browser/agent-browser-bridge-lifecycle.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.
…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.
…desktop window (#22534) * fix(browser): let pixel capture hold its own page drawn, without the 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. * fix(browser): probe for a frame instead of repeating the full capture 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.

ELI5
When a phone or an agent drives a page in Orca's built-in browser, Orca used to ask the desktop window to redraw that page before every single command, and wait for it. If the desktop window was minimized or in the background, that wait always ran to its 2-second limit. Now Orca only waits for a redraw when a command actually needs pixels (a PDF, or a raw passthrough command that may take a screenshot or recording). Clicks, typing, scrolling, mouse moves, page scripts and snapshots run immediately.
What Changed
Before: every targeted browser command (click, mouse move, wheel, type, snapshot, eval, ...) first took an "automation visibility" lease. The desktop renderer marked the page as drawable and waited for two animation frames of the desktop window, capped at 2 s. With the desktop window minimized or throttled, each command paid the full cap. From a phone this shows up as taps and scrolls that each stall for ~1-2 s.
After: ordinary commands run straight against the page. Only commands that can capture pixels still take the lease:
exec(raw passthrough, which can runscreenshot/record)pdfScreenshot and full-page screenshot are unchanged; they already manage their own lease.
Mechanism: the queue option
ensureVisible(default on, opted out withensureVisible: false) is replaced byneedsPaint(default off, opted in byexecandpdf). TheensureVisible: falsecall sites are deleted. Queued commands now look up the page's webContents and set up its session when they start running, not when they are queued. Forexec/pdfthat happens after the lease, so the leased path no longer needs its own refresh step. If a page gets a new guest webContents,browser:registerGuestreports it to the bridge in the same tick (onProcessSwap). That destroys the page's session and rejects the commands queued for it withbrowser_tab_closed, as it did before this PR. The next command runs against the new guest. The old session-restart path (restartSessionForTarget) had no remaining caller and is deleted.Why
Measured on a real Electron 43 window: input events, page JavaScript, layout, lazy loading and the accessibility tree all work on a page hidden with
display:none, even with the window minimized. Only pixel capture (screenshots, screencast frames) needs the page drawn. PDF keeps the lease until it is checked on a hidden page. The lease never mounted anything either:acquireAutomationVisibilityis a no-op for an unregistered page (browser-manager-visibility.ts), and the runtime wakes an explicitly targeted page before the command runs (runtime-browser-commands-active-screencasts-by-page-id.ts). Leasing also moved pages into a drawn-but-transparent state where scrolling is slower.Alternatives considered: shortening the 2 s cap, or skipping the wait when the window is hidden. Both keep a per-command round trip to the desktop renderer for work that never needed it; flipping the default removes the round trip entirely and makes the rare case the explicit one.
Supersedes draft PR #22390.
Linked Issue
Relates to Linear STA-8024 (phone taps stall ~2 s). Making pixel capture itself fast on a throttled window is follow-up work.
Visual Proof
N/A — no visible UI change; the change is command latency. Timings below.
Testing
Live, background dev build (
ORCA_BACKGROUND_LAUNCH=1), browser tab on a local page, desktop switched to no active worktree so the page is hidden:orca mouse movex5orca mouse wheelx5Page.setWebLifecycleState frozen)CLI round-trip floor (
orca tab list) on the same build was 124-142 ms. The page received every event while hidden (mousemove count andscrollYadvanced as expected,document.hidden === true).orca pdfstill takes the lease and returns a valid PDF; PDF output on a hidden page without the lease was not checked.Automated:
execandpdfdo take the lease, including the page re-registration path — fail ifneedsPaintis removed from them.onProcessSwap): a click queued behind apdfwhose lease swaps the page's guest is rejected withbrowser_tab_closed, thepdfitself runs on the new guest, and intercept routes survive the swap.pnpm tc:node,pnpm run check:code-quality:changedpass.src/main/browser+src/main/runtimesuites pass exceptbrowser-manager-viewport-ownership.test.ts, which fails identically onmain.Tested on macOS only. Not done: Windows, Linux, a page reached over SSH, and PDF on a hidden page without the lease. The change is in main-process command routing only, with no platform- or SSH-specific code paths.
AI Disclosure
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
Remote/mobile: commands from paired phones take the same main-process path and benefit the same way; no wire change.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)