fix(desktop): hidden preview tabs throttle instead of running at full speed #25184
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 17 commits into
main fromrefs/pull/25184/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/desktop/src/preview/DesktopBrowserHost.ts lines 321 to 321OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -134,0 +301,21 @@301+ send: (method, params, sessionId, owner) => {302+ // A child session's screencast is not the page's, such as a late one on a detached session.303+ if (sessionId === undefined && method === "Page.startScreencast") {304+ tab.screencasts.add(owner);305+ } else if (sessionId === undefined && method === "Page.stopScreencast") {306+ tab.screencasts.delete(owner);307+ }308+ // Waits for focus emulation; insertText and other non-CDP input would not queue behind it.309+ const forward = (current?: () => boolean) => {310+ const change = tab.focusChange;311+ const run = () =>312+ current === undefined || current()313+ ? send(method, params, sessionId)314+ : Promise.reject(new Error("The page this screenshot was for has moved on."));315+ return change === null ? run() : change.then(run);316+ };317+ return method === "Page.captureScreenshot"318+ ? takeScreenshot(tab, relay, (current) =>319+ owner !== undefined && detachedOwners.has(owner)320+ ? Promise.reject(new Error("The session that asked for this screenshot closed."))321+ : holdFocus(tab, method, owner, () => forward(current)),apps/desktop/src/preview/DesktopBrowserHost.ts line 156OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -109,11 +144,13 @@109144 }110145 const turn = {};111146 tab.screenshotTurn = turn;112- capture()147+ capture(() => tab.screenshotTurn === turn && tab.relay === relay)113148 .finally(() => {114149 if (tab.screenshotTurn === turn) nextScreenshot(tab);115150 })116151 .then(resolve, reject);117152 };118153 if (tab.screenshotTurn === null) start();119- else tab.waitingScreenshots.push(start);154+ else {155+ // The one ahead may be abandoned mid-capture; it needs frames to finish and free its turn.156+ tab.waitingScreenshots.push(start);
- apps/desktop/src/preview/CdpRelay.test.ts lines 118 to 122OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -95,0 +102,21 @@102+ it("acknowledges Playwright's focus emulation without forcing it onto the guest", async () => {103+ const send = vi.fn(async () => ({}));104+ const written: Array<Record<string, unknown>> = [];105+ const relay = createCdpRelayConnection(makeTarget(send), (raw) =>106+ written.push(JSON.parse(raw)),107+ );108+ relay.receive(109+ JSON.stringify({110+ id: 1,111+ method: "Emulation.setFocusEmulationEnabled",112+ params: { enabled: true },113+ sessionId: "t3-preview-page",114+ }),115+ );116+ await settle();117+ expect(written).toEqual([{ id: 1, result: {}, sessionId: "t3-preview-page" }]);118+ expect(send).not.toHaveBeenCalledWith(119+ "Emulation.setFocusEmulationEnabled",120+ { enabled: true },121+ undefined,122+ );apps/server/src/orchestration-v2/RunExecutionService.ts line 1467Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1442,3 +1459,4 @@14421459 yield* finalizeRootRun(event);14431460 }14441461 yield* trackChildLifecycle(event, deliveredEvent !== null);1462+ if (yield* agentTurnsSettled) yield* endPreviewActivity;
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed