forked from longtao.wu/droboticflow
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
import { existsSync } from "node:fs";
|
|
import { chromium } from "playwright";
|
|
|
|
export function browserExecutableOptions({
|
|
env = process.env,
|
|
platform = process.platform,
|
|
exists = existsSync,
|
|
bundled = chromium.executablePath(),
|
|
} = {}) {
|
|
const explicit = env.BROWSER_EXECUTABLE || env.BROWSER_PATH;
|
|
if (explicit) {
|
|
if (!exists(explicit)) throw Error(`Configured browser does not exist: ${explicit}`);
|
|
return { executablePath: explicit };
|
|
}
|
|
const candidates =
|
|
platform === "darwin"
|
|
? [
|
|
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
|
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
]
|
|
: ["/usr/bin/chromium", "/usr/bin/chromium-browser", "/usr/bin/google-chrome"];
|
|
const executablePath =
|
|
platform === "darwin"
|
|
? candidates.find(exists) || (exists(bundled) ? bundled : undefined)
|
|
: exists(bundled)
|
|
? bundled
|
|
: candidates.find(exists);
|
|
if (!executablePath)
|
|
throw Error("No Chromium browser found. Set BROWSER_EXECUTABLE or run npx playwright install chromium.");
|
|
return { executablePath };
|
|
}
|