Repository navigation
fix(browser): keep the desktop drawing while a phone streams a browser tab - #26284
Conversation
…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
📝 WalkthroughWalkthroughBrowser 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 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)
✅ Passed checks (3 passed)
Full details: Description checkExplanation 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
✨ Finishing Touches 💡 1📝 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 |
…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
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:
43a51ad0-9aaa-40a4-ae23-28b55f53ebed
📒 Files selected for processing (7)
src/main/browser/browser-screencast-first-frame-timeout.test.tssrc/main/browser/browser-screencast-snapshot-capture.tssrc/main/browser/browser-screencast-stream.tssrc/main/runtime/browser-screencast-renderer-throttle-lease.test.tssrc/main/runtime/orca-runtime-browser-screencast-fanout.test.tssrc/main/runtime/runtime-browser-commands-browser-screencast.tssrc/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.
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:
capturePageand thePage.captureScreenshotfallback both hang (they neither fail nor return empty);Page.startScreencastemits nothing.On Windows, the screen saver instead freezes the stream after the first frame, and it never recovers on its own.
Fix
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 oncapturePagekeeps a hung capture from blocking the stop and viewport updates queued behind it.There's no wire change. Both events (
error, thenend) 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:
error"Browser stream timed out." at 10.0 s, thenend, and the lease is released.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.