Skip to main content

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:
Auto-connect discovers Chrome by:
  1. Reading Chrome’s DevToolsActivePort file from the default user data directory
  2. Falling back to probing common debugging ports (9222, 9229)
This is useful when Chrome 144+ has remote debugging enabled via 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)

From src/browser.ts:1515-1518:

WebSocket URL (Local or Remote)

From 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:
From src/browser.ts:1550, the CDP endpoint is cached:
Reconnection is triggered if the endpoint changes (see 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+):
From src/browser.ts:1609-1610.

2. Port Probing

Probes common debugging ports (9222, 9229) if the file doesn’t exist:
See 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:
From src/browser.ts:1204-1206:

No Extension Support

Extensions cannot be loaded via CDP connections:
From 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:
From src/browser.ts:1252-1257.

Page Switching

CDP sessions are page-specific. Switching pages invalidates the current CDP session: From src/browser.ts:1830-1858:
The next command automatically creates a new CDP session for the active page (see src/browser.ts:1921-1930).

Advanced Features

Screencast (Live Preview)

CDP mode supports screencasting for live browser preview:
From 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:
From src/browser.ts:2164-2228.

CDP Profiling

Use CDP’s Tracing API for performance profiling:
From 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:
These providers use CDP under the hood (see 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:
Never expose the debugging port to the network without authentication.

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

Solutions:
  1. Verify Chrome is running with --remote-debugging-port=9222
  2. Check if the port is actually listening: lsof -i :9222 (macOS/Linux) or netstat -ano | findstr :9222 (Windows)
  3. 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:
  1. Manually enable remote debugging in chrome://inspect/#remote-debugging
  2. Or start Chrome with --remote-debugging-port=9222
  3. Use --cdp 9222 explicitly instead of --auto-connect