# Agent Browser
<!--
ref: @integrations/agent-browser
type: protocol
tags: [browser, cdp, authenticated-fetch, session, chrome, automation, integration]
aliases: [agent-browser, test-chrome, browser-attach, auth-browser, authed-fetch]
triggers: [login wall, HTTP 401 402 403 on a fetch, redirected to a login page, need to read a page as a signed-in user, the public page shows less than the signed-in view, read a LinkedIn or X page, call a site's API with my session, what is on the tab I have open, CDP browser, test-chrome]
trigger_prompt: A fetch hits a login wall or 401/402/403, or the signed-in view of a site would show more than the public page, or you need to inspect a tab a human has open. Run the block below.
category: integration
last_reviewed: 2026-10-20
complements: [@integrations/agent-browser_/agent-browser-setup, @integrations/agent-browser_/agent-browser-scripting, @integrations/agent-browser_/agent-browser-forms, @integrations/loom, @integrations/linkedin]
audience: [agent-author, terminal-only]
version: 40
updated_at: 2026-11-29T18:00:08.606Z
appendixes: [@integrations/agent-browser_/agent-browser-forms, @integrations/agent-browser_/agent-browser-scripting, @integrations/agent-browser_/agent-browser-setup]
files: [agent-browser.mjs]
-->

Read a page, call a site's API, or inspect a tab **as a signed-in user**, through a dedicated Chrome that agents drive over CDP. One script, `agent-browser.mjs`, downloaded fresh on every run.

## When to use it

Use it whenever a plain HTTP fetch sees less than a signed-in user would:

- **Error codes:** a fetch returns 401, 402 or 403, or redirects to a login page.
- **Sign-in-only content:** DMs, drafts, settings, dashboards and private videos appear only when signed in. Sites like LinkedIn, X and Substack serve a public page that returns 200 but shows a smaller truth.

Ask whether the signed-in view would show *more*, not only whether the request succeeded. If the answer is yes or unknown, use this.

## Setup

First run on a machine, or exit 2 from `start` → **`@integrations/agent-browser_/agent-browser-setup`**. Setup covers the Chrome install, its profile, one-time site sign-in, and keeping it out of the way. To write your own site integration on top of this browser → **`@integrations/agent-browser_/agent-browser-scripting`**. To write a script that fills and submits forms → **`@integrations/agent-browser_/agent-browser-forms`**.

## Run

```bash
B="${TMPDIR:-/tmp}/agent-browser.mjs"
curl -fsSL https://api.protocol.supply/@integrations/agent-browser_/agent-browser.mjs -o "$B"
node "$B" start            # no-op if the browser is already up
node "$B" <action> [args]
```

Needs Node 22+ (or Bun). Stdout carries only the result. Progress and errors go to stderr.

The same file is the library: `import { withPage } from "./agent-browser.mjs"` and `await withPage(url, async (page) => …)` gives you a loaded background tab, closed after. See `_/agent-browser-scripting`.

## Actions

| Action | Returns |
|---|---|
| `check` | JSON `{node, cdpUrl, browser, tabs, crashedTabs}` |
| `start` | Launches the agent Chrome if it isn't up, with background throttling off so tabs nobody is looking at still render. Safe to run every time |
| `read <url>` | The page's visible text, from a background tab (pinned active, so lazy lists still mount) that is closed afterwards. `--html` returns the full HTML; `--settle MS` waits longer for slow apps (default 1500) |
| `fetch <url>` | Response body of an HTTP request made with the browser's cookies, from the URL's own origin. `--method`, `--data`, and a repeatable `--header 'K: V'` shape the request. Use it for a site's JSON or GraphQL endpoints |
| `screenshot <url\|tab> --out FILE.png` | Full-page PNG of a URL (our own tab) or an open tab. Prints the path. `--segments` captures tall pages as 1400 px strips (`FILE-0.png`, …) and prints JSON `{url, shots, blank?}`; a strip listed in `blank` captured nothing |
| `tabs` | JSON list of open tabs: `[{i, title, url, crashed}]` |
| `inspect <tab> text\|html\|links` | Reads a tab that is already open, without navigating it. `<tab>` is an index from `tabs`, or a substring of the tab's URL or title. `links` lists links and buttons with visibility |
| `eval <tab> '<js>'` | JSON result of a JS expression run in an open tab |
| `grep <tab> '<regex>'` | JSON `{url, hits, snippets}`: case-insensitive matches in an open tab's text, with `--context N` characters each side (default 120) |
| `sweep` | Closes crashed tabs (blank URL). This client is immune to them (it attaches only to the tab it uses), but they still hold memory, and they hang any Playwright client |

| Exit | Meaning | Do |
|---|---|---|
| 0 | Done | Use stdout |
| 2 | No browser at `CDP_URL`, or `start` couldn't launch one | Run `start`. If that fails too, go to setup |
| 3 | Redirected to a sign-in page, or HTTP 401/403 | A human signs in to that site once in the agent browser window. Never type credentials yourself |
| 4 | The page couldn't load: a 30 s timeout, a DNS failure, or a refused connection | Check the URL, retry once, then treat the site as down |
| 5 | No open tab matches | Run `tabs` |
| 1 | Usage error, or an unexpected failure | Read stderr |

## Common calls

```bash
node "$B" read https://www.linkedin.com/in/<handle>/ > profile.txt        # a signed-in page as text
node "$B" fetch https://example.com/api/me | jq .                         # a site's own API, with the session's cookies
node "$B" tabs && node "$B" inspect <n> links                             # what is on the page a human left open
```

## Rules

- **The browser is shared and long-lived.** Start it once and leave it up; never kill it or launch a second one on the same profile. A force-kill can drop sign-in sessions. To stop it, send SIGTERM and wait.
- **Work in your own tab.** `read`, `fetch` and `screenshot` open a background tab and close it when done. `inspect`, `eval`, `grep` and `screenshot <tab>` read the user's tabs; never navigate those tabs.
- **Run one job at a time, at a polite pace.** Default to about one page every 2 seconds. On sites that watch for automation (LinkedIn), use one page every 5–10 seconds with varied timing. That spacing is the floor; any daily ceiling belongs to the account owner and is not set here.
- **Stay visible and consistent.** Use the agent browser, never a headless one, for signed-in sites. Reuse its profile; don't create fresh contexts.
- **`CDP_URL`** points at the browser (default `http://127.0.0.1:10020`).

---

*Related: `@integrations/linkedin` · `@protocol/protocol-api` · `@content/youtube/dan-martell/it-s-actually-pretty-easy-to-get-ahead-of-99-of-people-with-ai` · `@content/youtube/dan-martell/i-tested-500-ai-tools-these-will-make-you-rich` · `@content/youtube/tiago-forte/build-a-business-that-runs-itself-5-stages-of-ai-integration`*

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*