Support headless shell debug launch

This commit is contained in:
Codex
2026-07-08 01:08:31 +00:00
parent 99fcf11b87
commit 1b33fa2940
+19 -1
View File
@@ -1,5 +1,6 @@
import { chromium } from "playwright"; import { chromium } from "playwright";
import { spawn } from "node:child_process"; import { spawn } from "node:child_process";
import { existsSync, readdirSync } from "node:fs";
import { mkdtemp, rm } from "node:fs/promises"; import { mkdtemp, rm } from "node:fs/promises";
import os from "node:os"; import os from "node:os";
import path from "node:path"; import path from "node:path";
@@ -22,6 +23,22 @@ function now() {
return new Date().toISOString(); return new Date().toISOString();
} }
function findChromiumExecutable() {
const preferred = process.env.DEBUG_CHROMIUM_EXECUTABLE || chromium.executablePath();
if (existsSync(preferred)) return preferred;
const browsersRoot = process.env.PLAYWRIGHT_BROWSERS_PATH || path.dirname(path.dirname(preferred));
const headlessShell = readdirSync(browsersRoot)
.filter((entry) => entry.startsWith("chromium_headless_shell-"))
.sort()
.reverse()
.map((entry) => path.join(browsersRoot, entry, "chrome-headless-shell-linux64", "chrome-headless-shell"))
.find((candidate) => existsSync(candidate));
if (headlessShell) return headlessShell;
throw new Error(`No Chromium executable found. Tried ${preferred} and ${browsersRoot}/chromium_headless_shell-*.`);
}
async function close() { async function close() {
if (context) await context.close().catch(() => undefined); if (context) await context.close().catch(() => undefined);
if (browser) await browser.close().catch(() => undefined); if (browser) await browser.close().catch(() => undefined);
@@ -33,7 +50,8 @@ process.on("SIGINT", () => close().finally(() => process.exit(130)));
process.on("SIGTERM", () => close().finally(() => process.exit(143))); process.on("SIGTERM", () => close().finally(() => process.exit(143)));
userDataDir = await mkdtemp(path.join(os.tmpdir(), "aishare-debug-")); userDataDir = await mkdtemp(path.join(os.tmpdir(), "aishare-debug-"));
const executablePath = chromium.executablePath(); const executablePath = findChromiumExecutable();
console.log(`[${now()}] Chromium executable: ${executablePath}`);
browserProcess = spawn(executablePath, [ browserProcess = spawn(executablePath, [
"--headless", "--headless",
"--no-sandbox", "--no-sandbox",