Attach
Connect to an existing browser instead of launching a new one.
Commands
| Command | Description |
|---|---|
attach --cdp=<channel> | Connect to a running browser by channel name |
attach --cdp=<url> | Connect via Chrome DevTools Protocol endpoint |
attach --endpoint=<url> | Connect to a Playwright server endpoint |
attach --extension | Connect via Playwright MCP Bridge extension |
Attach by channel name
Connect to a running Chrome or Edge instance by its channel name. The browser must have remote debugging enabled — navigate to chrome://inspect/#remote-debugging in the target browser and check "Allow remote debugging for this browser instance".
# Attach to Chrome
playwright-cli attach --cdp=chrome
# Attach to Chrome Canary
playwright-cli attach --cdp=chrome-canary
# Attach to Microsoft Edge
playwright-cli attach --cdp=msedge
# Attach to Edge Dev
playwright-cli attach --cdp=msedge-dev
Supported channels: chrome, chrome-beta, chrome-dev, chrome-canary, msedge, msedge-beta, msedge-dev, msedge-canary.
This is the simplest way to connect — no need to start Chrome with special flags or know the debugging port.
CDP endpoint
Connect to any Chromium-based browser with a Chrome DevTools Protocol endpoint:
# Start Chrome with remote debugging
google-chrome --remote-debugging-port=9222
# Connect from the CLI
playwright-cli attach --cdp=http://localhost:9222
playwright-cli snapshot
playwright-cli click e5
Works with:
- Chrome / Chromium with
--remote-debugging-port - Edge with remote debugging
- Electron apps exposing CDP
- Cloud browser services (Browserbase, etc.)
Playwright server endpoint
Connect to a remote Playwright server:
playwright-cli attach --endpoint=ws://localhost:3000
playwright-cli snapshot
Browser extension
Connect to your existing browser tabs using the Playwright MCP Bridge extension. This lets you reuse your logged-in sessions, cookies, and installed extensions.
playwright-cli attach --extension
When to use extension mode
- SSO / 2FA — skip complex login flows by reusing your authenticated session
- Browser extensions — interact with pages that depend on installed extensions
- Existing tabs — automate pages you already have open
Named sessions
Attach creates a session. Use -s to name it:
playwright-cli attach --cdp=chrome -s=debug-session
playwright-cli -s=debug-session snapshot
playwright-cli -s=debug-session click e5
Workflow: connect to your running Chrome
# 1. In Chrome, go to chrome://inspect/#remote-debugging
# and enable "Allow remote debugging for this browser instance"
# 2. Attach by channel name
playwright-cli attach --cdp=chrome
# 3. Interact with your existing tabs
playwright-cli snapshot
playwright-cli screenshot --filename=current-state.png
# 4. Save state for future headless sessions
playwright-cli state-save auth.json
Workflow: debugging a remote browser
# On the remote machine: start Chrome with debugging
google-chrome --remote-debugging-port=9222
# On your machine: connect via SSH tunnel
ssh -L 9222:localhost:9222 user@remote-host
# Attach and inspect
playwright-cli attach --cdp=http://localhost:9222
playwright-cli snapshot
playwright-cli screenshot --filename=remote-state.png
playwright-cli console error