Agent-readable docs index: /llms.txt. Download /docs.zip to grep all markdown files locally.

Configuration, Environment Variables, and MCP Setup Options

Playwriter is configured through CLI flags and environment variables. No config files needed.

Environment variables

VariableDescriptionDefault
PLAYWRITER_HOSTRemote relay server URLws://localhost:19988
PLAYWRITER_TOKENAuth token for remote connections-
PLAYWRITER_DIRECTCDP connection mode (see below)-
PLAYWRITER_API_KEYAPI key for cloud browsers-

PLAYWRITER_DIRECT

Connect directly to Chrome's DevTools Protocol, bypassing the extension:
ValueBehavior
1Auto-discover Chrome on port 9222
ws://... or wss://...Explicit WebSocket endpoint
host:portResolves via HTTP probe to ws:// URL
# Auto-discover local Chrome PLAYWRITER_DIRECT=1 playwriter session new # Cloud browser provider PLAYWRITER_DIRECT=wss://xxx.cdp.browser-use.com playwriter session new

PLAYWRITER_HOST and PLAYWRITER_TOKEN

For remote access, point to a relay server running on another machine:
export PLAYWRITER_HOST=https://my-tunnel.traforo.dev export PLAYWRITER_TOKEN=MY_SECRET playwriter session new

CLI global flags

FlagDescription
-s, --session <id>Session ID (required for -e, -f)
-e <code>Execute JavaScript code inline
-f <path>Execute JavaScript from a file
--host <host>Remote relay server host
--token <token>Auth token for remote connections
--timeout <ms>Execution timeout (default: 10000)
--patchrightUse @playwriter/patchright-core for stealth

Session new flags

FlagDescription
--browser <key>Browser type: extension ID, headless, cloud, direct:port
--direct [endpoint]Direct CDP: auto-discover or explicit endpoint
--proxy <region>Cloud proxy region (us, de, jp, etc.)
--custom-proxy <url>Custom proxy (host:port or user:pass@host:port)
--timeout <minutes>Cloud browser timeout (1-240, default 60)
--disable-proxy-bandwidth-accelerationLoad images/video with proxy

Browser start flags

FlagDescription
--user-data-dir <dir>Persistent profile directory
--headlessHeadless mode
--headedShow browser window
--disable-sandboxDisable Chrome sandbox

Serve flags

FlagDescription
--host [host]Bind host (default: 0.0.0.0)
--token <token>Auth token (required for public hosts)
--replaceKill existing server on the port

MCP configuration examples

Basic (extension mode)

{ "mcpServers": { "playwriter": { "command": "npx", "args": ["-y", "playwriter@latest"] } } }

Direct CDP

{ "mcpServers": { "playwriter": { "command": "npx", "args": ["-y", "playwriter@latest"], "env": { "PLAYWRITER_DIRECT": "1" } } } }

Cloud browser provider

{ "mcpServers": { "playwriter": { "command": "npx", "args": ["-y", "playwriter@latest"], "env": { "PLAYWRITER_DIRECT": "wss://xxx.cdp.browser-use.com" } } } }

Remote relay

{ "mcpServers": { "playwriter": { "command": "npx", "args": ["-y", "playwriter@latest"], "env": { "PLAYWRITER_HOST": "https://my-tunnel.traforo.dev", "PLAYWRITER_TOKEN": "MY_SECRET" } } } }

Debugging configuration

Playwriter logs to files for debugging:
# Get log file paths playwriter logfile # typically: ~/.playwriter/relay-server.log # CDP JSONL log for protocol debugging jq -r '.direction + "\t" + (.message.method // "response")' ~/.playwriter/cdp.jsonl | uniq -c
Both files are recreated every time the relay server starts.