console Chrome never outlives its run: exit kills it, SIGINT / SIGTERM / SIGHUP close it gracefully, a detached watchdog ends it when the parent dies (SIGKILL included; a reused pid is never killed); every start ends headless orphans on storebound profiles and names orphaned windows; headless runs on macOS prefer Chromium / Chrome for Testing over Google Chrome.app (an orphan kept the owner's Chrome from opening from the Dock); console fill closes the window on errors; pitfall 68; tests

This commit is contained in:
CRTkafa 2026-10-15 00:28:32 +08:00
parent b350781ab5
commit 89d94d6993
10 changed files with 372 additions and 17 deletions

View file

@ -95,11 +95,13 @@ const notInstalled = (e: unknown) => /Executable doesn't exist|distribution '[^'
* --restore-last-session, so session cookies are dropped on relaunch. `label` is null when neither is installed.
*/
export async function persistentBrowser(): Promise<{ label: string | null; skipWhy: string }> {
const { installedBrowsers, launchCandidates } = await import('../../cli/shots/browser');
const { installedBrowsers, persistentExecutable } = await import('../../cli/shots/browser');
let pw: any = null;
try { pw = (await import('playwright')).chromium; } catch (e) { return { label: null, skipWhy: `playwright is not installed (${firstLine(e)})` }; }
// STOREBOUND_CHROME left out: the tests pin the resolver's choice of an installed Chrome / full Chromium
const c = launchCandidates('visible', installedBrowsers(pw, { ...process.env, STOREBOUND_CHROME: undefined }))[0];
// STOREBOUND_CHROME left out: the tests pin the resolver's choice of an installed Chrome / full Chromium (headless on
// macOS: Chromium first, so a test run never counts as the owner's running "Google Chrome", cli/console/chrome-guard.ts)
let c: { label: string } | null = null;
try { c = persistentExecutable('visible', installedBrowsers(pw, { ...process.env, STOREBOUND_CHROME: undefined }), {}, { headless: true }); } catch { /* none */ }
return c ? { label: c.label, skipWhy: '' }
: { label: null, skipWhy: 'neither Google Chrome nor Playwright\'s full Chromium is installed (the headless shell drops session cookies on relaunch); install Google Chrome or run `bunx playwright install chromium`' };
}