From cb2e8414bf9d863d4980e43036a7b0caf8df9306 Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2026 23:38:44 +0200 Subject: [PATCH] test(app): preserve browser registration readiness reproduction The packaged desktop reproduced registration timeouts and left unlisted tabs behind. This failing test models attachment before method readiness, a possible mechanism whose event order remains unconfirmed in the packaged failure. No production fix is included. Refs #7348. --- .../browser/resident-webviews.browser.test.ts | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/packages/app/src/desktop/browser/resident-webviews.browser.test.ts b/packages/app/src/desktop/browser/resident-webviews.browser.test.ts index 679081df0e..dac1116169 100644 --- a/packages/app/src/desktop/browser/resident-webviews.browser.test.ts +++ b/packages/app/src/desktop/browser/resident-webviews.browser.test.ts @@ -250,6 +250,54 @@ describe("resident browser webviews", () => { ]); }); + it("registers a browser when DOM readiness follows an attachment before method readiness", () => { + const webview = ensureTestBrowser({ + browserId: "browser-not-ready-at-attachment", + workspaceId: "workspace-a", + url: "https://example.com", + }); + if (!webview) { + throw new Error("Expected resident webview"); + } + + // Model Electron's method-readiness boundary. This event order is a + // hypothesis for #7348, not an observation from the packaged desktop. + let ready = false; + Object.assign(webview, { + getWebContentsId: () => { + if (!ready) { + throw new Error( + "The WebView must be attached to the DOM and the dom-ready event emitted before this method can be called.", + ); + } + return 303; + }, + }); + const attachmentErrors: string[] = []; + const recordAttachmentError = (event: ErrorEvent) => { + attachmentErrors.push(event.message); + event.preventDefault(); + }; + window.addEventListener("error", recordAttachmentError); + try { + webview.dispatchEvent(new Event("did-attach")); + expect(attachedBrowsers).toEqual([]); + + ready = true; + webview.dispatchEvent(new Event("dom-ready")); + expect(attachedBrowsers).toEqual([ + { + browserId: "browser-not-ready-at-attachment", + workspaceId: "workspace-a", + webContentsId: 303, + }, + ]); + expect(attachmentErrors).toEqual([]); + } finally { + window.removeEventListener("error", recordAttachmentError); + } + }); + it("normalizes an existing resident host back to permanent parking", () => { const staleHost = document.createElement("div"); staleHost.id = RESIDENT_HOST_ID;