BLOG
Browser Use CDP: Connect AI Agents to Hosted Chromium
Browser use CDP explained: how to connect Playwright, Puppeteer, or Selenium to hosted Chromium for reliable AI agent automation.
# Browser Use CDP: Connect AI Agents to Hosted Chromium
If you're building an AI agent that needs to browse the web, you've likely hit the same wall: local browser automation works in demos but falls apart in production. The Chrome DevTools Protocol (CDP) is the bridge that lets your code talk to a browser, and browser use CDP is how you connect that protocol to a hosted Chromium instance that survives restarts, scales across workers, and doesn't get blocked by anti-bot systems.
This guide explains what CDP means for browser-use workloads, how to connect Playwright or Puppeteer to a remote browser, and what to look for when choosing a hosted CDP endpoint for AI agents.
What Is Browser Use CDP?
CDP is the protocol that Chrome DevTools uses to inspect, debug, and control Chromium-based browsers. Every modern automation tool—Playwright, Puppeteer, Selenium (via the ChromeDriver bridge)—ultimately speaks CDP under the hood.
When we say "browser use CDP," we mean the pattern of connecting your automation code to a browser instance over the network using this protocol. Instead of launching a local Chrome process, you connect to a remote browser that exposes a CDP endpoint.
The practical difference matters:
- Local CDP: Your code spawns Chrome, connects via
localhost, and dies when your process dies. - Remote CDP: Your code connects to a browser running elsewhere, typically in a container or VM, and can reconnect even if your worker crashes.
For AI agents, remote CDP is the difference between a script and a service.
Why Hosted CDP Beats Local Browser Automation
Local browser automation has three fundamental problems that become critical when you're running AI agents:
1. Session Lifespan
AI agents often need to maintain state across multiple steps, retries, or even separate worker processes. A local browser dies with the process that spawned it. If your agent crashes mid-task, you lose the session, cookies, and any in-progress state.
A hosted browser with CDP access keeps the session alive independently of your worker. You can disconnect, reconnect, and pick up where you left off.
2. Scaling and Concurrency
Running 50 browser instances on a single machine is a recipe for resource exhaustion. Each Chromium instance consumes a significant amount of RAM. When you need to scale your agent horizontally across multiple workers, you need browsers that live outside your worker processes.
Hosted CDP endpoints let you spin up browsers on demand, connect from any worker, and tear them down when done—without managing the underlying infrastructure.
3. IP Reputation and Blocking
Websites increasingly block traffic from cloud IP ranges and datacenter networks. If your agent needs to access sites with aggressive bot detection, the IP address of your browser matters as much as the browser itself.
Hosted browser services typically offer configurable proxy settings, letting you route traffic through residential or other IP pools. This is something you simply cannot do with a local Chrome instance.
How to Connect Playwright to a Remote Browser via CDP
The most common pattern for browser use CDP is connecting Playwright to a remote Chromium instance. Here's a minimal TypeScript example:
import { chromium } from 'playwright';
// Connect to a hosted browser via CDP endpoint
const browser = await chromium.connectOverCDP('wss://remote-browser.dev/cdp/your-session-id');
// Get the default context or create a new one
const context = browser.contexts()[0] || await browser.newContext();
// Create a page and navigate
const page = await context.newPage();
await page.goto('https://example.com');
// Interact with the page
await page.click('button.submit');
const result = await page.textContent('.result');
// The browser stays alive even if your process exits
console.log(result);
// Don't close the browser—just disconnect
await browser.close();The key difference from local automation: connectOverCDP instead of launch(). You're attaching to an existing browser rather than creating one. This means:
- The browser persists after your script exits.
- Multiple workers can connect to the same session.
- You can inspect the browser state via a live viewer while your agent runs.
CDP vs. WebDriver: Which Protocol Should You Use?
Most automation frameworks support both CDP and WebDriver (via Selenium). Here's how they compare for browser-use workloads:
| Aspect | CDP (Playwright/Puppeteer) | WebDriver (Selenium) |
|---|---|---|
| Protocol | Chrome DevTools Protocol | W3C WebDriver standard |
| Browser support | Chromium-based only | Chrome, Firefox, Safari, Edge |
| Performance | Faster, lower overhead | Slower, more abstraction |
| Debugging | Native DevTools integration | Limited to WebDriver commands |
| AI agent fit | Better for complex interactions | Better for cross-browser testing |
| Session control | Fine-grained, direct | Coarser, HTTP-based |
For AI agents, CDP is almost always the right choice. Agents need fine-grained control over page state, network conditions, and DOM inspection—all of which CDP provides natively. WebDriver's abstraction layer gets in the way when you need to make decisions based on page content in real time.
What to Look for in a Browser Use CDP Endpoint
Not all hosted CDP endpoints are equal. When evaluating a service for production AI agent workloads, check for these capabilities:
Session Persistence
Your browser session should survive disconnects. If your agent crashes, you should be able to reconnect to the same session with all cookies, localStorage, and DOM state intact. Look for services that support persistent profiles tied to a session ID.
Live Debugging
When your agent makes a mistake, you need to see what happened. A live viewer that shows the browser state in real time—or at least a screenshot history—is essential for debugging. Without it, you're flying blind.
Proxy and IP Configuration
The ability to route browser traffic through different IPs is critical for sites with bot detection. Look for services that let you configure proxy settings per session or per profile.
Session Isolation
If you're running multiple agents, each should get its own isolated browser session. No shared cookies, no cross-contamination. This is table stakes for production use.
Usage Controls
Browser sessions that run indefinitely can rack up costs. Look for services with idle timeouts, max session durations, and automatic cleanup.
Common Browser Use CDP Pitfalls
Even with a good hosted CDP endpoint, there are traps that trip up developers:
1. Forgetting to Disconnect Instead of Close
When you call browser.close() in Playwright, it terminates the browser. If you're using a hosted service, you probably want to disconnect instead:
// This kills the browser
await browser.close();
// This disconnects but keeps the browser alive
await browser.close({ runBeforeUnload: false });Actually, in Playwright, browser.close() always closes the browser. To disconnect without closing, you need to use the CDP session directly or rely on the service's session management. Check your provider's documentation for the correct disconnect pattern.
2. Not Handling Reconnects
Your worker will crash. Your network will blip. Your browser session should survive. Build your agent to reconnect to the CDP endpoint rather than assuming the connection is permanent.
3. Ignoring Context Isolation
Each Playwright context is like a separate browser profile. If you're running multiple agents, use separate contexts or sessions to avoid state leakage.
4. Overlooking Network Conditions
AI agents often need to handle slow pages, timeouts, and network errors. Configure your CDP session with appropriate timeouts and retry logic. Don't assume the network is reliable.
Browser Use CDP in Production: A Practical Checklist
Before you deploy an AI agent that relies on browser use CDP, run through this checklist:
- Can you reconnect to a session after a crash? Test it explicitly.
- Can you see what the browser is doing in real time? You'll need this for debugging.
- Can you isolate sessions between agents? No shared state.
- Can you configure proxies per session? Required for sites with bot detection.
- Can you set usage limits? Idle timeouts and max durations prevent runaway costs.
- Can you scale horizontally? Multiple workers connecting to multiple browser sessions.
Remote Browser: A Hosted CDP Runtime for AI Agents
Remote Browser provides exactly this: hosted Chromium sessions with CDP access, designed for AI agent workloads. Here's what you get:
- Persistent sessions: Your browser stays alive across worker restarts and reconnects.
- Live viewer: Watch your agent's browser in real time to debug failures.
- Persistent profiles: Cookies, localStorage, and session state survive across sessions.
- Configurable proxy settings: Route traffic through different IPs as needed.
- Session isolation: Each agent gets its own clean browser environment.
- Usage controls: Set idle timeouts and session limits to control costs.
The service is compatible with Playwright, Puppeteer, and Selenium, so you can keep your existing automation code and just change where the browser runs.
Getting Started with Browser Use CDP
The fastest way to understand browser use CDP is to try it. Here's a minimal workflow:
- Create a browser session via the Remote Browser API or dashboard.
- Connect to it using
connectOverCDPin Playwright or Puppeteer. - Run your agent logic against the remote browser.
- Disconnect when done—the session persists for your next run.
For a deeper dive, check out our guides on connecting Playwright to remote browsers and keeping browser sessions alive across cloud workers.
CDP and the Future of Browser Automation
The Chrome DevTools Protocol has become the de facto standard for browser automation, and for good reason. It's powerful, flexible, and gives developers direct access to browser internals. As AI agents become more sophisticated, the demand for reliable, scalable CDP endpoints will only grow.
The shift from local to hosted browsers is similar to what happened with databases: first you run it on your laptop, then you realize you need it to be a service. Browser use CDP is the protocol that makes this transition possible.
If you're building AI agents that need reliable browser access, stop fighting local Chrome instances. Connect to a hosted CDP endpoint and let the infrastructure handle the hard parts.
---
*Ready to move your browser automation to the cloud? Check out Remote Browser's pricing and see how hosted Chromium compares to managing your own infrastructure.*