Overview
CDP (Chrome DevTools Protocol) mode allows agent-browser to connect to an existing browser instance instead of launching a new one. This enables control of:- Electron apps
- Chrome/Chromium with remote debugging enabled
- WebView2 applications
- Any browser exposing a CDP endpoint
- Remote browser services (Browserbase, Browser Use, Kernel)
Quick Start
Connect to Chrome
Auto-Connect
Use--auto-connect to automatically discover and connect to a running Chrome instance without specifying a port:
- Reading Chrome’s
DevToolsActivePortfile from the default user data directory - Falling back to probing common debugging ports (9222, 9229)
chrome://inspect/#remote-debugging (which uses a dynamic port).
CDP Endpoint Format
The--cdp flag accepts either a port number or a full WebSocket URL:
Port Number (Local)
src/browser.ts:1515-1518:
WebSocket URL (Local or Remote)
src/browser.ts:1509-1514:
Starting Chrome with Remote Debugging
macOS
Linux
Windows
Headless Chrome
Connection Lifecycle
CDP connections persist in the daemon across multiple commands:src/browser.ts:1550, the CDP endpoint is cached:
src/browser.ts:854-857):
Auto-Connect Discovery
Auto-connect attempts multiple discovery strategies in order:1. DevToolsActivePort File
Reads the WebSocket URL from Chrome’s active port file (Chrome 144+):src/browser.ts:1609-1610.
2. Port Probing
Probes common debugging ports (9222, 9229) if the file doesn’t exist:src/browser.ts:1655-1691 for the full auto-connect implementation.
Limitations
No Profile Support
Profiles cannot be used with CDP connections because the remote browser already has its own profile:src/browser.ts:1204-1206:
No Extension Support
Extensions cannot be loaded via CDP connections:src/browser.ts:1200-1202.
Download Path Ignored
The--download-path flag is ignored with CDP connections because downloads use the remote browser’s configuration:
src/browser.ts:1252-1257.
Page Switching
CDP sessions are page-specific. Switching pages invalidates the current CDP session: Fromsrc/browser.ts:1830-1858:
src/browser.ts:1921-1930).
Advanced Features
Screencast (Live Preview)
CDP mode supports screencasting for live browser preview:src/browser.ts:1942-1997, screencast uses CDP’s Page.startScreencast command.
Input Injection
CDP mode supports direct input injection (mouse, keyboard, touch) via the stream server or programmatically:src/browser.ts:2164-2228.
CDP Profiling
Use CDP’s Tracing API for performance profiling:src/browser.ts:2021-2162.
Use Cases
Electron Apps
Control Electron apps that expose a CDP endpoint:Browser Extensions Development
Test browser extensions in a real Chrome instance:WebView2 Apps
Connect to WebView2 applications on Windows:Remote Browser Services
Connect to remote browsers provided by cloud services:src/browser.ts:908-1153 for implementation).
Security Considerations
Localhost Only
When starting Chrome with--remote-debugging-port, the debugger binds to localhost by default:
Authentication
The Chrome DevTools Protocol does not require authentication by default. Anyone with network access to the debugging port has full control of the browser. For remote CDP connections, use:- TLS (wss://) to encrypt the connection
- Token-based authentication in the WebSocket URL
- Network-level security (VPN, SSH tunnel, firewall)
CDP Session Isolation
Each CDP session can control all pages in the browser. For security-sensitive automation, launch a dedicated browser instance:Troubleshooting
Connection Refused
- Verify Chrome is running with
--remote-debugging-port=9222 - Check if the port is actually listening:
lsof -i :9222(macOS/Linux) ornetstat -ano | findstr :9222(Windows) - Try a different port if 9222 is already in use
Connection Dropped
If the remote browser crashes or restarts, the CDP connection is lost. Reconnect with:Auto-Connect Not Working
Auto-connect requires Chrome to be running with remote debugging enabled. If it fails:- Manually enable remote debugging in
chrome://inspect/#remote-debugging - Or start Chrome with
--remote-debugging-port=9222 - Use
--cdp 9222explicitly instead of--auto-connect