Skip to content

Keep background browser scripts paintable after any new page load - #29161

Closed
Ellebam wants to merge 3 commits into
stablyai:mainfrom
Ellebam:fix/background-browser-script-paint
Closed

Ellebam wants to merge 3 commits into
stablyai:mainfrom
Ellebam:fix/background-browser-script-paint

Conversation

@Ellebam

@Ellebam Ellebam commented Oct 15, 2026 •

Copy link
Copy Markdown

ELI5

A background browser script can get stuck waiting for a frame after the tab loads a new page. This fix lets the script finish without switching workspaces.

What Changed

Runtime.evaluate and Runtime.callFunctionOn keep the page drawing until the command finishes. The hold is also released on failure, disconnect, client replacement or teardown.

The test now covers cross-site navigation, same-origin navigation and reload after parking. The existing fix passes all three; no further production change was needed.

Why

This reuses the paint hold already used for captures. It keeps the page drawable without focusing it and allows parking again when the script finishes.

Linked Issue

#27309

This handles scripts waiting for frames. Pointer input is covered separately by #27310, which excludes eval.

Visual Proof

N/A. Recording or taking a screenshot can wake the parked page and hide the failure. The test checks frame delivery, form visibility, focus and restored parking.

Testing

Linux, Electron 43.7.8:

  • All three cases pass. Removing the paint hold makes each fail at the frame check. Restoring it makes them pass again.
  • 35 focused lifecycle, origin and focus tests pass.
  • Changed-code quality passes.
  • E2E typecheck: 258 existing diagnostics, with byte-identical output on the unchanged PR head. None names the changed test.
  • Full pnpm test: 120,435 passed, 27 failed, plus one suite import error. The same failures reproduce on the unchanged PR head.

The earlier 73 focused macOS test results still apply to the previous revision; macOS was not rerun here. Windows, mobile and SSH were not tested.

  • Automated tests updated.
  • Additional-platform testing.

Author

The contributor does not have an X/Twitter account.

AI Disclosure

Codex assisted with implementation and test authoring. The exact model identifier is unavailable in this change record. All reported checks were executed locally.

Review

The tests check that a new document loads after parking. They probe the guest directly before using the patched eval path. Recording, focus emulation and background-throttling overrides are disabled.

Agent skill upstream boundary

  • Not applicable. This change copies no skill-installer material.

Notes

The unchanged Radix page reported in the comment was not reproduced, so that case remains open. The fix does not keep idle pages drawing indefinitely. A script that never finishes retains its paint hold until disconnect or teardown.

Checklist

  • Scope, behavior and mechanism explained.
  • Focus and cleanup checked.
  • Platform and performance limits stated.
  • Maintainer acceptance of frame checks in place of screenshots.
  • Full lint, typecheck, test and build gates. Local results are listed above.

@DaveDev42

Copy link
Copy Markdown
Contributor

Reproduced on Windows 11, Orca 1.4.226. This also corrects my note on #27309: the page difference I saw there was not about concurrent tabs or machine state.

Setup: one tab at a time, created with orca tab create in a worktree that is not on screen, no other browser tabs open. Every 2 s I ran orca eval with a probe that resolves when requestAnimationFrame fires within 1 s. The bootstrap lease ends at 10 s.

Case Result after the lease ends
example.com, no navigation keeps painting, 11/11
example.org, no navigation keeps painting 2/3, stopped 1/3
radix-ui.com dropdown-menu docs, no navigation stops, 6/6
example.com, then example.org after the lease (cross-site) stops, 3/3
example.com, then example.com/?same after the lease (same-site) stops, 3/3
example.com, location.reload() after the lease stops, 2/2
example.com, history.pushState after the lease keeps painting, 2/2
example.com, then example.org at 4 s (inside the lease) keeps painting, 3/3

So the trigger is broader than cross-site: any new document committed after the page is parked never gets a frame, including a same-site navigation and a reload. A same-document pushState is fine, and so is a navigation that commits while the lease is still active. The new e2e test only covers 127.0.0.1 to localhost, so a same-origin reload case might be worth adding.

Separately, a page that never navigates can still stop at the lease boundary. The Radix page did so every time with the same document throughout (unchanged performance.timeOrigin, no service worker, no iframes, same viewport size). That matches the "Chromium never paints inside display:none" comment, which makes example.com the odd one out, not Radix. Adding a CSS animation or an rAF loop to example.com did not make it stop either, so I can't say what keeps it painting.

One side effect for anyone probing parking the way I did: once evaluate holds paint, an rAF probe sent through orca eval reports painting even for a parked tab, so it can no longer detect parking.

@Ellebam Ellebam changed the title Keep background browser scripts paintable after cross-site navigation Keep background browser scripts paintable after any new page load Oct 18, 2026
@Ellebam

Ellebam commented Oct 18, 2026

Copy link
Copy Markdown
Author

Thanks for checking this. I added same-origin navigation and reload cases and renamed the PR. In local Orca instances on Linux (Electron 43.7.8), all three cases pass with the existing fix and fail at the frame check when I remove the paint hold.

I haven't reproduced the Radix case without navigation, so that remains open. You're also right about orca eval: it now wakes the page. The tests check for stopped frames directly on the guest, before calling through the patched path.

@Ellebam
Ellebam marked this pull request as ready for review October 18, 2026 10:54
@coderabbitai

coderabbitai Bot commented Oct 18, 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: c1f43685-aaf3-4755-9755-283bd32e3ae6
📥 Commits

Reviewing files that changed from the base of the PR and between e8c7b32 and fd968e1.

📒 Files selected for processing: 5
  • src/main/browser/browser-manager-visibility.ts
  • src/main/browser/cdp-debugger-channel.ts
  • src/main/browser/cdp-ws-proxy-paint.test.ts
  • src/main/browser/cdp-ws-proxy.ts
  • tests/e2e/browser-background-script-paint.spec.ts

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

📝 Walkthrough

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to fd968

The paint-hold change is mergeable after normal checks; no unresolved issue is established by this review.

Pre-merge checks: Passed 5
Check name Status Explanation
Description check Passed The description includes all required sections, links the issue, explains the user impact and mechanism, documents testing and platform limits, and records known failures and limitations. Some checkli…
Title check Passed The title clearly and concisely describes the primary change: keeping background browser scripts paintable after a new page load.
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 5…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes all required sections, links the issue, explains the user impact and mechanism, documents testing and platform limits, and records known failures and limitations. Some checklist items remain unchecked, but the missing coverage is explicitly stated and the description is sufficiently complete.

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 5 files.

  • 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.

@DaveDev42

Copy link
Copy Markdown
Contributor

Thanks! I think the Radix case without navigation is just normal parking: it stops at the end of the lease like any off-screen tab, and example.com staying live is the odd one. So I wouldn't hold this PR for it.

One more data point on 1.4.232 (Windows): input to a page that loaded while its tab was parked gets dropped while the CLI says ok. click takes ~5.6 s and the page only sees a mouseover, and type and keypress deliver nothing (same as the report in #27309). orca eval alone doesn't help, but one orca screenshot paints the page and input lands after that. So I think this PR fixes that too.

Keeping off-screen tabs painting is the ask in #27309.

@Ellebam

Ellebam commented Nov 2, 2026

Copy link
Copy Markdown
Author

Thanks @DaveDev42, agreed: the Radix case is normal parking.

Current main now covers both remaining symptoms without this PR. #34291 fixed the dropped input. For scripts, since #34776 orca eval sends Runtime.evaluate to the page inside a queued command that turns off the page's background throttling. On Linux at 66a0f1d, without this change, an eval that waits for requestAnimationFrame finished after a cross-site load and after a reload in a parked tab, although the page had no frames just before.

This PR would now only cover clients that connect to the get cdp-url endpoint and send scripts between Orca commands. That does not justify bringing back a paint hold for scripts, so I'm closing it.

@Ellebam Ellebam closed this Nov 2, 2026
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.

2 participants