Run Playwriter browser automation tasks via AI coding agents inside a Kernel cloud browser.
This tool creates a Kernel browser session with the Playwriter Chrome extension, installs an AI coding agent (Cursor, Claude Code, or OpenCode), builds Playwriter from source, and executes prompts that can control the browser using natural language.
- Go 1.22+
- Kernel API Key - Get from Kernel Dashboard
- Agent API Key:
- For Cursor:
CURSOR_API_KEYfrom your Cursor subscription - For Claude:
ANTHROPIC_API_KEYfrom Anthropic - For OpenCode:
ANTHROPIC_API_KEYfrom Anthropic (or configure other providers via opencode auth)
- For Cursor:
- Playwriter extension uploaded to Kernel (one-time setup, see below)
Upload the Playwriter Chrome extension to your Kernel account:
# Install Kernel CLI if needed
brew install onkernel/tap/kernel
# Download the Chrome extension and upload to Kernel
kernel extensions download-web-store \
"https://chromewebstore.google.com/detail/playwriter-mcp/jfeammnjpkecdekppnclgkkffahnhfhe" \
--to ./playwriter-ext
kernel extensions upload ./playwriter-ext --name playwriterNote: Playwriter has two components: a Chrome extension (uploaded above) and a relay/MCP server. The Chrome extension is from the Web Store, but the relay is built from source during setup because the npm package is outdated.
go build -o playwriter-in-kernel .export KERNEL_API_KEY="your-kernel-api-key"
export CURSOR_API_KEY="your-cursor-api-key" # For cursor agent
export ANTHROPIC_API_KEY="your-anthropic-api-key" # For claude or opencode agent
# Using Cursor
./playwriter-in-kernel -agent cursor -p "use duckduckgo to find the latest news in NYC"
# Using Claude Code
./playwriter-in-kernel -agent claude -p "use playwriter to navigate to example.com"
# Using OpenCode
./playwriter-in-kernel -agent opencode -p "use playwriter to navigate to example.com and tell me the page title"| Flag | Description | Default |
|---|---|---|
-p |
Prompt to send to the agent (required) | |
-agent |
Agent to use: cursor, claude, or opencode (required) |
|
-s |
Reuse an existing browser session ID | |
-m |
Model to use | opus-4.5 |
-timeout-seconds |
Browser session timeout | 600 |
-agent-timeout |
Hard timeout for agent (0 = no limit) | 0 |
-d |
Delete browser session on exit | false |
# Basic usage with Cursor
./playwriter-in-kernel -agent cursor -p "use playwriter to navigate to news.ycombinator.com and summarize the top 3 stories"
# Use Claude Code instead
./playwriter-in-kernel -agent claude -p "use playwriter to navigate to example.com and describe what you see"
# Reuse an existing session (faster for multiple prompts)
./playwriter-in-kernel -agent cursor -s f9v6br0tme7epagxtdss952x -p "click the first link"
# Auto-cleanup after running
./playwriter-in-kernel -agent cursor -d -p "navigate to example.com and tell me what the page says"
# Set a timeout to prevent hanging
./playwriter-in-kernel -agent-timeout 120 -p "search for recent news"
# Longer browser timeout for debugging (30 minutes)
./playwriter-in-kernel -timeout-seconds 1800 -p "explore the website"- Creates a Kernel browser with the Playwriter extension pre-loaded
- Pins the extension to the Chrome toolbar
- Installs the agent (Cursor or Claude Code)
- Builds Playwriter from source with the extension allowlist disabled
- Starts the Playwriter relay server
- Configures MCP to use the locally built Playwriter
- Activates Playwriter by clicking the extension icon
- Runs the agent with your prompt, streaming output in real-time
- Displays results including tool calls and assistant responses
The codebase uses an agent-agnostic interface so Cursor, Claude, and OpenCode all follow the same setup flow:
.
├── main.go # CLI entrypoint and orchestration
├── agent/
│ ├── agent.go # Agent interface and shared utilities
│ ├── cursor.go # Cursor-agent implementation
│ ├── claude.go # Claude Code implementation
│ └── opencode.go # OpenCode implementation
├── browser/
│ └── setup.go # Browser setup, Playwriter install, and activation
└── stream/
└── parser.go # Output stream parsing and display
All agents implement the Agent interface:
- Name() - Returns "cursor", "claude", or "opencode"
- Install() - Installs the agent CLI
- ConfigureMCP() - Sets up MCP server configuration
- Run() - Executes a prompt and streams output
- RequiredEnvVar() - Returns the API key env var name
- DefaultModel() - Returns the default model
Playwriter has two parts:
-
Chrome Extension (from Web Store): Injected into the browser, captures CDP commands. You upload this to Kernel once during setup.
-
Relay/MCP Server (built from source): Bridges between the AI agent and the Chrome extension. Built automatically during each session setup because the npm package is outdated.
The relay build process:
- Clone playwriter from GitHub (latest main branch)
- Patch the relay to disable extension ID validation (it has a hardcoded allowlist that doesn't include the uploaded extension's ID)
- Install dependencies with pnpm (required for workspace dependencies), run build (uses bun internally)
- Start the relay server on port 19988
- Configure MCP to use the locally built server
- PTY Requirement: All agents require a pseudo-terminal for output. The tool uses
script -qto allocate one. - HOME Environment: Kernel's process exec defaults to
HOME=/. The tool explicitly setsHOME=/home/kernel. - Extension ID: The Chrome extension ID (
hnenofdplkoaanpegekhdmbpckgdecba) is derived from the extension's public key and is consistent across all Kernel users. - Extension allowlist: The Playwriter relay has a hardcoded allowlist of known extension IDs. The extension ID when uploaded to Kernel isn't in this list, so we patch the relay to disable validation.
- Claude as kernel user: Claude Code refuses
--dangerously-skip-permissionsas root, so we usesu - kernel. - Build from source: The npm package is outdated, so we build the relay from source to get the
/extensionwebsocket endpoint.
When you run without -d, the browser session stays alive. You can reuse it for faster subsequent runs:
# First run - note the session ID in the output
./playwriter-in-kernel -agent cursor -p "navigate to github.com"
# Output: Reuse: playwriter-in-kernel -agent cursor -s f9v6br0tme7epagxtdss952x -p "..."
# Subsequent runs - skip setup, go straight to the prompt
./playwriter-in-kernel -agent cursor -s f9v6br0tme7epagxtdss952x -p "click on Explore"- Playwriter - Browser automation extension and MCP server
- Kernel - Cloud browser infrastructure
- Cursor CLI
- Claude Code
- OpenCode - Open source AI coding agent