From e74e5c4291157a9bcd0640b0279d1e07455025b0 Mon Sep 17 00:00:00 2001 From: shivam <91240327+shivamhwp@users.noreply.github.com> Date: Thu, 19 Nov 2026 15:50:07 +0000 Subject: [PATCH] fix(desktop): a phone can watch an agent's hidden browser tab while Windows is locked A remote viewer of a desktop-hosted tab the panel does not show asks the client to move the guest on screen behind the app. While the session is locked, the background-throttled main window runs no frames, so the guest never repaints: a fresh viewer waited on "Connecting to browser" until the host was unlocked. Agent tabs open hidden, so they hit this; a tab shown in the panel kept painting. A server-driven capture now takes the same frame-capture lease recording and still screenshots use, which unthrottles the window and the guest until the capture ends. Co-Authored-By: Claude Opus 5.5 --- apps/desktop/src/preview/Manager.test.ts | 24 +++++++++++++++++++++--- apps/desktop/src/preview/Manager.ts | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/preview/Manager.test.ts b/apps/desktop/src/preview/Manager.test.ts index 2091ff3c7f8f2..2a01977302594 100644 --- a/apps/desktop/src/preview/Manager.test.ts +++ b/apps/desktop/src/preview/Manager.test.ts @@ -2415,10 +2415,18 @@ describe("PreviewManager", () => { Effect.gen(function* () { const host = yield* DesktopBrowserHost.DesktopBrowserHost; const serverTab = { threadId: "thread-1", tabId: "server-tab-1" }; + const windowThrottling = vi.fn<(enabled: boolean) => void>(); + const mainWebContents = Object.assign(makeTestHostWebContents(), { + setBackgroundThrottling: windowThrottling, + }); const contents = Object.assign( - makeTestPreviewWebContents(async () => { - throw new Error("unused"); - }, 42), + makeTestPreviewWebContents( + async () => { + throw new Error("unused"); + }, + 42, + mainWebContents, + ), { isDevToolsOpened: () => false, getUserAgent: () => "Electron", @@ -2431,6 +2439,11 @@ describe("PreviewManager", () => { ) as unknown as typeof contents.debugger.sendCommand; fromId.mockReturnValue(contents); const manager = yield* PreviewManager.PreviewManager; + yield* manager.setMainWindow({ + isDestroyed: () => false, + once: vi.fn(), + webContents: mainWebContents, + } as never); const capturing = yield* Queue.unbounded(); yield* manager.subscribeStateChanges((_tabId, state) => Queue.offer(capturing, state.capturing).pipe(Effect.asVoid), @@ -2463,9 +2476,14 @@ describe("PreviewManager", () => { }), ); expect(yield* Queue.take(capturing)).toBe(true); + // A locked or covered window paints a guest it had hidden only while unthrottled. + expect(windowThrottling.mock.calls).toEqual([[false]]); + expect(contents.setBackgroundThrottling.mock.calls).toEqual([[false]]); yield* manager.setCaptureDrawn("tab_1", true); screenshot.resolve({ data: "" }); expect(yield* Queue.take(capturing)).toBe(false); + expect(windowThrottling.mock.calls).toEqual([[false], [true]]); + expect(contents.setBackgroundThrottling.mock.calls).toEqual([[false], [true]]); }).pipe(Effect.provide(managerLayer())), ); diff --git a/apps/desktop/src/preview/Manager.ts b/apps/desktop/src/preview/Manager.ts index 1f28826bcc196..fbf70e12fd375 100644 --- a/apps/desktop/src/preview/Manager.ts +++ b/apps/desktop/src/preview/Manager.ts @@ -3623,6 +3623,8 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function { discard: true }, ); }); + // A hidden or locked window draws no frames, so a guest it hid stays unpainted until unthrottled. + const serverCaptureLeases = new Map(); const updateServerTabCapturing = Effect.fn("PreviewManager.updateServerTabCapturing")( function* (painting: { readonly key: { readonly threadId: string; readonly tabId: string }; @@ -3633,6 +3635,25 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function candidate.serverTab?.threadId === painting.key.threadId && candidate.serverTab.tabId === painting.key.tabId, ); + const key = `${painting.key.threadId}\u0000${painting.key.tabId}`; + const held = serverCaptureLeases.get(key); + if (!painting.active && held) { + serverCaptureLeases.delete(key); + yield* stopFrameCapture(held.tabId, held.lease); + } else if (painting.active && !held && tab) { + const lease = Symbol("server-capture"); + yield* startFrameCapture(tab.tabId, lease).pipe( + Effect.andThen( + Effect.sync(() => serverCaptureLeases.set(key, { tabId: tab.tabId, lease })), + ), + Effect.catch((error) => + Effect.logWarning("Failed to unthrottle a server tab for its capture.", { + tabId: tab.tabId, + error, + }), + ), + ); + } if (tab && tab.capturing !== painting.active) { yield* update(tab.tabId, { capturing: painting.active }); }