import { rootPath } from "./paths.ts"; import { type Browser, chromium, type Page } from "playwright-core"; export async function launchChromium(): Promise { const executablePath = Deno.env.get("CHROMIUM_PATH") ?? findChromiumExecutable(); return await chromium.launch({ executablePath, headless: true, args: ["--no-sandbox", "--disable-dev-shm-usage"], }); } export async function installSelectorProbe(page: Page): Promise { await page.addScriptTag({ path: rootPath("dist", "selector_probe.iife.js") }); } function findChromiumExecutable(): string { const candidates = [ "/usr/bin/chromium", "/usr/bin/chromium-browser", "/usr/bin/google-chrome", "/usr/bin/google-chrome-stable", ]; for (const candidate of candidates) { try { if (Deno.statSync(candidate).isFile) return candidate; } catch { // Keep looking. The explicit error is raised below with the supported override. } } throw new Error("Chromium was not found. Set CHROMIUM_PATH to a Chromium-compatible executable."); }