chromePath
uses node:path
The Chrome tcm shot uses: the one installed (where Playwright's chrome channel looks), else the Chromium of the
Playwright tcm ships, if it has downloaded it. Undefined when there's neither.
import { shippedPackage } from "#codebase/tcmts/loader/packages"; import fs from "node:fs"; import path from "node:path"; import { pathToFileURL } from "node:url"; export async function chromePath(): Promise<string | undefined> { const installed = process.platform === "darwin" ? ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"] : process.platform === "win32" ? [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env["PROGRAMFILES(X86)"]] .filter((d): d is string => !!d) .map((d) => path.join(d, "Google", "Chrome", "Application", "chrome.exe")) : ["/opt/google/chrome/chrome"]; const found = installed.find((p) => fs.existsSync(p)); if (found) return found; const own = shippedPackage("playwright"); if (!own) return undefined; try { const mod = (await import(pathToFileURL(path.join(own.dir, "index.mjs")).href)) as { chromium?: { executablePath(): string }; default?: { chromium?: { executablePath(): string } }; }; const at = (mod.chromium ?? mod.default?.chromium)?.executablePath(); return at && fs.existsSync(at) ? at : undefined; } catch { return undefined; } }