From 8a100e782db0fdcc9840c1c6fd5625a6851fff18 Mon Sep 17 00:00:00 2001 From: David McKay Date: Fri, 27 Nov 2026 00:29:05 -0800 Subject: [PATCH] Organization browser tests: say in the log whether a lost page crashed or was closed organization-unavailable-chat has failed three times in the WebKit job with "Target page, context or browser has been closed", always in the audit log's filter step, and never on a Linux box running it hundreds of times. Playwright gives those same words whether the browser crashed the page or something closed it, so the failures said nothing of which. The shared harness for these tests now logs a line starting [browser lost] when a page crashes, when a page closes without the test closing it, or when a browser disconnects before the tests are done with it, naming the engine, the window and where the page was. The failing test's name follows those lines in the output. Nothing changes for a test that passes. --- app/tests/organization-notices-browser.ts | 46 +++++++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/app/tests/organization-notices-browser.ts b/app/tests/organization-notices-browser.ts index 8272ada152..a79d42d1c1 100644 --- a/app/tests/organization-notices-browser.ts +++ b/app/tests/organization-notices-browser.ts @@ -507,28 +507,65 @@ async function stylesheet(classes: string[]): Promise { const browsers = new Map(); let script: string; +/** Set while `stop` closes the browsers, so only a browser lost before then is said. */ +let stopping = false; + +/* + * A PAGE OR BROWSER LOST MID-TEST IS SAID IN THE LOG, AND HOW. Playwright fails whatever the test was + * waiting on with the same words whether the browser crashed the page or something closed it + * ("Target page, context or browser has been closed"), so a test that failed that way in CI said + * nothing of which it was. Lines start with [browser lost]; the failing test's name follows them in + * the output. Nothing here changes what a test does. + */ /** Build the app (`fixture`, beside this file) and start each browser asked for. */ export async function start( fixture = "organization-notices.fixture.tsx", ): Promise { script = await bundle(fixture); + stopping = false; const playwright = await import("playwright-core"); for (const engine of engines) { const type: BrowserType = playwright[engine]; - browsers.set( - engine, - // The CI job installs full Chromium without the headless shell. - await type.launch(engine === "chromium" ? { channel: "chromium" } : {}), + // The CI job installs full Chromium without the headless shell. + const browser = await type.launch( + engine === "chromium" ? { channel: "chromium" } : {}, ); + browser.on("disconnected", () => { + if (!stopping) + console.error( + `[browser lost] ${engine} disconnected: the browser crashed or was killed`, + ); + }); + browsers.set(engine, browser); } } export async function stop(): Promise { + stopping = true; for (const browser of browsers.values()) await browser.close(); browsers.clear(); } +/** Say when `page` crashes, or closes without the test closing it. */ +function sayIfLost(page: Page, what: string): void { + let closedByTest = false; + const close = page.close.bind(page); + page.close = (options) => { + closedByTest = true; + return close(options); + }; + page.on("crash", () => + console.error(`[browser lost] the page crashed: ${what}, at ${page.url()}`), + ); + page.on("close", () => { + if (!closedByTest && !stopping) + console.error( + `[browser lost] the page closed, not by the test: ${what}, at ${page.url()}`, + ); + }); +} + /** The app opened at `path`, signed in, in a window of `look`'s size and theme. */ export async function open( engine: string, @@ -543,6 +580,7 @@ export async function open( colorScheme: look.theme, reducedMotion: "reduce", }); + sayIfLost(page, `${engine}, ${look.width}, ${look.theme}, opened at ${path}`); page.on("pageerror", (error) => console.error(error)); const inter = join(packageDir("@fontsource-variable/inter"), "files"); await page.route(`${ORIGIN}/**`, (route) => {