fix(desktop): capture headed browser tabs while macOS is locked #27092
main fromrefs/pull/27092/head·opened View on GitHubProblem#
On a Mac Studio hosting T3 Code, locking macOS causes agent browser snapshots to time out and a remote desktop client's browser panel to remain on Connecting. Unlocking restores operation. The failure reproduces with the host displays still on and with a Screen Sharing connection present.
Host: macOS 27.0.1, Apple Silicon. Observed on 0.1.4-nightly.20261028.3824 (eb751fa0730d), Electron 44.9.3 / Chromium 152.0.7977.167. This build is newer than the hidden-guest capture fix in #25184, which closed #24514 and #22461. This PR addresses the remaining locked-macOS case. The unanswered initial capture in #24852 is related, but this PR does not claim to resolve every cause of that failure.
Change#
On macOS, keep server-driven desktop guests inside the window behind the app, including between captures, and use Electron's webContents.capturePage for main-page viewport PNG/JPEG captures. In isolated Electron tests, keeping the guest inside the window is necessary for composition, and native capture returns unchanged frames when CDP Page.captureScreenshot stalls under screen lock.
The native path retains JPEG quality. Requests with clipping, capture beyond the viewport, fromSurface: false, WebP, or unknown options continue through CDP. Child target sessions continue through CDP. The existing screenshot queue, focus leases, and capture lifecycle remain in place. Other host platforms keep their existing rendering and capture paths. No wire contract changes.
This deliberately keeps inactive server-driven macOS guests inside the viewport. That can increase background rendering work compared with moving them off-window between captures; this PR has no quantitative energy-use measurement. Ordinary local tabs retain the existing suspension behavior.
Reproduction#
- Run the desktop app on a Mac host and connect from another Mac's T3 desktop app.
- Have the agent open a browser tab and confirm snapshots and remote viewing work while the host is unlocked.
- Lock the host with its displays still on.
- Request a snapshot and open the remote browser panel. The affected build times out and the viewer stays on Connecting.
- Unlock the host; browser operation recovers.
Validation#
vp run check:changed: format, lint, knip, affected package typechecks, 37 focused desktop tests, and 2 React Compiler checks passed.- New tests cover native capture with unavailable CDP capture, JPEG quality, forwarding unsupported capture options, and macOS-only selection of the native path. Existing screenshot lifecycle tests continue to pass.
vp run build:desktoppassed for the candidate used in the packaged desktop check.- An isolated Electron 44.9.3 headed, sandboxed webview using the changed capture helper and production input helper captured repeated frames and accepted input while macOS was locked.
- An isolated packaged T3 desktop candidate using the changed macOS capture/rendering behavior streamed 12 frames through
/api/preview-stream/ws. The fixture observed a mouse click and the entered textlocked-input-test. macOS reported the screen locked at both ends of the test. The tab used the desktop renderer, with no headless fallback.
{"lockedAtStart":true,"buttonClicked":true,"inputValue":"locked-input-test","frames":12,"lockedAtEnd":true,"passed":true}
The stream check used a protocol client against the actual T3 viewer WebSocket. The patched UI on a second physical Mac has not been verified. The packaged check used Electron 44.10.0 and the same macOS behavior before the added platform guards; the final guards leave that macOS path unchanged. Initial app startup while already locked is outside the verified scope. No installed app or live user data was modified.
Before: capture timed out and the remote viewer produced no frame. After, this frame came from the locked-host interaction check:
Structured Codex autoreview (--mode local --prompt-file ...): no accepted/actionable findings.
Authored with Codex (gpt-6.1-sol) in T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Approved at
d4e4a67Macroscope's review found this PR approvable — This restores macOS browser-tab screenshots while locked using native guest capture and keeps server-driven tabs paintable behind the app. Capture remains scoped to existing guest tabs, with other platforms and unsupported screenshot options retaining their existing paths.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: b50d8a1
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
2f9b67b5-7b5a-4cca-a7d1-c5f6c686d7fb
Commits-
Reviewing files that changed from the base of the PR and between d4e4a67b8863a3c2ea18c07544594be32d7eebbc and d24f5de10e2b8907fe20e66be2b6fa173660b03b.
Files selected for processing: 2-
apps/desktop/src/preview/DesktopBrowserHost.test.tsapps/desktop/src/preview/DesktopBrowserHost.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.
-
Walkthrough
-
On macOS, server-driven preview guests use a visible, non-interactive wrapper fallback, and eligible top-level screenshot commands use native page capture. Unsupported capture parameters and commands with a session ID continue through CDP. Tests cover capture parameter handling and macOS/Linux routing.
Changes: Preview capture
Layer / File(s) Summary Keep server-driven macOS guests visible
apps/web/src/browser/HostedBrowserWebview.tsx,apps/web/src/browser/hostedBrowserWebviewStyle.tsThe webview passes a macOS-gated serverDrivenvalue to the wrapper-style resolver. The resolver applies the visible, non-interactive fallback whenrenderingActiveorserverDrivenis true and the active-rectangle branch does not apply.Route eligible screenshots through native capture
apps/desktop/src/preview/DesktopBrowserHost.ts,apps/desktop/src/preview/GuestCapture.ts,apps/desktop/src/preview/GuestCapture.test.ts,apps/desktop/src/preview/DesktopBrowserHost.test.tsDesktopBrowserHostroutes sessionless macOSPage.captureScreenshotcommands throughcaptureGuestPage. The helper uses native capture for supported parameters and forwards other requests to CDP. Tests cover capture parameters and platform routing.Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)#
sequenceDiagram participant DesktopBrowserHost participant captureGuestPage participant WebContents participant CDP DesktopBrowserHost->>captureGuestPage: Route eligible macOS screenshot captureGuestPage->>WebContents: Capture supported PNG or JPEG request WebContents-->>captureGuestPage: Native image data captureGuestPage-->>DesktopBrowserHost: Base64 image data captureGuestPage->>CDP: Forward unsupported capture request CDP-->>DesktopBrowserHost: Screenshot responsePossibly related issues
- pingdotgg/t3code#23022 — Both concern capture stalls when a desktop guest is not paintable.
- pingdotgg/t3code#24094 — Both concern preview capture during renderer failure; clipped and child-target captures remain on CDP in this change.
- pingdotgg/t3code#23514 — Keeping server-driven macOS guests paintable may address the background-guest condition, but recording capture is not changed here.
- pingdotgg/t3code#27783 — Both concern macOS server-tab automation and viewer stalls when a host tab runs in the background.
- pingdotgg/t3code#23139 — Both concern stalls when preview guests are covered or not paintable; this change applies the wrapper behavior on macOS.
- pingdotgg/t3code#17483 — Both concern automation stalls from hidden preview guests; this change covers server-driven macOS guests.
- pingdotgg/t3code#26964 — Both concern screenshots from hidden guests and guest placement; this change does not cap oversized viewports.
- pingdotgg/t3code#23936 — Both concern snapshot timeouts for hidden or delegated preview tabs; child-target sessions continue through CDP.
Suggested labels:
bugfixSuggested reviewers:
shivamhwp
Merge Risk:
Minimal · up tod24f5-
The change keeps server-driven macOS browser previews capturable while the host is locked, and other platforms keep their existing behavior. No concrete merge-blocking defect was found. Locked-host capture on a real Mac, including the freshness of the captured image, remains unverified by the reported testing and is worth confirming manually.
Pre-merge checks:
3 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Description check The description clearly explains the problem, implementation, scope, reproduction steps, and detailed verification. It does not include the required Scope and approval information, such as maintainer … Add a Scope and approval section. Link the triaged issue or maintainer approval comment, or explain why this focused fix qualifies for the approval exemption and confirm that its scope remains limited. Passed checks: 3 passed-
Check name Status Explanation Title check The title clearly identifies the primary fix: enabling headed browser capture while macOS is locked. Linked Issues check No active directly linked issue remains. Issue #24514is closed and completed, so it provides historical context only. This pull request has no linked-issue coding requirements.Out of Scope Changes check The changes remain within the stated intent. They select native macOS capture for supported main-page captures, preserve CDP fallback behavior, keep server-driven macOS guests in the viewport, preserv… Full details: Out of Scope Changes check
-
Explanation
The changes remain within the stated intent. They select native macOS capture for supported main-page captures, preserve CDP fallback behavior, keep server-driven macOS guests in the viewport, preserve other platform paths, and add focused tests. No unrelated change is demonstrated.
-
Full details: Description check
-
Explanation
The description clearly explains the problem, implementation, scope, reproduction steps, and detailed verification. It does not include the required Scope and approval information, such as maintainer approval or an explanation for why this focused fix qualifies without prior approval.
Resolution
Add a Scope and approval section. Link the triaged issue or maintainer approval comment, or explain why this focused fix qualifies for the approval exemption and confirm that its scope remains limited.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Note
Written by
gpt-6.1-solon behalf of MariaVerified in a real dev environment#
linux regression checks passed at
d4e4a67b8863a3c2ea18c07544594be32d7eebbc. the macos lock fix remains unverified.- read the description, discussion, reviews, six-file diff, and both commits. the pr is open; neither commit is by juliusmarminge or t3dotgg.
- started
github/main(e00ebb6e2641a2681d7612bccc5d8810403d99b8) in../mainaftervp i, then stopped its captured process group before starting the exact pr head after anothervp i. both used isolated empty state, with seeding disabled. only one verification dev server ran at a time. - drove the real web ui with the repo's playwright and
/usr/bin/google-chrome. added a project pointing at the real checkout, created a thread, selected codexgpt-6.1-sol, and submitted real provider turns through the local proxy. no mocks, fixtures, replay provider, or source edits. - on main and the pr, the agent opened an independent server browser tab, saved a 1280×800 png through
preview_snapshot, clicked "learn more", reachedhttps://www.iana.org/help/example-domainswith http 200, returned, and captured another snapshot. - on the pr, two successive additional saved snapshots succeeded. revealed that same agent-created tab, took control through the web client, saw its streamed frames, clicked the link inside the streamed page, then used back and refresh. this exercises capture, navigation/input, and the viewer through the real client/server/provider path.
short runtime transcript, read from the isolated servers' persisted tool results:
main e00ebb6e26: model=gpt-6.1-sol; provider turns=completed preview_open -> https://example.com/ preview_snapshot -> image/png 1280x800 preview_act click -> https://www.iana.org/help/example-domains preview_navigate -> https://example.com/ preview_snapshot -> image/png 1280x800 pr d4e4a67b88: model=gpt-6.1-sol; provider turns=completed,completed same browser flow -> completed preview_snapshot (two additional captures) -> image/png 1280x800, image/png 1280x800 t3_preview_list -> runtime=server web viewer click -> https://www.iana.org/help/example-domains web viewer back -> https://example.com/main linux baseline, with the same destination as the pr capture:

pr linux browser viewer:

pr recording of input into the streamed browser, navigation, back, and refresh (animated copy for github rendering):

inspected the captures and played the uploaded recording, including seeking. github reports 24 passed checks and 8 skipped, zero failing or pending; git.cafe groups these as 32 successful. git.cafe renders these external media as links; the uploaded video was opened and its playback and seeking checked in the t3 browser. no code was changed or pushed; no additional build/test suite was run.
Not verified#
the original bug could not be reproduced on this linux vm. both production changes are gated to macos: electron's native
webContents.capturePagepath and keeping server-driven macos guests inside the app window. the browser used above explicitly reportsruntime=server; it does not execute the changed electron code. these linux captures are regression evidence, not before/after proof of the lock fix.macos host locking, repeated unchanged frames while locked, a remote desktop client's viewer while its mac host is locked, native jpeg quality and cdp fallback under lock, and startup while already locked still require a real macos desktop host. windows and native ios/android clients were not exercised. no claim is made that this pr's macos fix is verified or ready to merge from this run.
takeover merge verification#
merged current main into
d24f5de10e2b8907fe20e66be2b6fa173660b03bwithout rebasing. resolved the screenshot-routing conflict by keeping sessionless macos native capture and passing all other commands, including child-session input, through main's session-awaresendPageCommand. the diff against main remains six files.blacksmith verification passed:
vp run check:changed b50d8a1b15eed3a75e1e0969765e14c6436d80d7(format, lint, both knip passes, desktop/web/scripts typechecks, 38 tests, and react compiler coverage). a separate focused run coveringGuestInput,DesktopBrowserHost, andGuestCapturepassed all 51 tests. two independent code reviews approved this head with no blocker or should findings.macos locked-host native capture remains unverified on this linux vm. earlier linux evidence above is regression evidence for the original head, not proof of the locked-host fix or a new runtime check of this merge.
Additional report that may help validate this fix:
- Installed T3 Code Beta: 0.1.7
- Host OS: macOS 15.8.2 (24H232)
- Agent: Codex harness
The user reports that visual browser review works while they are using the Mac, but fails when the Mac is locked. During the failing session, we observed:
preview_evaluatecontinued to return page content, and browser interactions/navigation continued to work.preview_snapshotwithincludeImage: truerepeatedly failed withPreview automation snapshot timed out after 15000ms.- The failure occurred on both a local development page and an external web application, so it was not limited to one application.
- Fresh tabs and explicitly calling
preview_openwith the tab ID andopen: truedid not recover screenshot capture. A later status reported the tab as visible, but capture still timed out.
The locked-versus-unlocked correlation is user-observed; we have not performed a controlled lock/unlock A/B test or isolated the compositor cause on this machine. No claim that every timeout shares the same cause.
Could you confirm whether the proposed native capture path is expected to cover macOS 15.x as well as the macOS 27 host described here, and include that version range in validation if possible? This blocks unattended visual verification even while page interaction remains functional.
Posted with the user's permission. Application content, URLs, screenshots, credentials and session identifiers have deliberately been omitted.
Another macOS data point for this PR, from the Android client this time. We have not tested the patch itself.
Setup
- Host: MacBook Pro (Apple M5 Pro), macOS 27.0.1 (26A434)
- T3 Code (Beta) desktop and server 0.1.7 (stable), Electron 44.10.1
- Viewer: Android app 2.2.0 (Pixel 10 Pro XL), connected through the managed t3coderelay endpoint
Symptom With the host locked, the server browser panel on Android stays on "Connecting to browser…" indefinitely. The tabs were opened by the agent through
preview_openon the default profile.What we observed
- The phone's
POST /api/auth/websocket-ticket/mediareturns 200. The followingGET /api/preview-stream/ws?...reaches the host through cloudflared but never gets an upgrade response. When the client gives up, the relay log showsRequest failed error="Incoming request ended abruptly: context canceled" ... dest=https://<relay>/api/preview-stream/ws?threadId=…&tabId=…. - No
ServerBrowser.attachViewerspan completes in the server traces we checked. Reading the 0.1.7 bundle, the WS handler awaitsattachViewerbeforerequest.upgrade, andattachViewerawaitspushStill(captureViewport, so CDPPage.captureScreenshotwithout a timeout) when no screencast frame has arrived. That matches #24852. - On the agent side,
preview_snapshotwithincludeImage: truetimes out after 15000 ms, whilepreview_evaluatekeeps working.includeImage: falsefailed once right after the timeout with "No preview automation host is available", then recovered. - Correlation over three days: the relay log has 12
context canceledentries for/api/preview-stream/ws(2026-11-05 to 2026-11-07). In 9 of them,pmset -g logshows the display off. We only have the display state for those; the lock state was not recorded. The other 3 came after we woke the display while the session was confirmed locked (CGSSessionScreenIsLocked=Yes); see 5. - Small A/B: while the host was locked, we woke the display with
caffeinate -u, so it was no longer asleep but still locked.preview_snapshotwith an image still timed out, and the phone kept failing. Being locked appears to be enough; display sleep alone does not explain it. This matches your repro with the displays on.
So the locked-macOS case also reproduces on 0.1.7 stable with an Android viewer over the relay, which may help with the macOS validation that is still open here. Even with this capture fix, an upgrade-first or timeout-bounded initial still (#25381 / #27663) would probably still help mobile clients. A stalled capture otherwise looks like an endless "Connecting" with no error.
Happy to run a nightly or a candidate build that includes this change on this machine and report back.
Wladefant(GitHub profile, opens in a new tab) approved these changes
Independent exact-head source review — APPROVED. Refs pingdotgg/t3code#24852 #27092; Wladefant/superboard#1778 #1798 #1899. Candidate
d24f5de10e2b8907fe20e66be2b6fa173660b03b; baseb50d8a1b15eed3a75e1e0969765e14c6436d80d7. PR authormhodgsondiffers from connected reviewerWladefant.I read all six changed files and the root DesktopBrowserHost CDP dispatch, GuestCapture native/fallback logic, original CI steps/raw logs and bounded locked-macOS reproduction. On macOS only, server-driven guests stay paintable behind the window, and root viewport PNG/JPEG captures may use Electron native guest capture when CDP screenshot stalls. Child-target sessions, clip/beyond-viewport/fromSurface:false/WebP/unknown screenshot options and non-macOS clients retain the CDP path. The capture queue, focus leases and remote viewer path are not bypassed; native JPEG quality is preserved. No additional demonstrable P1/P2 in this bounded source change.
Original normally triggered CI #41292578944 checked out synthetic merge
c92308fexplicitly containing this exact head into this base (verified in original Test, Web, Build logs). Test #124807139980 ran DesktopBrowserHost.test.ts 35/35 and GuestCapture.test.ts 3/3, 110 desktop package files / 981/981 tests PASS (plus a separate 31-file/220-test group). Web #124807140003 ran 494 files / 5331/5331 PASS. Build/typecheck and lint successful. The eight server shards returned successful wrappers but their Test steps were SKIPPED; native mobile/Rust and release smoke SKIPPED. Skips are not passing tests.The PR author reports an isolated locked-macOS Electron/packaged stream check with 12 frames and working click/text, but this reviewer did NOT reproduce that host check. Not established: macOS 15.x behavior, patched second physical Mac/Android remote viewer, app startup already locked, quantitative energy/perf, and installed operator-owned fleet route. These remain host rollout/acceptance gates, not grounds for claiming installed browser success or replacing the working route.
Verdict: independent APPROVE of the reviewed source+CI, not an authorization to deploy, restart or merge. Upstream maintainer retains landing; fleet owner retains operator-session acceptance. No new test run, CI dispatch, source edit, merge, browser attach or runtime action in this review.
tanstack-source added labelsbug
mhodgson(GitHub profile, opens in a new tab) linked this to fix #24514
Still reproduces on T3 Code (Beta) 0.1.9 with a macOS 26.6.2 laptop host: a remote client's browser stays unloaded until the laptop is unlocked, at the machine or over Remote Desktop, and then loads at once.
This PR conflicts with
main. Rebase it or mergemaininto it. If it still conflicts after 7 days with no activity, it will be closed automatically.See the conflict window.
github-actions[bot](GitHub profile, opens in a new tab) added labelsneeds-rebase
I compared official stable 0.1.11 with a local build of this PR at
d24f5de1, using a disposable macOS 27.2.1 VM through CUA/Lume on an Apple Silicon Mac Studio. Neither build was a nightly.On stable 0.1.11, streaming worked while unlocked. After locking the guest, two fresh viewer connections received no browser frames within 20 seconds. Unlocking restored the stream.
The local PR build returned fresh frames in both locked probes, showing updated test labels and advancing clocks. Streaming also worked before locking and after unlocking.
Each probe checked
IOConsoleLockedbefore and after capture. The tests used headed Electron tabs with no headless fallback. The PR’s 38 focused tests passed too. I’ve saved screenshots, JSON results, and reproduction steps.This covers the remote browser stream in a VM; I haven’t tested the agent snapshot MCP tool. The stable and PR builds have different source bases and Electron patch versions, so this comparison doesn’t isolate the patch alone.
I’ll follow up shortly with results from an actual Mac, running directly on the hardware without a VM.
Files:
- Findings and reproduction details
- Evidence ZIP: screenshots, JSON results, lock-state records, and build provenance
- Screenshot comparison (PNG)

Thanks for this. #41212 makes the same change and is the one being kept.
#41212 carries the same native macOS capture and guest-placement fix, updated to preserve the current screenshot handshake and cookie-clearing behavior. It is the better continuation because it retains your fix while resolving the conflict with current main.
Your original authorship is preserved there. The reproduction reports and locked-host evidence in this discussion remain useful for validating the continuation.
Closing as a duplicate.
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes