Support headless shell debug launch
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { chromium } from "playwright";
|
||||
import { spawn } from "node:child_process";
|
||||
import { existsSync, readdirSync } from "node:fs";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -22,6 +23,22 @@ function now() {
|
||||
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() {
|
||||
if (context) await context.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)));
|
||||
|
||||
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, [
|
||||
"--headless",
|
||||
"--no-sandbox",
|
||||
|
||||
Reference in New Issue
Block a user