Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): Browser Screenshot saves fresh pixels while T3 Code is hidden #36671

MergedQuicksaver(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/36671/headmerged by juliusmarminge View on GitHub

Quicksaver(GitHub profile, opens in a new tab)commented

Summary

This is a new PR that replaces #22335, which was closed for staleness. The same single commit is rebased onto upstream main at 13f89ae0a7. git range-diff reports the patch identical to #22335's last head, and all proof below was regenerated at this base and head. Julius has since merged main at 121f0cf014 and trimmed the still-image tests in dab0ad7. Manager.ts is byte-identical to the proven head 932af4cb1d.

On Windows and Linux, clicking the Browser panel's Screenshot button while the T3 Code window is hidden saves nothing. Electron's capturePage never settles for a preview that isn't being presented, so every retry times out. Each human screenshot now keeps the preview rendering for the duration of the request, waits for a paint through the preview's existing debugger session, discards a warmup capture, and saves the final native readback.

This restores the human Screenshot fix from #19931, which #22222 reverted. Julius asked for a fresh PR with real-build before/after proof on every affected platform.

What changed

  • Each Screenshot click becomes its own rendering consumer next to recording and picture-in-picture, so background throttling comes back only after the last consumer finishes. Overlapping clicks run independent paint probes.
  • The paint probe waits for two animation frames in an isolated world, using only the debugger session the preview already owns. It never attaches or displaces a debugger, and it is bounded to one second.
  • If the probe or warmup fails, the capture logs a warning and saves whatever pixels are available, so freshness is not guaranteed in that case. A frozen renderer can delay the probe's page-side timeout, and Electron capture promises cannot be cancelled.
  • Agent/CDP screenshots, annotation screenshots, recording and contracts are unchanged. Only the Electron desktop runs this path; standalone web and mobile do not.

Validation

Tests, checks, control runs and review status at 932af4cb1d, plus dab0ad7
  • At dab0ad7: Manager.ts is byte-identical to 932af4cb1d, Manager.test.ts passed 85 of 85 locally (Node 24.15.0), and all required CI checks passed. Everything below this bullet was recorded at 932af4cb1d, before the merge and test trim.
  • Manager.test.ts: 89 of 89 passed (Node 26.12.1, pnpm 12.14.0).
  • vp run check:changed 13f89ae0a7 --concurrency 1 passed at this head: format, lint, both Knip passes, desktop and scripts typecheck, Manager tests. Typecheck printed advisory Effect suggestions only.
  • git diff --check is clean, and both files are LF.
  • Wider focused desktop preview run on Windows: 219 passed, 3 failed. The failures are BrowserSession "remembers approvals across restarts, but not incognito ones" and "clearing cookies deletes a saved approval even when none are loaded", plus DesktopBrowserHost "saves a server tab's download under its CDP guid where the server asked" (backslash vs slash path). A same-host control at exact 13f89ae0a7 fails the same three tests, and the branch fails them identically under Node 24.15.0 and 26.12.1. Neither test file loads Manager.ts at runtime.
  • The merge brought in 23 upstream commits through 121f0cf014. None of them touch apps/desktop/src/preview. They do make small changes to ensure-electron-runtime.mjs and vite.config.ts.
  • No open upstream PR changes the human captureScreenshot path. #21534, #22743 and #34935 edit Manager.ts for agent preview capture. #21534 adds the same symbol frame-capture consumer type, so whichever PR lands second needs a small merge there. #27092, #32412, #33719 and #34681 change capture or guest visibility in other files.
  • The source was re-reviewed at this head. Earlier CodeRabbit and multi-model reviews covered #22335 revisions with functionally identical Manager.ts. They do not cover this head.

Proof

Native before/after on Windows, Linux and macOS at 13f89ae0a7 vs 932af4cb1d

Both revisions ran as complete vp run build:desktop apps (Electron 44.10.1) from clean exact-SHA checkouts. No native build was rerun at dab0ad7, whose merge also changed the desktop build files ensure-electron-runtime.mjs and vite.config.ts. Each run started from a copy of the same existing state: an imported, settled real conversation that was opened before the cases. Every image came from clicking the app's real Capture screenshot button, driven by Playwright Electron. No CDP screenshot was used. The page paints a binary epoch counter and a background color, and a standard-library PNG decoder read each saved file.

Hidden app, requested epoch 5:

PlatformBeforeAfter
Windows 11 x64No PNG: three native captures never settledWindows saves fresh epoch 5 while hidden
Linux (Debian 12, Xvfb)No PNG: three native captures never settledLinux saves fresh epoch 5 while hidden
macOS 27.0.1 arm64macOS before saves fresh epoch 5macOS after saves fresh epoch 5

The macOS before and after files are byte-identical, so the upload service stored them once. macOS was not affected in these conditions.

CaseWindowsLinuxmacOS
Two overlapping hidden clicksBefore none, after 2 freshBefore none, after 2 fresh2 fresh on both
Shown, minimized, PiP open, navigation or early load failure during capture, replacement guestFresh on bothFresh on bothFresh on both
Busy page (4 s main-thread loop), and navigating away from it during captureFresh on both; after logged the probe fallbackSameSame
Tab closed after the first native capture startedNo PNG on bothNo PNG on bothClose landed after the save
App closed during a captureClean exit on bothClean exit on bothClean exit on both

Recording kept throttling disabled after PiP closed, and stopping it restored throttling. After every still capture taken without PiP open, throttling was back on and window focus was unchanged.

Limits:

  • The Windows session was locked with the display off for the entire Windows comparison, confirmed by a native display-state subscription and WTS session flags. An unlocked, display-on Windows run was not done at these revisions.
  • Linux ran in Docker on WSL2 with Xvfb, Openbox, picom and llvmpipe. Physical displays, lock, hardware GPU, Wayland and an installed AppImage are not covered.
  • macOS ran unlocked with the display on and used Electron's mock keychain flag. Display sleep and lock were not run at these revisions.
  • The "close after the second native capture" attempt landed after the save on every platform, so an interrupted final readback was not demonstrated. No frozen renderer was simulated.
  • On Windows, blur() left the window focused, so the "inactive" case there was effectively shown. Linux BEFORE did not register the minimize.

Proof package (zip, SHA-256 fe256a99a2387dedcd57022bdf80bfa7e2fb9dc4d17ab5c28c301d7937214785): every saved PNG, decoder output, native call and throttling observations, Windows display/session events, the driver and decoder scripts, and the Linux container recipe. Profiles, the seed database and app screenshots showing conversation content are excluded.

🤖 Generated by GPT 6.1 Sol in Codex via T3 Code. 🤖 Reviewed until clean on #22335 by GPT 6 Astra, GPT 6.1 Sol, Claude Fable 5.1, Claude Opus 5.5, CodeRabbit. Findings that reach consensus across the majority were addressed by the generation model. 🤖 Replacement PR, rebase validation and native proof by Claude Opus 5.5 in Claude Code via T3 Code.

    1. tanstack-source added labelsbug

    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. @@ -1859,0 +2092,21 @@
      2092+ yield* TestClock.adjust(0);
      2093+ expect(writeFile).not.toHaveBeenCalled();
      2094+ expect(oldCapture).toHaveBeenCalledOnce();
      2095+ expect(replacementCapture).toHaveBeenCalledTimes(2);
      2096+ expect(hostThrottling.mock.calls).toEqual([[false], [true], [false]]);
      2097+ expect(replacement.setBackgroundThrottling.mock.calls).toEqual([[false]]);
      2098+ finalCapture.resolve(fresh);
      2099+ yield* Fiber.join(healthy);
      2100+ expect(writeFile.mock.calls.map((call) => call[1])).toEqual([
      2101+ Buffer.from("replacement-png"),
      2102+ ]);
      2103+ expect(hostThrottling.mock.calls).toEqual([[false], [true], [false], [true]]);
      2104+ expect(replacement.setBackgroundThrottling.mock.calls).toEqual([[false], [true]]);
      2105+ }),
      2106+ ),
      2107+ );
      2108+
      2109+ effectIt.effect("paints a loading document with isolated scheduling despite page overrides", () =>
      2110+ withManager((manager) =>
      2111+ Effect.gen(function* () {
      2112+ for (const mode of ["suppressed", "synchronous", "timeout-before", "timeout-after"]) {
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      The suppressed and synchronous cases exercise the same isolated-world path: pageFrame is never called in either case. Could you remove the duplicate case?

      Suggested change
      2112- for (const mode of ["suppressed", "synchronous", "timeout-before", "timeout-after"]) {
      2112+ for (const mode of ["suppressed", "timeout-before", "timeout-after"]) {
      Posted via Macroscope — Test Signal

      Agreed, synchronous added no detection. Every mode asserts that pageFrame is never called, and the page context's undefined Promise stops a page-world probe before it reaches requestAnimationFrame. Julius's dab0ad7 has since removed this whole VM-based test, so there is nothing left to change here.

      Sorry, I'm unable to act on this request because you do not have permissions within this repository.

      Sorry, I'm unable to act on this request because you do not have permissions within this repository.

    4. Approvability

      Verdict: Approved at 932af4c

      Macroscope's review found this PR approvable — Screenshot capture now briefly keeps previews rendering and waits for fresh paint, including while the desktop window is hidden. The change retains existing artifact handling and uses bounded probes and independent rendering leases to limit interference with recording and picture-in-picture.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      Screenshot capture now uses a dedicated frame-capture lease, checks for paint readiness, and performs warmup and final captures. Tests cover paint timing, overlapping captures, rendering state, and fallback capture behavior.

      Changes: Still-image capture

      Layer / File(s)Summary
      Capture lease and final image
      apps/desktop/src/preview/Manager.ts
      captureScreenshot calls captureStillImage. The new flow acquires and releases a separate frame-capture lease, checks paint readiness, runs a warmup capture, and performs a final capture.
      Capture timing and rendering tests
      apps/desktop/src/preview/Manager.test.ts
      Tests cover warmup failures, waiting for paint, overlapping captures, picture-in-picture and recording state, and saving available pixels when paint readiness times out.

      Estimated code review effort: 3 (Moderate) | ~25 minutes

      Change: Bug fix

      Suggested reviewers: juliusmarminge, voltcrash

      Merge Risk: Minimal · up to dab0a

      This change makes the Browser panel's Screenshot button capture reliably when the window is hidden, and it falls back to saving available pixels if the paint check fails. The change is limited to desktop human screenshots, and no concrete merge-blocking problem was identified in the supplied review material.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the main change: a fix in the desktop Browser Screenshot path so that it saves fresh pixels while T3 Code is hidden. The raw summary shows the Manager.ts capture flow (captureStillImag…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Description checkPassedThe description is substantive and follows the template's intent. It has a clear Problem (Windows/Linux hidden-window Screenshot saves nothing because capturePage never settles), a Change section desc…
      Full details: Title check

      Explanation

      The title names the main change: a fix in the desktop Browser Screenshot path so that it saves fresh pixels while T3 Code is hidden. The raw summary shows the Manager.ts capture flow (captureStillImage, paint probe, warmup) and the Manager.test.ts paint-readiness tests, which match that title. It is a conventional commit title in plain language, under 80 characters.

      Full details: Description check

      Explanation

      The description is substantive and follows the template's intent. It has a clear Problem (Windows/Linux hidden-window Screenshot saves nothing because capturePage never settles), a Change section describing the paint-wait, warmup discard, and per-click rendering consumer, and a Scope section that links prior issue/PR context (#22335, #19931) and the maintainer request (Julius's comment asking for a fresh PR with before/after proof). Verification is detailed, with focused test counts, the three failing tests and a same-host control, and explicit statements of what was not checked. Native before/after proof is provided for all three platforms with embedded images and a proof package. Minor gaps: the template's header comment asks for a conventional commit title, and the description does not state a title; the 'Problem' and 'Change' sections are not explicitly headed as in the template (they are present as 'Summary' and 'What changed'), and the Verification section is spread across collapsible blocks. The description also ends with the required model/harness attribution. Overall it is mostly complete, so it passes.

      Finishing Touches

      Generate unit tests (beta)

      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 932af4cb1d0a61c8c6e115e00a77879fbb4bd1aa and dab0ad7d715a5027c010735b6c9cc89bf71b6c97.

      Files selected for processing: 1

      • apps/desktop/src/preview/Manager.test.ts

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

    6. juliusmarminge added labelstakeover:in-progress

    7. Evidence

      Linux desktop, Electron 44.10.1, Xvfb, light theme, 1440×840 window; isolated synthetic state on both commits. Open Browser, capture while shown, then hide for 3 seconds, change the page text/color, and activate Capture screenshot while hidden. Check files before restoring after 4.5 seconds. Repeat with two requests 200 ms apart.

      BeforeAfter
      121f0cf014dab0ad7d71
      Visible control saved; all 3 hidden requests timed out without PNGs.Visible control and all 3 hidden requests saved PNGs before restoration.
      Before: hidden Browser Screenshot reports capture timeoutAfter: actual saved PNG contains the fresh purple HIDDEN 200 marker
      Before recordingAfter recording

      The head temporarily disabled background throttling during captures and restored it afterward. Base observations · Head observations.

      Actual comparison driver · Counter fixture · Portable launch/setup and scripts · Sanitized runtime/build logs.

      The counter was paused at deterministic markers to inspect freshness. Video status strips are driver annotations; application pixels are native screen recordings. Captures were visually inspected.

      Not shown:

      • Windows and macOS were not run; the demonstrated before/after result is Linux only.
      • Ownership retention while recording or picture-in-picture remains active was not exercised.
      • The two requests 200 ms apart both succeeded on head, but completed separately; overlapping screenshot consumer lifetimes were not demonstrated.
      • Minimized windows, capture failure cleanup, and debugger-conflict fallback were not exercised.
    8. juliusmarminge added labelstakeover:ready

    9. juliusmarminge removed labelstakeover:in-progress

    10. juliusmarminge merged this8a45c51

    11. juliusmarminge closed this

    12. juliusmarminge removed labelstakeover:ready

Sign in to join this conversation.