Repository navigation
fix(browser): let a never-painted page paint before pointer input reaches it - #27310
outof-place wants to merge 3 commits into
Conversation
…ettle sleep agent-browser 0.27.0 sleeps 150 ms in ensure_daemon() on every warm CLI call before reusing the daemon; 0.27.2 removed it (#1432). Every browser command Orca routes through agent-browser (snapshot, click, fill, hover, focus, get, screenshot, exec passthrough...) paid that sleep. The sleep also hid a race in the stale-session reset: `close` on an idle session name spawns a daemon that lingers for its shutdown delay, and without the sleep the next command can reach that daemon and run against its own browser instead of Orca's page. The reset now waits for the closing daemon's pid file to disappear (bounded by the existing 3 s reset timeout, failing closed like a close that never returns). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ches it A tab an agent opens with browser.tabCreate is drawn only for its 10 s bootstrap lease, then parked. A document that loads while parked never paints. Chromium holds a mouse move until a frame and can drop a press that arrives before the first paint while still acking the CDP call, so a click after goto took ~5 s and, in some launches, returned ok without clicking. Before pointer input reaches the guest, the agent-browser CDP proxy and the bridge's own mouse commands now check whether the document has painted. If not, they take the capture paint hold until a paint entry or six drawn frames (at most 2 s), release it, and send the input. Pointer input through the proxy stays in order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The previously reported overlapping-click race is addressed. No actionable issue remains before normal merge checks. Pre-merge checks |
|
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:
4f9b6153-5e1f-4e97-b53e-b32152817b63
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (14)
package.jsonsrc/main/browser/agent-browser-bridge-execution.tssrc/main/browser/agent-browser-bridge-mouse-commands.tssrc/main/browser/agent-browser-bridge-pointer-commands.tssrc/main/browser/agent-browser-bridge-pointer-input.test.tssrc/main/browser/agent-browser-bridge-session-lifecycle.test.tssrc/main/browser/agent-browser-session-reset.test.tssrc/main/browser/agent-browser-session-reset.tssrc/main/browser/browser-manager-visibility.tssrc/main/browser/cdp-ws-proxy-first-paint.test.tssrc/main/browser/cdp-ws-proxy.tssrc/main/browser/guest-first-paint.test.tssrc/main/browser/guest-first-paint.tstests/e2e/browser-input-after-navigation.spec.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.
… the wait The bridge's direct mouse commands and the CDP proxy queue pointer input separately. A second caller for the same never-painted document saw it as already waited on and sent its input before the first paint. Later callers now await the pending wait for that document. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for digging into this. Your measurements, especially that a press can still be dropped until the paint entry shows up, shaped the fix. The proxy this branch changes has since been restructured, so we redid it on the current input queue in #34291. It also covers keys and the bridge's own mouse commands, and credits you as co-author. |
|
Closing as superseded by #34291, which is merged with you credited as co-author. Thanks again. |
ELI5
When an agent opens a web page in Orca, the page is drawn only for its first 10 seconds, and then it is put away out of sight. If the agent then goes to a new address in that tab, the new page is never drawn at all. Chromium does not deliver mouse input to a page that has never been drawn: the mouse move waits about 5 seconds, and the click itself can be thrown away while the command still reports success. This PR draws such a page just long enough for it to paint once, then sends the click.
What Changed
waitForGuestFirstPaint(src/main/browser/guest-first-paint.ts). Before pointer input reaches a guest, it asks the page whether its document has painted: oneRuntime.evaluatethat readsperformance.getEntriesByType('paint').holdPaintForCapture, the one screenshots use), so the parked pane is drawn. It waits in the page until apaintentry appears or six frames have been drawn, at most 2 s, then releases the hold and lets the input go.cdp-ws-proxy.ts), forInput.dispatchMouseEvent,dispatchTouchEvent,dispatchDragEvent,synthesizeScrollGestureandsynthesizeTapGesture. These now go out through one ordered queue, so a press that waits for the paint is never overtaken by its release.browser.mouseMove/mouseDown/mouseUp/mouseWheel/mouseClick), before each dispatch.evaland screenshots. The hold is released as soon as the page has painted, so the pane is parked again before the click returns.What users see: after a
gotoin a tab the agent opened in the background,browser.clickanswers in about 40–50 ms instead of about 5 s, and it lands. Before, depending on the launch, the click could report success without clicking.Why
display: nonenever paints: it gets nopaintentries and norequestAnimationFrame. In the windowless launch described below, the page then saw onlypointermove, about 5 s after the click started. Nopointerdown,pointeruporclickarrived, and CDP acked every event. An earlier version of this branch only held the pane drawn. With it, the page sawpointermoveandpointerupbut nopointerdownin 4 of 6 clicks; those events came 6–17 ms before the page's first paint. Waiting for the paint itself fixed that: 10 of 10 landed.paintentry (6 of 40 in one run). With a paint-only wait, those clicks sat at the 2 s bound (7 of 40 on a static page and 3 of 40 on an animated one, in another run). Counting drawn frames ends that wait at 73–82 ms.goto, including the many an agent never clicks on.Linked Issue
Fixes #27309
Visual Proof
N/A. The page is parked, so nothing changes on screen. The before/after is the click latency and whether the click landed, measured below.
Trade-offs
Setup.
ORCA_E2E_HEADLESS=1).ORCA_E2E_HEADLESS=1 ORCA_BACKGROUND_LAUNCH=1,--disable-renderer-backgrounding,--disable-backgrounding-occluded-windowsand--disable-background-timer-throttling, with background throttling off. This is how a benchmark harness runs Orca.browser.tabCreate, the driver waits until the pane is parked, then sendsbrowser.gototo a new document andbrowser.clickon a button. A counter in the page checks that the click landed.A. Merge risk and mitigations
Runtime.evaluate(silent, main world, read-only) before each pointer event, under 1 ms in main. A page that overridesperformance.getEntriesByTypecan mislead the check. The input then goes out as it does today, or after one bounded wait.browser-input-after-navigation.spec.tsfails on main and passes here.B. User-facing trade-offs, both directions
Click right after
gotoin a parked tab:requestAnimationFrameloopok: trueRuntime.evaluate, under 1 ms per pointer event. In the windowless benchmark, a click on a page that loaded during the lease took 7–17 ms on main and 6–7 ms here (n=4 each).tabCreateopened, which painted during its lease.requestAnimationFrame: its loop now keeps running while parked, at 120 callbacks/s on a 120 Hz display. That costs about 7.5 ms/s GPU process CPU and 13 ms/s guest renderer CPU (the mean of three 2 s windows).tabCreateopened costs about 9.6 ms/s GPU and 17 ms/s renderer when parked. A document that loads while parked costs nothing on main, because it never runs at all.C. Maintenance cost
browser-manager-visibility.ts.agent-browser-bridge-pointer-input.test.ts, 4 existing tests now fail the dispatch itself instead of the first debugger call, because the paint check comes first.Verdict: a correctness fix that is also a latency win. A click after a navigation in a background tab lands in about 50 ms instead of about 5 s, and it no longer reports success without clicking. The cost is that a page which got input behaves like a drawn page: an animated page keeps animating while parked, and the one-time GPU memory matches what screenshots already leave.
Testing
Ran locally. Everything below ran on the final head a4afd43 unless it says decd687 (the first commit, before the shared-wait fix):
pnpm exec vitest run --maxWorkers=4 src/main/browser/: 216 files; 1887 passed, 2 skipped, 47 failed. The 47 failures are in 5 files that fail the same way on perf(browser): bump agent-browser to 0.27.3 to drop its per-command settle sleep #27192's head without this change (browser-manager-tab-identity,browser-manager-viewport-ownership, and three*-retentionsuites).npx electron-vite build --mode e2e, thenSKIP_BUILD=1 pnpm exec playwright test <spec> --config tests/playwright.config.ts --project electron-headless:tests/e2e/browser-input-after-navigation.spec.ts› "a click right after goto lands promptly on a parked page": fails on perf(browser): bump agent-browser to 0.27.3 to drop its per-command settle sleep #27192's head (click 0 took 5168 ms), passes here.browser-input-after-navigation,browser-embedded-owner-routingandpaired-client-hosted-browser(ORCA_BACKGROUND_LAUNCH=1): 4 passed, rerun on the final head.browser-pointer-input-dispatchis tagged@headful, so the headless project skips it. It did not run.tests/e2e/browser-*.spec.ts(decd687): 38 passed, 1 skipped. On an earlier build of this branch,browser-split-shortcuts› "opens Find only in the browser split whose guest owns the shortcut" failed once in this group run and passed 2 of 2 runs on its own.pnpm tc,ORCA_CODE_QUALITY_BASE=upstream/main pnpm run check:code-quality:changedandpnpm run check:max-lines-ratchet(decd687);pnpm tc:nodeandnpx oxlinton the changed files (final head)node config/scripts/run-vitest.mjs run --config config/vitest.config.ts src/main/browser/guest-first-paint.test.ts src/main/browser/cdp-ws-proxy-first-paint.test.ts: 9 passedNot run locally: Windows and Linux, a visible window (the harness keeps windows off screen), the full
pnpm testandpnpm lint, and packaging.AI Disclosure
Implemented with Claude Opus 5.5 via Claude Code: diagnosis, code, tests and measurements. A human (outof-place) directed the work.
Review
Start with
waitForGuestFirstPaintinguest-first-paint.ts, thenforwardPointerInputincdp-ws-proxy.ts.Agent skill upstream boundary
Notes
display: none. Only macOS was measured.browser.keypressin a parked tab returnedokwhile the page received nokeydown, in both launches (3 of 3 each). This held even after the page had painted, so it is not the first-paint drop. Keys are left out of this PR.requestAnimationFrameat display rate. Throttling parked guests would save that for every page, not only after a click.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred). Only the commands listed under Testing ran locally; the rest is left to CI.🤖 Generated with Claude Code