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

@ -176,11 +176,16 @@ export interface LaunchDeps {
* STOREBOUND_CHROME, Google Chrome, then Playwright's full Chromium; kind "chrome" = Google Chrome only. Never the
* headless shell. Nothing installed: the same error as withCandidates.
*/
export function persistentExecutable(kind: 'visible' | 'chrome', i: Installed, env: Record<string, string | undefined> = process.env): { label: string; path: string } {
export function persistentExecutable(kind: 'visible' | 'chrome', i: Installed, env: Record<string, string | undefined> = process.env, o: { headless?: boolean; platform?: string } = {}): { label: string; path: string } {
const list: { label: string; path: string }[] = [];
if (kind === 'visible' && i.storeboundChrome) list.push({ label: `STOREBOUND_CHROME (${i.storeboundChrome})`, path: i.storeboundChrome });
// headless on macOS (tests): Playwright's Chromium first. LaunchServices counts a headless run of Google Chrome.app as
// the running "Google Chrome", so while it runs the Dock's Chrome only activates it and the owner's Chrome stays
// closed (October 2026). Chromium / Chrome for Testing has a bundle id of its own.
const chromiumFirst = kind === 'visible' && o.headless === true && (o.platform ?? process.platform) === 'darwin';
if (chromiumFirst && i.chromium) list.push({ label: `Playwright Chromium (${i.chromium})`, path: i.chromium });
if (i.chrome) list.push({ label: `Google Chrome (${i.chrome})`, path: i.chrome });
if (kind === 'visible' && i.chromium) list.push({ label: `Playwright Chromium (${i.chromium})`, path: i.chromium });
if (kind === 'visible' && !chromiumFirst && i.chromium) list.push({ label: `Playwright Chromium (${i.chromium})`, path: i.chromium });
if (list[0]) return list[0];
const skipped = env.STOREBOUND_CHROME && !i.storeboundChrome && kind !== 'chrome' ? `; STOREBOUND_CHROME ${env.STOREBOUND_CHROME}: no such file` : '';
throw new Error(`no usable browser (looked for ${LOOKED_FOR[kind]})${skipped}. `