BLOG
Simplest API to Add Browser Automation to My AI Agent
The simplest API to add browser automation to my AI agent: connect to hosted Chromium via CDP or Playwright. No infra, no session headaches.
# The Simplest API to Add Browser Automation to My AI Agent
If you're building an AI agent that needs to browse the web, fill forms, or scrape dynamic content, you've likely hit the same wall: browser automation is deceptively hard. You start with a local Playwright script, it works for a few hours, then the session dies, the proxy gets blocked, or the cloud worker can't maintain a persistent connection. The simplest API to add browser automation to my AI agent isn't another SDK—it's a hosted browser runtime that speaks standard protocols.
Remote Browser gives you a hosted Chromium instance accessible via a single API call. You don't install browsers, manage profiles, or keep sessions alive across workers. You connect, run your automation, and disconnect. This post explains why that matters, how to use it, and what to look for when evaluating browser automation APIs.
Why Local Browser Automation Fails for AI Agents
Local browser automation works fine for a single script on your laptop. It falls apart in production. Here's why:
- Session persistence: A browser session is tied to a process. When your cloud worker restarts, the session dies. Your agent loses cookies, local storage, and login state.
- Resource constraints: Chromium is memory-hungry. Running multiple instances in a serverless function is impractical.
- Network egress: Your local IP is a fingerprint. Sites block datacenter IPs, and your agent gets a CAPTCHA instead of data.
- Concurrency: Spinning up a browser per task is slow. Cold starts can take seconds, which kills agent latency.
A hosted browser API solves these by moving the browser to the cloud. Your agent connects over WebSocket or HTTP, and the browser runs in a managed environment with persistent profiles and clean network egress.
What Makes a Browser Automation API "Simple"?
"Simple" doesn't mean "fewest lines of code." It means the API handles the hard parts so you don't have to. For browser automation, the hard parts are:
- Browser lifecycle: Launch, configure, and shut down Chromium.
- Session persistence: Keep cookies and profiles alive across connections.
- Protocol compatibility: Speak CDP, Playwright, or Puppeteer without custom adapters.
- Observability: See what the browser is doing in real time.
- Scaling: Handle multiple concurrent sessions without resource contention.
Remote Browser scores high on all five. You get a hosted Chromium instance with a CDP endpoint. You connect with Playwright or Puppeteer using standard client libraries. No custom SDK to learn, no infrastructure to manage.
The Core API: Connect to a Remote Browser
The simplest way to add browser automation to your AI agent is to connect to a hosted Chromium instance via CDP. Here's a TypeScript example using Playwright:
import { chromium } from 'playwright';
// Connect to a hosted Chromium session via CDP
const browser = await chromium.connectOverCDP('wss://remote-browser.dev/cdp/session_abc123');
// Get the default context and page
const context = browser.contexts()[0];
const page = context.pages()[0];
// Navigate and interact
await page.goto('https://example.com');
await page.fill('#search', 'AI agents');
await page.click('button[type="submit"]');
// Wait for results
await page.waitForSelector('.results');
const results = await page.$$eval('.result', els => els.map(e => e.textContent));
console.log(results);
// The session stays alive after you disconnect
await browser.close();That's it. No browser installation, no profile management, no session keep-alive logic. The connectOverCDP call is the entire integration surface.
How to Keep Browser Sessions Alive Across Multiple Cloud Workers
This is the question that stumps most developers. You have a serverless function that spins up, does work, and dies. The browser session needs to survive that lifecycle.
The answer is to decouple the browser from the worker. Remote Browser hosts the Chromium instance independently. Your worker connects, does work, and disconnects. The session persists on the server.
Here's the pattern:
- Create a session via the Remote Browser API. You get a session ID and a CDP WebSocket URL.
- Store the session ID in your agent's state (database, Redis, or even a file).
- Reconnect from any worker using the same session ID. The browser state—cookies, localStorage, active tabs—is intact.
This works because the browser isn't a child process of your worker. It's a standalone service. Your worker is just a client.
Playwright Connect to Existing Browser: The Standard Way
Playwright's connectOverCDP method is the standard way to attach to an existing browser. It's designed for exactly this use case. You point it at a CDP endpoint, and it gives you a Browser object that controls the remote instance.
Remote Browser exposes a CDP endpoint for every session. That means any tool that speaks CDP—Playwright, Puppeteer, Selenium with the CDP bridge—can connect. You're not locked into a proprietary SDK.
This is a major advantage over browser automation APIs that require you to use their custom client. Standard protocols mean your existing code works with minimal changes.
Browser Automation API vs. Managing Playwright Infra Manually
Let's compare the two approaches side by side.
| Aspect | Remote Browser API | Self-Managed Playwright |
|---|---|---|
| Browser installation | None—hosted Chromium | Manual install per environment |
| Session persistence | Built-in, survives disconnects | You must implement keep-alive logic |
| Concurrency | Managed by the platform | You handle resource allocation |
| Network egress | Configurable proxy settings | Your IP, your problem |
| Live debugging | Built-in live viewer | Requires separate tooling |
| Scaling | Automatic | Manual, error-prone |
| Protocol support | CDP, Playwright, Puppeteer | Playwright only |
| Time to first automation | Minutes | Hours to days |
The trade-off is clear. Self-managed Playwright gives you full control but costs you engineering time. A browser automation API trades control for speed and reliability.
Remote Browser Online Free: What You Actually Get
You'll see "remote browser online free" in search results. Free tiers exist, but they're rarely useful for production AI agents. Here's what to look for:
- Session limits: How many concurrent sessions can you run?
- Duration limits: How long can a session stay alive?
- Features: Does the free tier include persistent profiles and live debugging?
Remote Browser offers a free tier for testing. It's enough to validate your integration, but production workloads will need a paid plan. Check the pricing page for current limits and rates.
Browser Control In-App Browser Skill: Codex and Skill.md
If you're using an agent framework like Codex or Claude Code, you might want a browser control skill. The pattern is to define a skill.md file that describes how to use the browser API.
Here's a minimal example:
# Browser Control Skill
## Description
Use the Remote Browser API to automate web tasks.
## Commands
- `browser_navigate <url>`: Navigate to a URL
- `browser_click <selector>`: Click an element
- `browser_type <selector> <text>`: Type text into a field
- `browser_screenshot`: Take a screenshot
## Implementation
Connect to the session via CDP:wss://remote-browser.dev/cdp/session_abc123
Use Playwright's `connectOverCDP` to attach. The session persists across calls.This gives your agent a structured way to interact with the browser. The skill file defines the interface; the CDP connection handles the execution.
Remote Browser Configuration Tool: What to Configure
A good browser automation API lets you configure the environment without touching code. Remote Browser offers:
- Profiles: Persistent browser profiles with cookies, localStorage, and extensions.
- Proxies: Route traffic through specific IPs or regions.
- Viewport: Set screen size and device type.
- User agent: Override the default user agent string.
- Session isolation: Run each session in a separate browser instance.
These settings are available via the API or the dashboard. You can change them on the fly without redeploying your agent.
Playwright Remote Browser: The Practical Integration
If you're already using Playwright, the integration is trivial. You replace chromium.launch() with chromium.connectOverCDP(). Everything else—selectors, actions, assertions—stays the same.
Here's a more complete example showing session reuse:
import { chromium } from 'playwright';
async function runAgentTask(sessionId: string, task: (page: any) => Promise<void>) {
const browser = await chromium.connectOverCDP(`wss://remote-browser.dev/cdp/${sessionId}`);
const context = browser.contexts()[0];
const page = context.pages()[0] || await context.newPage();
try {
await task(page);
} finally {
// Don't close the browser—keep the session alive
await browser.close();
}
}
// Use the same session across multiple workers
await runAgentTask('session_abc123', async (page) => {
await page.goto('https://example.com');
await page.fill('#email', 'agent@example.com');
await page.click('#submit');
});
await runAgentTask('session_abc123', async (page) => {
await page.waitForSelector('.dashboard');
const data = await page.textContent('.dashboard');
console.log(data);
});The session persists between calls. Your agent can pick up where it left off, even if the worker process died in between.
Web Automation API: Production Criteria
When evaluating a web automation API for your AI agent, use these criteria:
- Protocol compatibility: Does it support CDP, Playwright, and Puppeteer? Standard protocols mean you're not locked in.
- Session persistence: Can you disconnect and reconnect without losing state?
- Observability: Is there a live viewer or session recording for debugging?
- Network controls: Can you configure proxies and user agents?
- Pricing model: Is it per-hour, per-session, or per-task? Which matches your workload?
- Reliability: What's the uptime guarantee? How are failures handled?
Remote Browser checks all these boxes. The documentation covers each in detail.
Why Not Just Use a Local Browser?
Local browsers are fine for development. They're terrible for production AI agents. The reasons are technical, not philosophical:
- State loss: Every restart wipes cookies and sessions.
- Resource limits: A single Chromium instance uses 200-500MB of RAM. Multiply that by concurrent agents.
- Network fingerprinting: Your local IP is a single point of failure. Sites block it, and your agent fails.
- No isolation: One bad script can crash the browser, taking down all your agents.
A hosted browser API solves these problems by design. The browser runs in a managed environment, isolated per session, with persistent state and clean network egress.
The Bottom Line
The simplest API to add browser automation to my AI agent is a hosted Chromium runtime with CDP support. Remote Browser provides exactly that. You connect with standard Playwright or Puppeteer clients, manage sessions via a simple API, and get persistent profiles, live debugging, and configurable network settings out of the box.
You don't need to learn a new SDK. You don't need to manage browser infrastructure. You just connect, automate, and disconnect. The browser stays alive in the cloud, ready for your agent's next task.
For more context on how hosted browsers fit into AI agent workflows, read our posts on remote browsers for AI agents and remote browser online. If you're comparing options, our remote web browser guide covers the practical differences.
Ready to try it? Check the pricing page for current rates, or dive into the documentation to see the full API surface. The Playwright CDP documentation is also a good reference for understanding the connection protocol.