function spawn
spawn(
chromePath: string | null | undefined,
args: string[],
headless?: boolean,
onSpawn?: (handle: ChromeHandle) => void
): Promise<EarlyChrome | null>

Spawns a headless Chrome process with --remote-debugging-port=0 and resolves once the CDP WebSocket endpoint appears on stderr. Returns null if Chrome is unavailable or fails to start, so callers can fall back to playwright's normal chromium.launch().

import * as Chrome from './index.ts';

await Chrome.spawn(null, Chrome.CHROMIUM_ARGS); // null — no Chrome path, caller falls back to chromium.launch()

// Defined, not invoked: a real call spawns Chrome and creates a temp user-data-dir.
async function prelaunch(chromePath: string) {
  return await Chrome.spawn(chromePath, Chrome.CHROMIUM_ARGS); // EarlyChrome — { proc, cdpEndpoint, shutdown }
}

Parameters

chromePath: string | null | undefined
args: string[]
optional
headless: boolean = true
optional
onSpawn: (handle: ChromeHandle) => void

Return Type

Promise<EarlyChrome | null>

Usage

import { spawn } from "lib/chrome/spawn.ts";