import { spawn } from 'node:child_process'; const FLAGS = [ '--headless', '--hide-scrollbars', /** * Measured (idle editor, 20 s): software WebGL 373% of a core at 8 fps, HD 630 via ANGLE/Vulkan 69% at * 56 fps; no software fallback on purpose. `--use-angle=gl` and `--use-gl=egl` get no WebGL context at all. */ '--use-angle=vulkan', '--ignore-gpu-blocklist', '--enable-gpu', '--enable-features=Vulkan', // None of this serves a headless check, and its stderr was full of GCM sign-in retries. '--disable-background-networking', '--disable-sync', '--disable-extensions', '--no-first-run', '--mute-audio', ]; /** Starts chromium with the CDP port open; `proc.stderr` carries its last words. */ export function launchBrowser({ port, width, height }) { const proc = spawn( 'chromium', // --no-sandbox: this container runs as root, where chromium refuses to start otherwise. [ ...FLAGS, '--no-sandbox', `--remote-debugging-port=${port}`, `--window-size=${width},${height}`, 'about:blank', ], { stdio: ['ignore', 'ignore', 'pipe'] }, ); return { proc, stop: () => proc.kill('SIGTERM'), where: 'local chromium' }; }