Lines 39-79javascript
39 const requested = String(explicit || "").trim();
40 if (requested && fs.existsSync(requested)) return requested;
41 return chromeExecutableCandidates().find((candidate) => fs.existsSync(candidate)) || null;
44async function endpointReady(endpoint) {
46 const response = await fetch(`${endpoint}/json/version`, {
47 signal: AbortSignal.timeout(750),
49 if (!response.ok) return false;
50 const payload = await response.json();
51 return Boolean(payload?.webSocketDebuggerUrl);
57/** Start (or reuse) a dedicated, persistent Google Chrome CDP profile. */
58export async function ensureChromeCdp(options = {}) {
59 const configuredHome = String(
60 options.home || process.env.BETTERWRIGHT_HOME || path.join(os.homedir(), ".betterwright"),
62 const port = Math.max(1024, Math.min(Number(options.port) || DEFAULT_CDP_PORT, 65535));
63 const endpoint = `http://127.0.0.1:${port}`;
64 if (await endpointReady(endpoint)) {
65 return { endpoint, profileDir: path.join(configuredHome, "chrome-cdp-profile"), started: false };
68 const executable = findChromeExecutable(options.executablePath);
69 if (!executable) throw new Error("Google Chrome is not installed.");
70 const profileDir = path.join(configuredHome, "chrome-cdp-profile");
71 fs.mkdirSync(profileDir, { recursive: true, mode: 0o700 });
73 executable,
HighSame File Env Network Execution
A single source file combines environment access, network access, and code or shell execution; review context before blocking.
src/chrome.mjsView on unpkg · L59 75 `--remote-debugging-port=${port}`,
76 "--remote-debugging-address=127.0.0.1",
77 `--user-data-dir=${profileDir}`,
79 "--no-default-browser-check",