Skip to main content

Module sidecar

Module sidecar 

Source
Expand description

Playwright sidecar — spawn and talk to a Node script that wraps playwright-core.

This module owns the lifecycle of the Node child process and the NDJSON-over-stdio JSON-RPC channel to it. Tools in the MCP layer call Sidecar::call with (method, params) and get back the parsed result (or an error).

Lifecycle (per Sidecar instance):

  1. Sidecar::start — picks a launcher (bun preferred, then node), prepares the cache directory containing the bundled sidecar.mjs + package.json, runs bun install / npm install if the deps aren’t already there, then spawns the child with stdin/stdout piped.
  2. Sidecar::connect — sends a connect RPC carrying the CDP endpoint URL so the sidecar holds a Playwright Browser for the duration.
  3. Sidecar::call — send a request, receive the response. Many requests can be in flight (each carries a unique id); responses are routed by id.
  4. Drop — closes stdin, the child exits.

Errors that originate inside the sidecar arrive as JSON-RPC error responses; we surface them as anyhow errors. Connection-level failures (sidecar process gone, stdio closed) surface as SidecarGone so the caller can decide whether to restart.

Modules§

assets
Cache-dir management for the embedded sidecar assets.

Structs§

Sidecar
Live sidecar handle. Cloneable: behaviour is shared through Arcs inside.
SidecarConfig
User-facing configuration for spawning a sidecar.

Enums§

Launcher
Which runtime + package manager we use to launch the sidecar.

Constants§

DEFAULT_PLAYWRIGHT_VERSION
Default playwright-core version pinned in assets/playwright-sidecar/package.json. Overridable via --playwright-version (CLI) or SidecarConfig::version.