Skip to content

Commit b73700e

Browse files
committed
fix(desktop): release detached popup capture holds
1 parent 65b0b59 commit b73700e

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ describe("CDP relay popups", () => {
269269
await settle();
270270
expect(resultOf(written, 4)).toHaveProperty("error");
271271
expect(popupSend.mock.calls).toEqual([
272-
["Page.enable", {}, undefined, undefined],
272+
["Page.enable", {}, undefined, popupSession],
273273
["DOM.enable", {}, "sibling-frame", undefined],
274274
]);
275275
expect(pageSend.mock.calls).toEqual([["Page.enable", {}, undefined, undefined]]);
@@ -358,7 +358,7 @@ describe("CDP relay popups", () => {
358358
relay.receive(JSON.stringify({ id: 9, method: "Page.startScreencast", sessionId: extra }));
359359
relay.receive(JSON.stringify({ id: 10, method: "Page.enable", sessionId: "t3-preview-page" }));
360360
await settle();
361-
expect(earlySend.mock.calls.at(-1)).toEqual(["Page.enable", {}, undefined, undefined]);
361+
expect(earlySend.mock.calls.at(-1)).toEqual(["Page.enable", {}, undefined, earlySession]);
362362
expect(lateSend.mock.calls.at(-1)).toEqual(["Page.startScreencast", {}, undefined, extra]);
363363
expect(pageSend.mock.calls.at(-1)).toEqual(["Page.enable", {}, undefined, undefined]);
364364

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export function createCdpRelayConnection(
289289
const owner = session?.kind === "page" ? session.owner : children.get(child!)?.owner;
290290
if (owner === undefined) return Promise.reject(new Error("Unknown or detached CDP session"));
291291
if (command.method === "Target.detachFromTarget") return browserCommand(command);
292-
const extra = child === undefined && command.sessionId !== owner.sessionId;
292+
const extra = child === undefined && command.sessionId !== PAGE_SESSION_ID;
293293
// Child frames/workers pause on auto-attach until resumed; only a main page can skip this command.
294294
if (command.method === "Runtime.runIfWaitingForDebugger" && child === undefined) {
295295
return Promise.resolve({});

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,31 @@ describe("DesktopBrowserHost", () => {
10921092
expect(host.placeDownload(late.tab.webContents, item)).toBe(true);
10931093
expect(paths).toEqual(["/srv/downloads/guid-late"]);
10941094

1095+
for (const id of [5, 6, 7]) {
1096+
yield* cdp(key, {
1097+
id,
1098+
method: id === 7 ? "Page.startScreencast" : "Page.captureScreenshot",
1099+
params: { id },
1100+
sessionId: earlySession,
1101+
});
1102+
}
1103+
yield* settle;
1104+
yield* cdp(key, {
1105+
id: 8,
1106+
method: "Target.detachFromTarget",
1107+
params: { sessionId: earlySession },
1108+
});
1109+
let detached = yield* nextCdp;
1110+
while (detached["id"] !== 8) detached = yield* nextCdp;
1111+
yield* TestClock.adjust("1 minute");
1112+
expect(early.focusEmulation).toEqual([true, false]);
1113+
early.release();
1114+
let queued = yield* nextCdp;
1115+
while (queued["id"] !== 6) queued = yield* nextCdp;
1116+
expect(queued).toHaveProperty("error");
1117+
expect(early.sent.filter((id) => id === 5 || id === 6)).toEqual([5]);
1118+
expect(early.tab.webContents.close).not.toHaveBeenCalled();
1119+
10951120
late.destroy();
10961121
let closed = yield* nextCdp;
10971122
while (closed["method"] !== "Target.detachedFromTarget") closed = yield* nextCdp;

0 commit comments

Comments
 (0)