Skip to content

Commit 165ec9c

Browse files
Batuhan1999claude
andcommitted
fix(desktop): a stalled capture no longer freezes picture-in-picture
Picture-in-picture frame capture called capturePage without the per-attempt timeout that screenshots and the recording warmup already use. A cold guest that never settles capturePage left the PiP window hidden, blocked repeat opens on its readiness, and froze the frame loop with nothing logged. Bound the capture the same way so both callers log and retry. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d7a8d6f commit 165ec9c

2 files changed

Lines changed: 49 additions & 7 deletions

File tree

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,6 +2164,48 @@ describe("PreviewManager", () => {
21642164
),
21652165
);
21662166

2167+
effectIt.effect("shows picture-in-picture and keeps capturing after stalled captures", () =>
2168+
withManager((manager) =>
2169+
Effect.gen(function* () {
2170+
const image = {
2171+
toJPEG: () => Buffer.from("preview-frame"),
2172+
getSize: () => ({ width: 1280, height: 720 }),
2173+
};
2174+
const stalledInitial = Promise.withResolvers<typeof image>();
2175+
const stalledLoop = Promise.withResolvers<typeof image>();
2176+
const capturePage = vi
2177+
.fn<() => Promise<typeof image>>()
2178+
.mockImplementationOnce(() => stalledInitial.promise)
2179+
.mockImplementationOnce(() => stalledLoop.promise)
2180+
.mockResolvedValue(image);
2181+
fromId.mockReturnValue(makeTestPreviewWebContents(capturePage));
2182+
const { pictureInPictureWindow, send } = makeTestPictureInPictureWindow();
2183+
browserWindowConstructor.mockImplementation(function () {
2184+
return pictureInPictureWindow;
2185+
});
2186+
yield* manager.createTab("tab_pip_stalled_capture");
2187+
yield* manager.registerWebview("tab_pip_stalled_capture", 42);
2188+
2189+
try {
2190+
const open = yield* manager
2191+
.openPictureInPicture("tab_pip_stalled_capture")
2192+
.pipe(Effect.forkChild({ startImmediately: true }));
2193+
yield* TestClock.adjust(1_000);
2194+
expect(pictureInPictureWindow.showInactive).toHaveBeenCalledOnce();
2195+
yield* Fiber.join(open);
2196+
2197+
expect(send).not.toHaveBeenCalled();
2198+
yield* TestClock.adjust(500);
2199+
expect(send).toHaveBeenCalled();
2200+
} finally {
2201+
// Release stalled native calls after a failing assertion against unchanged base.
2202+
stalledInitial.resolve(image);
2203+
stalledLoop.resolve(image);
2204+
}
2205+
}),
2206+
),
2207+
);
2208+
21672209
effectIt.effect("rejects picture-in-picture when its webview changes during initialization", () =>
21682210
withManager((manager) =>
21692211
Effect.gen(function* () {

‎apps/desktop/src/preview/Manager.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,13 +2542,13 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
25422542
if (!captureSession?.consumers.has("picture-in-picture") || captureSession.scope === null)
25432543
return;
25442544
const wc = yield* requireWebContents(tabId);
2545-
const image = yield* attemptPromise(
2546-
{
2547-
operation: "frameCapture.capturePage",
2548-
tabId,
2549-
webContentsId: wc.id,
2550-
},
2551-
() => wc.capturePage(),
2545+
const captureContext = { operation: "frameCapture.capturePage", tabId, webContentsId: wc.id };
2546+
const image = yield* attemptPromise(captureContext, () => wc.capturePage()).pipe(
2547+
Effect.timeout(CAPTURE_PAGE_ATTEMPT_TIMEOUT_MS),
2548+
Effect.catchTags({
2549+
TimeoutError: (cause) =>
2550+
Effect.fail(new PreviewOperationError({ ...captureContext, cause })),
2551+
}),
25522552
);
25532553
const currentCaptureSession = yield* Effect.all(
25542554
[SynchronizedRef.get(frameCaptureSessionsRef), SynchronizedRef.get(tabsRef)],

0 commit comments

Comments
 (0)