← Blog

BLOG

Claude Browser Agent: Build a Remote Chromium Workflow

Learn how a Claude browser agent can use Playwright over CDP, manage session state, verify actions, and run against hosted Chromium safely.

8 min readRemote Browser
Ivory computer towers connected across terracotta platforms in a quiet desert landscape
The infrastructure behind your browserREMOTE BROWSER / ILLUSTRATION

A Claude browser agent is an application that lets Claude request browser actions and sends the results back to the model. Claude handles reasoning; your application defines the available tools, runs them, and decides what information to return. A browser runtime supplies the actual Chromium session.

One practical setup is a Claude tool loop connected to hosted Chromium through the Chrome DevTools Protocol (CDP). Playwright can drive the session, while your application controls which pages and actions the agent may use. This keeps browser execution separate from the model call and gives you a place to manage timeouts, session state, and access rules.

This guide explains that architecture, shows a TypeScript Playwright connection, and covers decisions that affect reliability in production. For the runtime side, see the Remote Browser documentation and the guide to remote browsers for AI agents.

What a Claude browser agent needs

Claude does not, by itself, provide your application with a browser session that persists across tool calls. Your integration supplies the tools and runs them. A useful design has four parts:

  • Model: Interprets the task and requests a tool call.
  • Tool controller: Validates the request, applies policy, and invokes browser code.
  • Browser runtime: Hosts Chromium and keeps the active pages and session state.
  • Observation: Returns a limited result, such as a page title, visible text, or screenshot, to Claude.

The typical cycle is:

  1. Your application sends Claude a task and a description of the tools it can use.
  2. Claude requests an action, such as opening an allowed URL or reading a page.
  3. The controller validates the request and runs the action in the active browser session.
  4. The controller returns the result to Claude, which can request another action or finish.

This separation matters. Claude can suggest a browser action, but your application still decides whether to run it. A tool that accepts arbitrary JavaScript or unrestricted URLs gives the model a much broader reach than a tool that performs a small set of validated operations.

Choose a browser control path

A Claude browser agent can use different control methods. The right choice depends on what the task needs and where you want browser execution to happen.

Control pathUseful whenMain trade-off
Local Chromium with PlaywrightYou are prototyping on a developer machine or running a controlled workerYour application must install, launch, secure, and maintain the browser environment
Hosted Chromium with Playwright over CDPThe agent runs in a server or worker and needs a browser session managed separatelyCDP adds a remote connection and network latency; test the features your workflow depends on
Screenshot and coordinate toolsThe task depends on visual layout or controls that are difficult to inspect through the DOMCoordinate actions can be sensitive to layout changes and may need more visual verification

For many web workflows, Playwright locators give the controller a clear way to find and verify page elements. CDP is a practical connection method for Chromium, but Playwright describes connectOverCDP as lower fidelity than its native Playwright connection. Review the Playwright CDP documentation and test the behavior your application relies on.

Connect Playwright to a hosted session

Create a browser session through your browser provider, then pass the session’s CDP WebSocket endpoint to the worker that runs Playwright. The endpoint is a credential: keep it in a secret store or protected environment variable, and avoid logging it.

The example below assumes the endpoint connects to a Chromium session with an existing browser context. It provides a read-only page inspection function. In a Claude integration, your tool dispatcher would call this function after validating a matching tool request.

import { chromium } from "playwright";

const cdpUrl = process.env.REMOTE_BROWSER_CDP_URL;
if (!cdpUrl) {
  throw new Error("REMOTE_BROWSER_CDP_URL is required");
}

const browser = await chromium.connectOverCDP(cdpUrl);
const contexts = browser.contexts();

if (contexts.length === 0) {
  throw new Error("The connected browser has no available context");
}

const context = contexts[0];
const page = context.pages()[0] ?? await context.newPage();
const allowedHosts = new Set(["example.com"]);

export async function readPage(rawUrl: string) {
  const target = new URL(rawUrl);

  if (target.protocol !== "https:" || !allowedHosts.has(target.hostname)) {
    throw new Error("URL is outside the permitted host list");
  }

  await page.goto(target.toString(), {
    waitUntil: "domcontentloaded",
    timeout: 30_000,
  });

  const finalUrl = new URL(page.url());
  if (!allowedHosts.has(finalUrl.hostname)) {
    throw new Error("Navigation ended outside the permitted host list");
  }

  const heading = page.locator("h1").first();
  const headingText =
    (await heading.count()) > 0 ? (await heading.textContent())?.trim() ?? null : null;

  return {
    url: page.url(),
    title: await page.title(),
    heading: headingText,
  };
}

const result = await readPage("https://example.com/");
console.log(result);

This sample intentionally exposes one narrow operation: navigate to an allowed host and return a few page fields. Add operations to match your application’s tasks, such as finding a result or submitting a form. Validate each operation’s inputs in the controller instead of letting the model assemble arbitrary browser code.

In a long-running worker, keep the connection and page state available for the duration of the task. Use your provider’s documented session lifecycle to end the remote session when the job finishes. If your runtime creates contexts differently, select the intended context according to its documentation rather than assuming that the first context is always correct.

Make the tool loop observable and bounded

Browser actions can fail for ordinary reasons: a page may load slowly, a locator may match nothing, or a site may change its markup. The controller should report these failures clearly so Claude can choose whether to retry, inspect the page, or stop.

For each tool call, keep track of:

  • The requested action and its validated inputs. Record enough to understand what the agent tried without storing secrets unnecessarily.
  • The browser result. Return specific evidence, such as a page title, matching text, or a confirmation message.
  • The time spent and the outcome. Use per-action timeouts and a limit on total steps or elapsed task time.
  • The active session. Tie calls to the intended task so that a later request does not accidentally use another user’s browser state.

A Claude browser agent should verify important actions against the page. After a form submission, for example, check for a visible confirmation or a changed record state. A successful click only proves that the browser dispatched a click; it does not prove the website accepted the change.

Return concise observations to the model. A focused result is easier to use than a full page dump, and it reduces how much page content enters the model’s context. If the result is ambiguous, let the agent request a follow-up inspection through another defined tool.

Handle state, authentication, and untrusted pages

Some tasks need to preserve a login across multiple steps. Persistent browser profiles can provide that state, while isolated sessions help keep separate tasks from sharing cookies or local storage. Choose the behavior explicitly: reuse a profile when continuity is required, and isolate sessions when one task should not inherit another task’s state.

Treat page content as untrusted input. A page can contain text that looks like instructions to the agent. Your controller should keep tool policy outside the page content and should not let a page redefine what the agent is allowed to do. Keep credentials and secrets out of returned page text, model prompts, and logs wherever possible.

Start with a narrow set of actions. For example, a research workflow might allow navigation to an approved set of hosts and extraction of visible headings and links. A workflow that purchases, deletes, or submits data needs stricter checks, including a clear authorization rule before the controller performs consequential actions.

Remote Browser provides hosted Chromium sessions, CDP access, persistent profiles, a live viewer, session isolation, configurable browser settings, and usage controls. These capabilities can help separate browser execution from the application worker and make sessions easier to inspect. Review the remote browser overview to understand the hosted runtime model.

Production criteria for a Claude browser agent

Before deploying a Claude browser agent, check how the full workflow behaves under normal and failed conditions:

  • Session setup: Confirm how your application obtains the CDP endpoint, selects a profile, and associates the session with a task.
  • Access policy: Restrict destinations and actions to what the workflow requires. Consider redirects and page requests as part of your network policy.
  • Timeouts and retries: Set limits for navigation, locator waits, and total task duration. Retry only when repeating the action is safe.
  • Verification: Check the resulting page state after each consequential action, and return that evidence to Claude.
  • Debugging: Keep useful logs and use a live viewer or session recordings where available. Redact endpoint credentials and sensitive page data.
  • Usage and cost: Estimate session duration and concurrency for your workload, then check current pricing and limits.

A hosted browser does not remove the need for application-level policy, and CDP does not make a workflow automatically reliable. The controller still needs to manage the session, validate tool requests, and confirm that the site reached the intended state.

When a remote browser fits

Use hosted Chromium when your Claude application runs separately from the browser, when you need a managed session for a worker, or when you want to inspect browser activity through a live viewer. It can also help keep browser profiles and task sessions separate from the machine running your model integration.

A local browser can be simpler for development and tightly controlled jobs. A hosted session introduces a network hop and provider-specific session lifecycle, so measure the workflow with realistic pages and expected concurrency. Check the Remote Browser documentation for connection and session details, and use pricing information to plan usage.

The useful design principle is to keep Claude’s decisions, your application’s permissions, and the browser’s execution in distinct parts of the system. With that boundary in place, a Claude browser agent can use Playwright and hosted Chromium while your application retains control over what it can access and how success is verified.