← Blog

BLOG

Connect Over CDP: The Production Path to Remote Browser Control

Connect over CDP to hosted Chromium for reliable AI agents and automation. Learn how Playwright and Selenium attach to remote sessions.

September 6, 202611 min readRemote Browser

# Connect Over CDP: The Production Path to Remote Browser Control

If you're building an AI agent or a browser automation pipeline, the phrase "connect over CDP" is the difference between a script that runs on your laptop and a workload that survives in production. The Chrome DevTools Protocol (CDP) is the wire-level interface that lets Playwright, Puppeteer, and Selenium drive a Chromium instance that isn't running in your local process. When you connect over CDP to a hosted browser, you decouple your automation logic from the browser lifecycle—which is exactly what you need for persistent sessions, multi-worker scaling, and giving an AI agent reliable web access.

This guide explains how to connect over CDP to Remote Browser's hosted Chromium, why that matters for AI agents and test suites, and what production criteria you should check before you trust any remote browser provider.

What Does "Connect Over CDP" Actually Mean?

CDP is the protocol that Chrome DevTools uses to inspect and control Chromium. It exposes domains for page navigation, DOM inspection, network interception, JavaScript execution, and more. When you "connect over CDP," your client code speaks this protocol directly to a browser process—either locally or over a WebSocket connection to a remote host.

The practical implication: you don't need to launch a browser binary from your code. Instead, you attach to an existing browser session. This is the foundation of browser-as-a-service architectures. Your Playwright script, Selenium test, or AI agent loop sends CDP commands to a browser that lives in a data center, not on your machine.

For AI agents, this pattern is essential. An agent that needs to log into a portal, navigate a multi-step workflow, or maintain state across turns cannot afford to lose its browser context. When you connect over CDP to a persistent remote session, the browser stays alive regardless of what happens to the worker process that spawned it.

Why Remote Browser Uses CDP as the Core Integration

Remote Browser is built around hosted Chromium sessions that expose CDP endpoints. Every session you create gets a unique WebSocket URL. You point your Playwright or Puppeteer client at that URL, and you're driving a real browser in the cloud.

The architecture is straightforward:

  1. Provision a session via the Remote Browser API or dashboard.
  2. Receive a CDP WebSocket endpoint (e.g., wss://remote-browser.dev/session/abc123).
  3. Connect from your code using Playwright's connectOverCDP, Puppeteer's connect, or a raw CDP client.
  4. Run your automation against a browser that persists independently of your worker.

This model solves a class of problems that local browser automation cannot. If your cloud worker crashes, the browser session remains. If you need to scale from one worker to ten, each worker can connect over CDP to the same session or to dedicated sessions without re-initializing browser state.

Playwright connectOverCDP: The Code Path

Playwright's connectOverCDP method is the most direct way to attach to a Remote Browser session. Here's a TypeScript example that connects to a hosted Chromium instance and performs a basic navigation:

import { chromium } from 'playwright';

// The CDP endpoint from your Remote Browser session
const cdpUrl = 'wss://remote-browser.dev/session/your-session-id';

async function main() {
  // Connect to the existing browser via CDP
  const browser = await chromium.connectOverCDP(cdpUrl);
  
  // Get the default context or create a new one
  const context = browser.contexts()[0] || await browser.newContext();
  const page = await context.newPage();

  // Navigate and interact
  await page.goto('https://example.com');
  await page.fill('#search', 'connect over cdp');
  await page.click('button[type="submit"]');

  // Wait for results and extract data
  await page.waitForSelector('.result');
  const results = await page.$$eval('.result', els => 
    els.map(el => el.textContent?.trim())
  );

  console.log('Results:', results);

  // Don't close the browser—leave the session alive for reuse
  // await browser.close();
}

main().catch(console.error);

Note what's missing: no chromium.launch(), no executable path, no browser binary download. The browser is already running in Remote Browser's infrastructure. You're just attaching to it.

This pattern is particularly useful for AI agents that need to maintain state. Instead of launching a fresh browser for every task turn, the agent connects over CDP to a session that retains cookies, localStorage, and navigation history.

Selenium and connectOverCDP: Bridging the Gap

Selenium 4 supports CDP directly through the DevTools interface, but the more common pattern for remote execution is the WebDriver BiDi protocol. However, if you have an existing Selenium suite and want to connect over CDP to a hosted Chromium, you have options.

The cleanest path is to use Selenium Manager or a custom ChromiumDriver that points to your Remote Browser session's debugger address. Selenium's ChromiumDriver accepts a debuggerAddress capability, which tells it to attach to an already-running Chrome instance via CDP.

ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("debuggerAddress", "remote-browser.dev:9222");
WebDriver driver = new ChromeDriver(options);

This approach works, but it's less flexible than Playwright's native connectOverCDP. For most production workloads, we recommend standardizing on Playwright or Puppeteer when you need CDP-level control. Selenium remains a solid choice for teams with existing WebDriver infrastructure, but the CDP integration is more of an adapter than a first-class citizen.

How to Keep Browser Sessions Alive Across Cloud Workers

One of the most common questions we hear: "How do I keep a browser session alive when my cloud worker dies?" The answer is to separate the browser lifecycle from the worker lifecycle.

When you run Playwright locally, the browser process is a child of your script. Kill the script, and the browser dies. When you connect over CDP to a Remote Browser session, the browser runs as an independent service. Your worker is just a client.

This architecture enables several production patterns:

  • Persistent sessions: Create a session once, store the CDP endpoint, and reconnect from any worker at any time.
  • Worker failover: If a worker crashes mid-task, a new worker can connect over CDP to the same session and resume where the previous one left off.
  • Horizontal scaling: Multiple workers can connect to the same session for read-only tasks, or you can provision dedicated sessions per worker for isolation.

Remote Browser's session API returns a stable WebSocket URL. Store that URL in your orchestration layer (Redis, a database, or your agent's state store). When a worker needs to act, it connects over CDP to that URL.

Giving Your AI Agent Browser Access in Production

AI agents that browse the web have a specific set of requirements that generic browser automation doesn't address. An agent needs to:

  1. Maintain context across multiple turns without re-authenticating.
  2. Handle dynamic content that requires JavaScript execution.
  3. Recover from errors without losing the entire session.
  4. Scale horizontally when handling multiple users or tasks concurrently.

Connecting over CDP to a hosted browser addresses all four. The session persists, JavaScript runs in a real Chromium engine, and the browser is independent of any single agent process.

For agent frameworks like browser-use, LangChain, or custom ReAct loops, the integration pattern is consistent: the agent receives a task, calls a browser tool, and that tool connects over CDP to a Remote Browser session. The session's state persists between tool calls, so the agent can navigate, click, type, and extract without re-initializing.

Playwright Firefox and connectOverCDP: What You Need to Know

A frequent source of confusion is Firefox support. Playwright's connectOverCDP method is explicitly Chromium-only. The Playwright documentation states that connecting over CDP is supported for Chromium, not Firefox or WebKit.

This limitation exists because CDP is a Chromium protocol. Firefox uses the Remote Protocol (which is similar but not identical), and WebKit has its own inspector protocol. If you need Firefox automation, you have two options:

  1. Use Playwright's Firefox WebDriver (BiDi) instead of CDP.
  2. Use Selenium's FirefoxDriver with the GeckoDriver.

For Remote Browser, we focus on Chromium because it offers the most complete CDP implementation and the broadest compatibility with automation libraries. If your workload requires Firefox, you'll need to run it locally or find a provider that supports Firefox's remote protocol—but be prepared for a less mature ecosystem.

Scaling Playwright Browser Workloads Reliably

Scaling browser automation is harder than scaling typical API workloads. Each browser instance consumes significant CPU and memory. If you're running Playwright locally, you're limited by your machine's resources. If you're running it in containers, you're paying for idle browser processes.

When you connect over CDP to Remote Browser, you shift the resource burden to a managed infrastructure. This changes the scaling calculus:

Scaling ApproachLocal PlaywrightRemote Browser via CDP
ConcurrencyLimited by local CPU/RAMConfigurable per session
Session persistenceLost on process exitSurvives worker crashes
Resource cleanupManual or container lifecycleManaged by the platform
Network isolationSingle egress IPConfigurable proxy settings
Browser versionTied to local installManaged by the provider
Session debuggingLocal DevTools onlyLive viewer and CDP access

The table above highlights the key trade-off: local Playwright gives you full control but requires you to manage infrastructure. Remote Browser via CDP abstracts the infrastructure but requires you to trust the provider's session management.

For production workloads, the deciding factor is usually session persistence. If your automation can tolerate losing browser state on crash, local execution might suffice. If not—and AI agents almost always need persistence—a hosted CDP endpoint is the more reliable choice.

Selenium and Playwright Headless Resource Usage

Headless browsers are more resource-efficient than headed ones, but they're not free. A single headless Chromium instance typically uses 200-500 MB of RAM, depending on page complexity. When you run multiple sessions, resource usage scales linearly.

Remote Browser handles this by running each session in an isolated container with configurable resource limits. You don't need to guess how many sessions your server can handle—the platform manages that. This is particularly valuable for AI agents that might spawn dozens of browser sessions in response to user requests.

The practical implication: when you connect over CDP to Remote Browser, you're not just getting a browser. You're getting a resource-managed runtime that isolates sessions, prevents memory leaks from affecting other workloads, and cleans up idle sessions according to your configuration.

What Is a Browser Agent, Really?

The term "browser agent" gets thrown around loosely. In the context of CDP and remote browsers, a browser agent is software that uses a browser as its primary tool for interacting with the web. Unlike a traditional API client that makes structured requests, a browser agent navigates pages, reads rendered content, fills forms, and extracts data from the DOM.

Browser agents are distinct from web scrapers in one important way: they're typically driven by an LLM or a rule-based system that makes decisions based on what it sees. This means the agent needs a browser that can:

  • Render JavaScript-heavy pages accurately.
  • Maintain cookies and sessions across interactions.
  • Provide a clean interface for extracting structured data.
  • Support interruption and resumption without losing state.

Connecting over CDP to a hosted Chromium gives you all of these capabilities. The agent's decision loop runs in your infrastructure, but the browser runs in Remote Browser's cloud. This separation of concerns is what makes production browser agents feasible.

Production Criteria for Choosing a CDP Endpoint

Not all CDP endpoints are created equal. Before you commit to a browser provider, evaluate these criteria:

Session persistence: Can you disconnect and reconnect to the same session? Does the browser survive network interruptions?

Live debugging: Can you watch the browser in real time? This is critical for debugging AI agent behavior.

Profile isolation: Are sessions isolated from each other? Can you use persistent profiles for authenticated workflows?

Proxy support: Can you route traffic through different IPs? This matters for geo-specific testing or avoiding rate limits.

Resource controls: Can you set timeouts, memory limits, and concurrency caps? You don't want a runaway agent consuming excessive resources.

API ergonomics: Is the CDP endpoint stable? Does the provider offer a client library or do you need to handle WebSocket connections manually?

Remote Browser addresses these criteria with a session-based API that exposes CDP endpoints, a live viewer for real-time debugging, persistent profiles, configurable browser settings, and usage controls. The documentation covers the full API surface.

The Bottom Line: CDP Is the Integration Layer

Connecting over CDP is not a feature—it's the fundamental integration pattern for remote browser control. Whether you're using Playwright, Puppeteer, Selenium, or a custom AI agent framework, CDP is the protocol that lets your code drive a browser that isn't running in your process.

For AI agents, this pattern is non-negotiable. An agent that needs to browse the web reliably must have a browser session that persists independently of the agent's execution context. Remote Browser provides exactly that: hosted Chromium sessions with stable CDP endpoints that you can connect to from anywhere.

If you're evaluating browser infrastructure, start with the pricing page to understand session costs, then read about how remote browsers work for AI agents to see the architecture in practice. For a deeper dive into the protocol itself, the Chrome DevTools Protocol documentation is the authoritative reference.

The shift from local browser automation to remote CDP connections is the same shift that happened with databases and compute: from self-managed to managed infrastructure. The browser is becoming a service, and CDP is the API that makes it possible.