Skip to content

fix(browser): keep the desktop drawing while a phone streams a browser tab - #26284

Merged
Jinwoo-H merged 7 commits into
mainfrom
browser-stream-throttle
Oct 7, 2026
Merged

Jinwoo-H merged 7 commits into
mainfrom
browser-stream-throttle

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​312 $\color{#cf222e}{\Huge{\mathbf{−}}}$​40 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​272
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​75 $\color{#cf222e}{\Huge{\mathbf{−}}}$​15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​60

Problem

When the desktop is in the screen saver or minimized, a paired phone that opens a browser tab shows a spinner forever. The page only appears after the desktop is unlocked.

The main window is allowed to throttle in the background. Once it's covered, its compositor stops, and a browser page's pixels come from that compositor. So:

  • the first-frame capturePage and the Page.captureScreenshot fallback both hang (they neither fail nor return empty);
  • Page.startScreencast emits nothing.

On Windows, the screen saver instead freezes the stream after the first frame, and it never recovers on its own.

Fix

  • Keep the window drawing while a remote client streams a browser tab. Each page stream (one per streamed tab, shared by all of its viewers) holds the existing refcounted renderer-throttle lease, the same one mobile terminal create and close use. The page stream's existing cleanup releases it, and every way a stream ends runs that cleanup: the last viewer leaving (unsubscribe, connection close or reap, ghost eviction), the page closing, a stream error, or a failed start. Power use goes back to normal as soon as the stream ends.
  • A 10 s no-frame deadline. If a stream has produced no frame 10 s after it starts, it reports the existing Browser stream timed out. error and ends, so the viewer leaves the spinner. The stream's owner stops it the same way the last viewer leaving would, so a viewer arriving during teardown gets a fresh stream. A bound on capturePage keeps a hung capture from blocking the stop and viewport updates queued behind it.

There's no wire change. Both events (error, then end) already exist, and every phone version handles them.

Verification

This was measured on a real macOS 26 machine with the window actually shown. Playwright's CDP focus emulation keeps the window compositing and hides the bug, so the rig drives the app without attaching CDP to the main renderer. 3 runs per case:

case before after
saver, browser tab behind another tab 0 frames in 20 s; first frame about 4 s after unlock first frame 30–44 ms, live stream
minimized, browser tab behind another tab 0 frames first frame 35–45 ms, live stream
no saver (control) 41–58 ms 40–58 ms
  • Throttle: 15/15 runs read true, then false while streaming, then true again. That covers unsubscribe, socket close, tab close, two viewers (still lifted until the last leaves) and the timeout.
  • Timeout: a forced frameless stream gets error "Browser stream timed out." at 10.0 s, then end, and the lease is released.
  • Windows (Remote Desktop session): the same lift fixed the screen-saver freeze and the minimized hidden-tab case.
  • Other phone features under the screen saver (terminals, typing, tab lists, files, markdown, tab create and close) don't stall. Only the browser stream needs the window to draw.

Unit tests: one case per distinct path. That covers the lift before start, its release after a normal end, a failed start, an error and an abort before ready, and a fresh stream for a viewer who joins during teardown. The timeout tests check the exact 10 s boundary, that any frame suppresses it, and that a late capture is dropped. Removing the release fails 4 of the 6 lease tests. Related suites pass.

Not in this PR

When the browser tab is the active desktop tab, the browser page itself is hidden, not just the window, so under the screen saver or minimize the stream still freezes after 1–2 frames. A follow-up handles it once its after-stream power use has been measured.

…a browser tab

A hidden or minimized desktop window is background-throttled, which stops its
compositor; guest frames come from that compositor, so a phone streaming a
browser tab got no frames and capturePage hung forever.

- Each remote browser.screencast subscription now holds the existing
  renderer publication throttle lease on the main window, acquired before the
  stream starts and released in the subscription's single exit path
  (unsubscribe, connection close/reap, ghost eviction, page close, errors,
  failed start). Leases are refcounted.
- The first-frame snapshot capture is bounded at 10 s. When it hangs or is
  refused and the stream has produced no frame, the stream reports the
  existing "Browser stream timed out." error and ends, so the phone leaves
  its spinner through the error path it already handles. A late capture is
  dropped.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…y the page stream

Review round 1:
- The stream arms one 10 s timer at start and reports "Browser stream timed
  out." only if no frame arrived by then. A capture rejection no longer ends
  the stream; the capture keeps a hang bound only so queued updates and stop
  cannot wedge.
- Stream errors are terminal, so the page-stream owner marks the record
  stopping and stops it. A viewer joining during that teardown now starts a
  fresh stream instead of waiting on the dead one. Detach finishes before
  reporting, so that stop finds the stream already closed.
- Take the throttle lease before registering the connection's stream.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
… stop a no-op

Review round 2:
- Put snapshot capture back to its original shape and wrap only
  webContents.capturePage in the 10 s withTimeout; the CDP fallback already
  gives up at 8 s.
- stop() returns early once the stream is stopping, so a last-viewer leave
  racing the owner's stop sends no second Page.stopScreencast.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
When the streamed tab is the active desktop tab, the guest's own widget is
the one Chromium hides when the window is covered, and lifting the window
throttle does not reach it. Electron's SetBackgroundThrottling(false) sets
disable_hidden_ on the guest's current widget host and re-shows it if
hidden; the attach-time call can predate that widget.

The page-stream record now re-applies the guest's
setBackgroundThrottling(false) when the stream starts, and again on the
hosting window's 'hide' and 'minimize' while the stream lives. It drops
those listeners when the stream ends and makes no further guest call.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The re-apply keeps the streamed guest painting when it is the active desktop tab,
but whether it leaves the guest compositing after the stream ends is not measured
yet. It continues on its own branch.

This reverts commit 04995ee.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Walkthrough

Browser screencast capture now has a 10-second limit for native snapshot capture and a 10-second deadline for the first frame. The runtime controller acquires a renderer publication throttle for a stream and releases it when the stream completion chain settles. Stream errors now trigger session stopping. Tests cover timeout, throttle cleanup, and teardown behavior. Fanout tests now use a shared single-page browser command host test double.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 60099

The new deadline is meant to recover streams that stall. But when the desktop's native capture hangs, the phone's tab stream still ends with "Browser stream timed out." The backup screenshot path never gets a chance to send a frame. Before merging, shorten the native capture limit, or fit both capture attempts inside the 10-second first-frame deadline.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the problem, fix, scope, and verification, but it omits several required template sections, including an actual Linked Issue entry, Visual Proof or an explicit N/A justificati… Complete the required template sections. Add a real issue reference under Fixes #, provide before-and-after visual proof or write N/A with a reason, complete the Testing and Checklist items, and address AI Disclosure, Review, Agent skil…
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly describes the primary change: keeping desktop rendering active while a phone streams a browser tab.
Full details: Description check

Explanation

The description explains the problem, fix, scope, and verification, but it omits several required template sections, including an actual Linked Issue entry, Visual Proof or an explicit N/A justification, Testing checkboxes, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist.

Resolution

Complete the required template sections. Add a real issue reference under Fixes #, provide before-and-after visual proof or write N/A with a reason, complete the Testing and Checklist items, and address AI Disclosure, Review, Agent skill upstream boundary, and Notes.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · 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.

…y the deadline

Review round 5 (elegance):
- The renderer throttle lease moves from the per-connection controller to
  the page-stream record: acquired before Chromium's stream starts and
  released in the record's existing finally, which runs on a failed start,
  on an error and when the last viewer leaves. The controller dependency and
  its runtime wiring are gone.
- The no-frame deadline is a const timer cleared when the stream is done;
  finish() is back to its original body.
- Snapshot capture uses the bounded capturePage result directly instead of
  throwing into its own catch.
- The owner's error teardown keeps only the session guard.
- Tests cover one case per path; the single-page command host double is
  shared with the fanout suite.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

@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: 43a51ad0-9aaa-40a4-ae23-28b55f53ebed
📥 Commits

Reviewing files that changed from the base of the PR and between f406b9c and 6009944.

📒 Files selected for processing (7)
  • src/main/browser/browser-screencast-first-frame-timeout.test.ts
  • src/main/browser/browser-screencast-snapshot-capture.ts
  • src/main/browser/browser-screencast-stream.ts
  • src/main/runtime/browser-screencast-renderer-throttle-lease.test.ts
  • src/main/runtime/orca-runtime-browser-screencast-fanout.test.ts
  • src/main/runtime/runtime-browser-commands-browser-screencast.ts
  • src/main/runtime/single-page-browser-commands-host-test-double.ts

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

@Jinwoo-H
Jinwoo-H merged commit 7b054e6 into main Oct 7, 2026
51 of 53 checks passed
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.

1 participant