fix(desktop): agent screenshots and clicks work while T3 Code is hidden, minimized or covered #40263
Merged3xcalibur-tech(GitHub profile, opens in a new tab)merged 7 commits into
main fromrefs/pull/40263/headmerged by juliusmarminge View on GitHubtanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -260,0 +271,21 @@271+ */272+ const nudgePaint = ({ webContents, windowDrawing }: DesktopBrowserTabDebugger) =>273+ Effect.sleep(PAINT_NUDGE_INTERVAL).pipe(274+ Effect.andThen(275+ Effect.suspend(() =>276+ webContents.isDestroyed() || windowDrawing?.() === true277+ ? Effect.void278+ : Effect.promise(() =>279+ webContents.capturePage().then(280+ () => undefined,281+ () => undefined,282+ ),283+ ).pipe(Effect.timeoutOption(PAINT_NUDGE_TIMEOUT)),284+ ),285+ ),286+ Effect.forever,287+ );288+289+ const nudgedUntilSettled = <A>(tab: AttachedTab, work: () => Promise<A>) => {290+ const nudging = runFork(nudgePaint(tab.debuggee));291+ return work().finally(() => runFork(Fiber.interrupt(nudging)));
Pushedb2fc8e2
3xcalibur-tech(GitHub profile, opens in a new tab) changed the title
- @@ -260,0 +271,21 @@271+ * prods the guest, less often as it goes on.272+ */273+ const nudgePaint = (webContents: Electron.WebContents, delayMs: number): Effect.Effect<void> =>274+ Effect.sleep(delayMs).pipe(275+ Effect.andThen(276+ Effect.suspend(() =>277+ webContents.isDestroyed()278+ ? Effect.void279+ : Effect.promise(() =>280+ webContents.capturePage().then(281+ () => undefined,282+ () => undefined,283+ ),284+ ).pipe(Effect.timeoutOption(PAINT_NUDGE_TIMEOUT)),285+ ),286+ ),287+ Effect.andThen(288+ Effect.suspend(() =>289+ nudgePaint(webContents, Math.min(delayMs * 2, PAINT_NUDGE_LONGEST_MS)),290+ ),291+ ),
Pushedc5f9f18
Pushed88edbfa
- @@ -258,3 +267,14 @@258267 runFork(PubSub.publish(painting, { key: tab.key, active }));259268 };260269270+ /** By guest rather than attachment, since reopening DevTools reattaches the same guest. */271+ const nativeCaptures = new WeakMap<Electron.WebContents, number>();272+ /** Nudge loops per guest; a guest is rethrottled only by the last, and only if they unthrottled it. */273+ const unthrottleHolds = new WeakMap<Electron.WebContents, { count: number; owned: boolean }>();274+275+ /** On Windows a hidden window's throttled guest draws no frame, and capturePage cannot wake it. */276+ const startNudging = (tab: AttachedTab) => {277+ if (tab.nudging !== null) return;278+ const { webContents } = tab.debuggee;279+ const hold = unthrottleHolds.get(webContents) ?? { count: 0, owned: false };280+ if (hold.count === 0 && !webContents.isDestroyed() && webContents.getBackgroundThrottling()) {@@ -260,0 +276,21 @@276+ const startNudging = (tab: AttachedTab) => {277+ if (tab.nudging !== null) return;278+ const { webContents } = tab.debuggee;279+ const hold = unthrottleHolds.get(webContents) ?? { count: 0, owned: false };280+ if (hold.count === 0 && !webContents.isDestroyed() && webContents.getBackgroundThrottling()) {281+ webContents.setBackgroundThrottling(false);282+ hold.owned = true;283+ }284+ hold.count += 1;285+ unthrottleHolds.set(webContents, hold);286+ tab.nudging = runFork(nudgePaint(tab, PAINT_NUDGE_FIRST_MS));287+ };288+289+ const endNudging = (tab: AttachedTab) => {290+ if (tab.nudging === null) return;291+ tab.nudging = null;292+ const { webContents } = tab.debuggee;293+ const hold = unthrottleHolds.get(webContents);294+ if (!hold || --hold.count > 0) return;295+ unthrottleHolds.delete(webContents);296+ if (hold.owned && !webContents.isDestroyed()) webContents.setBackgroundThrottling(true);
Sign in to join this conversation.




Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
Walkthrough
The desktop browser host periodically calls
capturePage()while focus-held work or screenshot sends remain pending. Nudging stops when the work settles, the tab detaches, or its web contents are destroyed. The host limits each guest to two in-flight native captures and restores background throttling when appropriate.Changes: Preview paint nudges
apps/desktop/src/preview/DesktopBrowserHost.tsapps/desktop/src/preview/DesktopBrowserHost.ts,apps/desktop/src/preview/DesktopBrowserHost.test.tsEstimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)#
Possibly related issues
capturePage()while a screenshot wait remains pending, addressing the reported guest-not-drawing capture stall by prodding the guest to draw.Possibly related PRs
DesktopBrowserHostkeeps a hidden guest painting while a screenshot capture is pending.DesktopBrowserHost.Suggested labels:
bugfixSuggested reviewers:
juliusmarminge,homemadetoast57,macroscopeappMerge Risk:
Moderate · previous review
88edbThe change lets agent screenshots and clicks work while the desktop window is hidden, but the current head fails the desktop test step because a test fixture lacks the new throttling methods. The host and the preview manager can also each re-enable background throttling on a guest the other still needs unthrottled, which could bring back the stalled hidden-window commands this PR fixes. Fix the fixture and the throttling ownership overlap before merging.
Pre-merge checks:
4
#2…Full details: Title check
Explanation
The title names the main change: agent screenshots and clicks in the desktop app work while T3 Code is hidden, minimized, or covered. It matches the changeset, which prods guests with capturePage() while waits are pending. It uses the conventional commit format.
Full details: Description check
Explanation
The description covers the problem, cause, fix, verification, and scope. It follows the template's section order with Problem, Cause, Fix, Evidence, Other platforms, and Not covered. It links issue
#23139and gives detailed before/after evidence in a table. The Scope section does not state that the change is a bug fix rather than a feature, and the template's Change section is labeled as Fix. The template's screenshot requirement is met by a table rather than images, and the description does not include visual before/after screenshots or recordings. These are minor gaps. The description also says the author used a Claude model, which the template asks for.Finishing Touches
Generate unit tests (beta)
Fix failing CI checks