Skip to content

fix(browser): let a never-painted page paint before pointer input reaches it - #27310

Closed
outof-place wants to merge 3 commits into
stablyai:mainfrom
outof-place:fix/browser-input-after-navigation
Closed

outof-place wants to merge 3 commits into
stablyai:mainfrom
outof-place:fix/browser-input-after-navigation

Conversation

@outof-place

@outof-place outof-place commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #27192. This PR contains that PR's commit (the agent-browser 0.27.3 bump), so please review only the two commits after it: fix(browser): let a never-painted page paint before pointer input reaches it and fix(browser): let overlapping first-paint waits on one document share the wait. I'll rebase once #27192 lands.

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

  • New waitForGuestFirstPaint (src/main/browser/guest-first-paint.ts). Before pointer input reaches a guest, it asks the page whether its document has painted: one Runtime.evaluate that reads performance.getEntriesByType('paint').
    • Already painted (the common case): nothing else happens, and the input goes out.
    • Never painted: it takes the existing capture paint hold (holdPaintForCapture, the one screenshots use), so the parked pane is drawn. It waits in the page until a paint entry appears or six frames have been drawn, at most 2 s, then releases the hold and lets the input go.
    • Bounds and fallbacks. A document that still reports no paint is waited on only once. Callers that overlap on one document (the bridge and the proxy queue separately) share that wait. Any failure, or a renderer that does not answer within 2.5 s, sends the input as before.
  • Where it runs:
    • In the agent-browser CDP proxy (cdp-ws-proxy.ts), for Input.dispatchMouseEvent, dispatchTouchEvent, dispatchDragEvent, synthesizeScrollGesture and synthesizeTapGesture. These now go out through one ordered queue, so a press that waits for the paint is never overtaken by its release.
    • In the bridge's own coordinate commands (browser.mouseMove/mouseDown/mouseUp/mouseWheel/mouseClick), before each dispatch.
  • Not changed: keys, text, eval and 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 goto in a tab the agent opened in the background, browser.click answers 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

  • The cause, measured. A document that loads while its pane is display: none never paints: it gets no paint entries and no requestAnimationFrame. In the windowless launch described below, the page then saw only pointermove, about 5 s after the click started. No pointerdown, pointerup or click arrived, and CDP acked every event. An earlier version of this branch only held the pane drawn. With it, the page saw pointermove and pointerup but no pointerdown in 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.
  • Why "has it painted" instead of "keep it drawn". A page that painted once keeps taking input after it is parked again. So the hold is needed once per document, only until the first paint. That keeps the drawing cost to one paint, not a hold after every pointer command.
  • Why six frames as a fallback. In the headless e2e launch, some documents draw frames but never get a paint entry (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.
  • Alternatives considered:
    • Hold paint for 1 s after every pointer event. I tried this first. It removed the 5 s wait, but in the windowless launch 4 of 6 presses were still dropped, and every click drew the page for a full second.
    • Draw every page after each navigation, input or not. That pays a paint for every goto, including the many an agent never clicks on.
    • Extend the bootstrap lease. It only moves the cliff: a lease of N seconds fails the same way at N + 1.

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.

  • macOS 27, Apple M4 Max, Electron 43.7.5, agent-browser 0.27.3, on a shared machine with load average 8–35.
  • The measurements came from throwaway drivers that are not part of this PR.
  • Headless: Orca's headless e2e fixture (ORCA_E2E_HEADLESS=1).
  • Windowless: a dev build launched with ORCA_E2E_HEADLESS=1 ORCA_BACKGROUND_LAUNCH=1, --disable-renderer-backgrounding, --disable-backgrounding-occluded-windows and --disable-background-timer-throttling, with background throttling off. This is how a benchmark harness runs Orca.
  • In both, the tab comes from browser.tabCreate, the driver waits until the pane is parked, then sends browser.goto to a new document and browser.click on a button. A counter in the page checks that the click landed.

A. Merge risk and mitigations

  • Scope: pointer input to a browser guest, and only the first pointer event for each document that has never painted. Keys, text, evaluation and captures are untouched.
  • New round trip: one Runtime.evaluate (silent, main world, read-only) before each pointer event, under 1 ms in main. A page that overrides performance.getEntriesByType can mislead the check. The input then goes out as it does today, or after one bounded wait.
  • Ordering: pointer events through the proxy are forwarded one after another instead of as each arrives. agent-browser already awaits each event before it sends the next.
  • Fallback: every error path, including a renderer that does not answer, sends the input as today. The worst case is a blank document: one wait per document, bounded by six frames or 2 s.
  • Coverage: unit tests for the gate (painted, never painted, waits once per document, overlapping callers share one wait, document gone mid-wait, unreadable state, stuck renderer), for proxy ordering (press and release held until the paint, then sent in order; keys and text untouched) and for the bridge path (check, hold, wait, release, then dispatch). The e2e spec browser-input-after-navigation.spec.ts fails on main and passes here.

B. User-facing trade-offs, both directions

Click right after goto in a parked tab:

Launch main this PR
Headless, static page p50 5036 ms (n=10), landed 10/10 p50 50 ms, p90 74, max 82 (n=40), landed 40/40
Headless, page running a requestAnimationFrame loop p50 5037 ms (n=10), landed 10/10 p50 48 ms, p90 80, max 82 (n=40), landed 40/40
Windowless, static page 5008–5123 ms (n=10), landed 0/10, each ok: true 36–46 ms, first click 141 ms (n=10), landed 10/10
  • Latency on a page that has painted: the extra Runtime.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).
  • CPU per click, the whole app over the click window (headless, median): static page 161 → 117 ms, animated page 155 → 123 ms. On main the window includes the 5 s wait.
  • Paint cost of the hold: the pane is drawn until the first paint (a few frames), and it is parked again before the click returns.
  • What stays after the click: the document has now painted, so it behaves like the page tabCreate opened, which painted during its lease.
    • Static page, parked: under 1 ms/s of GPU and renderer CPU on both builds.
    • Page running 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).
    • The same thing today: on main, the page tabCreate opened 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.
  • Memory: this is the same cost a drawn pane already has.
    • GPU process: about +32 MB once, after the first clicks (118 → 150 MB), then flat over the rest of 20 clicks. Six screenshots, whose path this PR does not touch, leave the same: 113 → 149 MB.
    • Guest renderer: working set +3.5 MB per navigation that gets a click (96 → 167 MB over 20). On main, with the pane kept drawn the way a visible pane is, it grows at the same rate (97 → 236 MB over 40). On main a parked tab stays flat (107–112 MB after 20) because its documents are never drawn.

C. Maintenance cost

  • One new module, about 75 lines including comments. Three call sites: the proxy, the bridge's pointer dispatch, and its click. One comment updated in browser-manager-visibility.ts.
  • No new IPC, setting or renderer code. It reuses the capture paint hold.
  • Tests: 2 new unit test files (7 + 2 cases), 1 new bridge case, and a 1-test e2e spec (3 rounds). In 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 *-retention suites).
  • npx electron-vite build --mode e2e, then SKIP_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-routing and paired-client-hosted-browser (ORCA_BACKGROUND_LAUNCH=1): 4 passed, rerun on the final head. browser-pointer-input-dispatch is tagged @headful, so the headless project skips it. It did not run.
    • All 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:changed and pnpm run check:max-lines-ratchet (decd687); pnpm tc:node and npx oxlint on the changed files (final head)
  • The gate's unit tests also under the repo's Bun runner: 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 passed

Not run locally: Windows and Linux, a visible window (the harness keeps windows off screen), the full pnpm test and pnpm lint, and packaging.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

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 waitForGuestFirstPaint in guest-first-paint.ts, then forwardPointerInput in cdp-ws-proxy.ts.

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

  • Security: the check runs a fixed, read-only expression in the page and writes nothing to it. No new IPC.
  • Cross-platform: no platform-specific code. The behaviour comes from Chromium, so it should apply wherever a parked guest is display: none. Only macOS was measured.
  • SSH and remote: browser guests run in the local app; no change for remote hosts.
  • Mobile: no change to the mobile app.
  • Backward compatibility: no wire or setting change.
  • Related, not fixed here:
    • browser.keypress in a parked tab returned ok while the page received no keydown, 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.
    • A parked guest that has painted keeps running requestAnimationFrame at display rate. Throttling parked guests would save that for every page, not only after a click.

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)
  • 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). Only the commands listed under Testing ran locally; the rest is left to CI.

🤖 Generated with Claude Code

outof-place and others added 2 commits October 10, 2026 09:58
…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>
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: ac412836-e867-4ed5-b682-9fb3908d3c43


📥 Commits

Reviewing files that changed from the base of the PR and between decd687 and a4afd43.



📒 Files selected for processing (2)
  • src/main/browser/guest-first-paint.test.ts
  • src/main/browser/guest-first-paint.ts


🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/browser/guest-first-paint.test.ts
  • src/main/browser/guest-first-paint.ts


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




📝 Walkthrough
📝 Walkthrough

Walkthrough

Pointer input now waits for guest first paint where required, including input sent through the CDP proxy and bridge paths. The CDP proxy serializes pointer input while it waits. Stale agent-browser session reset now waits for the session process to exit before continuing. Tests cover paint waiting, pointer dispatch, clicks after navigation, and session-exit polling.



Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to a4afd

The previously reported overlapping-click race is addressed. No actionable issue remains before normal merge checks.

Pre-merge checks | Passed 3 | Failed 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check Warning The first-paint gate, input ordering, shared waits, and related tests support [#27309]. The whole pull request also changes stale agent-browser session reset behavior in `agent-browser-bridge-executio… Remove the stale-session reset changes and the unrelated agent-browser dependency bump from this pull request, or move them to a separate pull request.
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 13 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check Passed Issue [#27309] requires faster and reliable clicks after navigation in a parked tab. waitForGuestFirstPaint checks document paint state, holds the guest for first paint or the bounded frame fallback…
Description check Passed The description is complete and directly explains the problem, user impact, implementation, alternatives, testing, risks, and checklist status. It includes the linked issue and provides the required N…
Title check Passed The title clearly and concisely describes the primary change: allowing a never-painted page to paint before pointer input is sent.

Full details: Out of Scope Changes check

Explanation

The first-paint gate, input ordering, shared waits, and related tests support [#27309]. The whole pull request also changes stale agent-browser session reset behavior in agent-browser-bridge-execution.ts, agent-browser-bridge-session-lifecycle.test.ts, agent-browser-session-reset.ts, and agent-browser-session-reset.test.ts. It also bumps the agent-browser dependency in package.json. These changes do not address parked-tab pointer input. The current head adds the shared-wait fix, but it does not remove these unrelated changes.


  • Fix all pre-merge checks with AI
  • 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

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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4f9b6153-5e1f-4e97-b53e-b32152817b63
📥 Commits

Reviewing files that changed from the base of the PR and between 0a73d1e and decd687.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • package.json
  • src/main/browser/agent-browser-bridge-execution.ts
  • src/main/browser/agent-browser-bridge-mouse-commands.ts
  • src/main/browser/agent-browser-bridge-pointer-commands.ts
  • src/main/browser/agent-browser-bridge-pointer-input.test.ts
  • src/main/browser/agent-browser-bridge-session-lifecycle.test.ts
  • src/main/browser/agent-browser-session-reset.test.ts
  • src/main/browser/agent-browser-session-reset.ts
  • src/main/browser/browser-manager-visibility.ts
  • src/main/browser/cdp-ws-proxy-first-paint.test.ts
  • src/main/browser/cdp-ws-proxy.ts
  • src/main/browser/guest-first-paint.test.ts
  • src/main/browser/guest-first-paint.ts
  • tests/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.

Comment thread src/main/browser/guest-first-paint.ts Resolved
… 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>
@AmoabaKelvin

Copy link
Copy Markdown
Collaborator

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.

@AmoabaKelvin

Copy link
Copy Markdown
Collaborator

Closing as superseded by #34291, which is merged with you credited as co-author. Thanks again.

@outof-place
outof-place deleted the fix/browser-input-after-navigation branch November 7, 2026 08:26
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.

Agent browser: a click after goto in a parked tab takes ~5 s and can return ok without clicking

2 participants