Skip to content

Commit 65b0b59

Browse files
committed
fix(desktop): detach announced popup relay sessions
1 parent 6a4ba28 commit 65b0b59

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,43 @@ describe("CDP relay popups", () => {
187187
const resultOf = (written: Array<Record<string, unknown>>, id: number) =>
188188
written.find((message) => message["id"] === id)!;
189189

190+
it("detaches an announced popup session without closing its native window or detaching the opener", async () => {
191+
const pageSend = vi.fn(async () => ({}));
192+
const popupSend = vi.fn(async () => ({}));
193+
const closePopup = vi.fn();
194+
const written: Array<Record<string, unknown>> = [];
195+
const relay = makeRelay(makeTarget(pageSend), (raw) => written.push(JSON.parse(raw)));
196+
relay.addPopup(makePopup("POPUP", popupSend, closePopup));
197+
relay.receive(JSON.stringify({ id: 1, method: "Target.setAutoAttach" }));
198+
await settle();
199+
relay.receive(
200+
JSON.stringify({
201+
id: 2,
202+
method: "Target.detachFromTarget",
203+
params: { sessionId: "t3-preview-popup-1" },
204+
}),
205+
);
206+
relay.receive(
207+
JSON.stringify({
208+
id: 3,
209+
method: "Target.detachFromTarget",
210+
params: { sessionId: "t3-preview-page" },
211+
}),
212+
);
213+
await settle();
214+
expect(resultOf(written, 2)).toHaveProperty("result");
215+
relay.receive(
216+
JSON.stringify({ id: 4, method: "Runtime.evaluate", sessionId: "t3-preview-popup-1" }),
217+
);
218+
relay.receive(JSON.stringify({ id: 5, method: "Page.enable", sessionId: "t3-preview-page" }));
219+
await settle();
220+
expect(resultOf(written, 4)).toHaveProperty("error");
221+
expect(popupSend).not.toHaveBeenCalled();
222+
expect(closePopup).not.toHaveBeenCalled();
223+
expect(pageSend).toHaveBeenCalledExactlyOnceWith("Page.enable", {}, undefined, undefined);
224+
expect(resultOf(written, 5)).toHaveProperty("result");
225+
});
226+
190227
it.each(["browser", "popup", "child"])(
191228
"detaches a popup child through its %s session without affecting the other sessions",
192229
async (source) => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export function createCdpRelayConnection(
257257
undefined,
258258
);
259259
children.delete(sessionId as string);
260-
} else if (session?.kind === "page" && sessionId !== session.owner.sessionId) {
260+
} else if (session?.kind === "page" && sessionId !== PAGE_SESSION_ID) {
261261
sessions.delete(sessionId as string);
262262
session.owner.target.sessionDetached?.(sessionId as string);
263263
} else if (session?.kind === "browser") {

0 commit comments

Comments
 (0)