Skip to main content
Glama
README.md
# browser-agent

Let the AI apps you run on your own computer (Claude Desktop, Cursor, your own scripts) work in your **real** browser tabs.
An MCP server and command line tool on your computer, plus a Chrome (Manifest V3) extension, with an experimental Firefox build.

- npm package: https://www.npmjs.com/package/@agentruntime-labs/browser-agent
- Project page: https://www.agentruntime.io/labs/browser-agent
- Privacy policy: https://www.agentruntime.io/legal/browser-agent-privacy
- Sibling project: [desktop-agent](https://github.com/agentruntime-io/desktop-agent), which sends real mouse and keyboard input to native Windows apps.
- Licence: Apache-2.0 ([LICENSE](LICENSE), [NOTICE](NOTICE), [third-party licences](docs/THIRD_PARTY_LICENSES.md)).

How it fits together: **MCP host or command line** ↔ **local helper** (this package) ↔ **WebSocket on `127.0.0.1`** ↔ **browser extension** ↔ **your tab**.
Nothing is sent to AgentRuntime. What an agent reads from a page goes to the AI app that asked for it, and that app decides what to do with it.

> **It works in your real, signed-in browser.** An agent can do what you can do on a page. Read [docs/SAFETY.md](docs/SAFETY.md) first, and use the tab modes (below) to limit which tabs it may touch.

## Quick start

The extension does nothing on its own: it is the browser half of a helper that runs on your computer.

1. **Install the helper** (Node.js 18 or newer):
   ```
   npx @agentruntime-labs/browser-agent install
   ```
   It adds the `browser-agent` server to Claude Desktop and Cursor (a `.bak-<time>` copy of each config is saved first). Restart them afterwards. For a plain command line with no AI app: `npm install -g @agentruntime-labs/browser-agent`, then `browser-agent status`.
2. **Install the extension.** Chrome: from the Chrome Web Store (link to be added at publication), or **Load unpacked** the `extension/` folder from the npm package or this repository. Firefox (experimental): build a Firefox copy, see [docs/FIREFOX.md](docs/FIREFOX.md).
3. **Pair it, once.** Run `browser-agent token`, click the extension icon, open **Advanced**, paste the **Pairing token**, press **Connect**. The popup shows **Connected**. Give each Chrome profile a name in the popup.
4. **Try it:** `browser-agent call get_current_tab`, or ask your AI app to take a screenshot of the current tab.

## What you control

- **Tab mode** (set only in the popup, an agent cannot change it): **Freeform** (any tab), **Follow** (only the tab you are on) or **Pinned** (only tabs you pin). Calls outside the allowed tabs are refused.
- **DevTools access** (off until you allow it, for 10 minutes or until you turn it off): needed for dark-mode emulation, full-page and hidden-tab screenshots, trusted mouse input, recording and clipboard. Chrome shows its own debugging bar while it is in use.
- **Script evaluation** (`browser_evaluate`) is off unless you tick it in the popup **and** start the helper with `BROWSER_AGENT_ALLOW_EVAL=1`.
- **Disconnect** in the popup stops all access at once.

## Settings

Optional environment variables for the helper:

| Variable | Effect |
|----------|--------|
| `BROWSER_AGENT_HOME` | Where the helper keeps its files (default `~/.ar_browser`). |
| `BROWSER_AGENT_SESSION_LOG` | Session log of every tool call: **on by default** in `~/.ar_browser/logs/`. Set `0` to turn it off. |
| `BROWSER_AGENT_ENFORCE_NAV_DISCIPLINE` | Default on: read the page before the next navigation. Set `0` to turn it off. |
| `BROWSER_AGENT_WS_PORT` | WebSocket port (default 18791; the helper tries the next ports if it is taken). |
| `BROWSER_AGENT_CONFIRM_CROSS_ORIGIN=1` | Ask you in the browser before navigating to a different site. |
| `BROWSER_AGENT_CONFIRM_TAB_CLOSE=1` | Ask you before a tab is closed. |
| `BROWSER_AGENT_ALLOW_EVAL=1` | Allow `browser_evaluate` (see above). |
| `BROWSER_AGENT_PACING=1` | A short, varying wait between actions and step-by-step typing, for pages that react to every click or keystroke. Also `BROWSER_AGENT_PACING_MIN_MS` (400) and `BROWSER_AGENT_PACING_MAX_MS` (1200). |

Older names still work with a warning: `BROWSER_AUTOMATION_*` for every setting, and `BROWSER_AGENT_HUMAN_LIKE*` for pacing.

## Files the helper writes

On first start the helper creates `~/.ar_browser/`:

| Path | Purpose |
|------|---------|
| `logs/` | Session log (JSON lines) and screenshots. It holds tool arguments (including text an agent typed) and the first part of each result. Delete it when you like. |
| `sessions/` | State, so an agent can resume a session. |
| `skills/` | Skill files for agents (copied from `skills/`). |
| `bridge-token` | The pairing token (one secret per computer). |

## Run from source

```bash
cd server && npm install && npm run build && cd ..
npm install            # repository root: needed for the shell commands (status, call, daemon, ...)
node cli/main.mjs install
```

Or start only the helper: `cd server && npm start`. It listens on `127.0.0.1`, accepts connections only from the extension (`chrome-extension://…` or `moz-extension://…`) or from a program that sends no `Origin` header, and requires the pairing token. Web pages are refused with HTTP 403. `npm run start:insecure` turns the token off for development; web pages are still refused.

**One helper per port.** Each MCP host starts its own helper, and each helper binds its own port (shown as `BRIDGE_PORT` on stderr). The extension tries the ports from 18791 upward. If an `EADDRINUSE` error appears, another helper (or a leftover `node` process) already holds the port: free it, or set `BROWSER_AGENT_WS_PORT`.

Manual MCP config, if you do not use `install`:

```json
{
  "mcpServers": {
    "browser-agent": {
      "command": "node",
      "args": ["/absolute/path/to/browser-agent/server/dist/main.js"]
    }
  }
}
```

`chrome://`, `edge://` and other browser pages cannot be automated: point the tab at an `http(s)://` page.

## Command line

The `browser-agent` command drives the browser without an MCP host: `browser-agent help-control` lists the commands. Quoting URLs in PowerShell, cmd and bash: [docs/SHELL_QUOTING.md](docs/SHELL_QUOTING.md). Tool reference: [docs/MCP_TOOLS.md](docs/MCP_TOOLS.md). A managed Chromium (headless or headed) is available as an option: [docs/MANAGED_BROWSER.md](docs/MANAGED_BROWSER.md).

Every tool has a Zod output schema and returns validated `structuredContent` (`server/src/toolSchemas.ts`).

## Tests

```bash
cd server
npm test               # unit tests (vitest)
npx playwright install chromium
npm run test:e2e       # real Chromium with the unpacked extension (headed; needs a display)
```

`PW_HEADLESS=1` is not supported for the e2e suite: headless Chromium does not load extensions.

## Documents

[Safety and threat model](docs/SAFETY.md) · [Architecture](docs/ARCHITECTURE.md) · [Wire protocol](docs/MESSAGES.md) · [Extension permissions](docs/EXTENSION_MANIFEST.md) · [Tools](docs/MCP_TOOLS.md) · [Firefox](docs/FIREFOX.md) · [Vision and scope](docs/VISION.md) · [Changelog](CHANGELOG.md) · [Security policy](SECURITY.md)

## Skill for Claude

`skills/browser-agent/SKILL.md` teaches an agent to use this tool carefully. Copy the `browser-agent` folder into `~/.claude/skills/` (or a project's `.claude/skills/`).