> For the complete documentation index, see [llms.txt](https://www.openclawbook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.openclawbook.xyz/en/ch24-browser-control/24.5-source-deep-dive-four-sources-three-gates.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 24.5 Source Deep Dive: Four Browser Sources and Three Security Gates

> **Generated by**: Claude Opus 5 (claude-opus-5\[1m]) **Token usage**: Input \~248,000 tokens, Output \~9,000 tokens (this section) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`); line numbers refer to this commit

***

The browser is the agent's hand reaching into the real world. §24.1–24.4 covered the architecture and the CDP/Playwright layers; this section adds two blocks of source detail: **where the browser instance comes from**, and **how the security boundary is drawn**.

## 24.5.1 A Counterintuitive Fact: It Isn't Headless

The browser subsystem (`src/browser/`, 15,505 lines) centers on a **loopback-only HTTP control service** (default port = gateway port + 2, i.e. 18791). The agent's `browser` tool calls it as a client, and the service drives a real browser over CDP.

The underlying driver is `playwright-core`'s `connectOverCDP` (`src/browser/pw-session.ts:353`) —

> **not Playwright's own headless browser, but an attachment to a real Chrome / Brave / Edge instance.**

That choice matters. Headless browsers are recognized and blocked by a great many sites (anti-bot detection), while a real instance carries a full fingerprint and login state.

## 24.5.2 Four Sources for the Browser

| Source                                       | Details                                                                                                                                                                                                                      |
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **openclaw-managed profile**                 | The gateway launches its own Chrome with user data under `~/.openclaw/browser/<profile>/user-data` (`src/browser/chrome.ts:73-75`); **the window carries an orange marker** and is fully isolated from your everyday browser |
| **Chrome extension relay** (default profile) | Attaches to a tab in the user's system browser through the OpenClaw browser extension plus a relay port (18792)                                                                                                              |
| **Remote CDP**                               | `cdpUrl` points at Browserless / Browserbase and similar; supports both http discovery and direct ws endpoints, **preserving token/basic auth in the URL**                                                                   |
| **Node proxy**                               | The browser lives on another machine, forwarded by the node host's browserProxy (Appendix F.5.2); remote screenshots come back as base64 files                                                                               |

**The orange window marker** is worth calling out: when the agent is driving a browser window on your screen, you need to tell at a glance that *this isn't the window I'm using*.

## 24.5.3 The Tool Surface: Semantics Before Pixels

Core actions:

| Action                      | Notes                                                                                                                                                                                                           |
| --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `snapshot`                  | **An accessibility tree snapshot** — a text tree with stable `ref` handles, not pixels                                                                                                                          |
| `act`                       | click / type / drag / select / press / scroll, referencing nodes by `ref` from the snapshot; also supports `fields` for bulk form filling, `startRef`/`endRef` for dragging, and `textGone` as a wait condition |
| `screenshot`                | Screenshot                                                                                                                                                                                                      |
| Tab management / PDF export | —                                                                                                                                                                                                               |

**The snapshot being a text tree rather than a screenshot is the key to token efficiency** — a page screenshot costs a vision model thousands of tokens; the accessibility tree costs hundreds, and the model can reference nodes precisely by `ref` to act on them.

> **Semantics before pixels**, an order of magnitude better on token efficiency. Screenshots are reserved for when visual confirmation is actually needed.

Snapshots use Playwright's internal `_snapshotForAI` (a type shim at `pw-session.ts:58-62`), with a fallback to a home-grown role snapshot (`pw-role-snapshot.ts:26-45` defines 22 interactive roles).

### The pre-arm mechanism

Dialogs and file choosers use a "pre-arm" design: `browserArmDialog` / `browserArmFileChooser` —

```
first declare "a dialog / file picker is about to appear"
   ↓
then execute the triggering action
```

**Avoiding an async dialog race.** Waiting until the dialog appears and only then handling it risks the dialog having already blocked the page, or having been auto-dismissed.

### The tab registry

`src/browser/session-tab-registry.ts`: tabs opened by an agent session are accounted for and can be cleaned up on session end.

**When several sessions share one browser instance, they don't close each other's pages.**

## 24.5.4 Three Security Gates

### Gate one: navigation SSRF guard

Before each navigate / open-tab, protocol and destination are validated and DNS resolution is pinned by policy; after navigation, the **final URL** is validated again on a best-effort basis (handling redirects).

The most rigorous part is how it treats proxy environment variables:

```ts
// src/browser/navigation-guard.ts:70-78
// Browser network stacks may apply env proxy routing at connect-time, which
// can bypass strict destination-binding intent from pre-navigation DNS checks.
if (hasProxyEnvConfigured() && !isPrivateNetworkAllowedByPolicy(opts.ssrfPolicy)) {
  throw new InvalidBrowserNavigationUrlError(
    "Navigation blocked: strict browser SSRF policy cannot be enforced while env proxy variables are set",
  );
}
```

Translated: the author recognized a **TOCTOU gap between "DNS pre-check" and "the browser's actual connection"** — you pre-check `evil.com`, it resolves to a public IP, you allow it; but the browser's actual connection goes through the proxy configured in the environment, and the proxy can route it anywhere.

**The pre-check becomes meaningless.** So in strict mode it fails closed.

> That's a hard attack surface to think of. **"I validated it" and "the thing actually connected to is what I validated" are two different statements** — any layer of redirect, proxy, or DNS change in between pulls them apart.

**But note the default**: `ssrfPolicy.dangerouslyAllowPrivateNetwork` **defaults to `true`** (trusting the local network); strict mode must be enabled explicitly.

That's consistent with §44.4's trust model (a personal machine at home, where the LAN is yours), but **it's a hazard when deployed on a shared network** — note the `dangerously` prefix, which is telling you exactly that (§44.4.5, "naming is a contract").

### Gate two: auth bootstrap

When the control service starts and finds **no gateway auth configured at all, it auto-generates a `gateway.auth.token` and persists it** (`src/browser/control-service.ts:34-37`).

This closes off "a bare loopback service being abused by another process on the machine."

> **Loopback does not mean safe.** Any process on the same machine — including any software you've installed — can reach a service on 127.0.0.1. Auto-generating a token is a direct answer to the common misconception that "loopback is secure enough."

### Gate three: profile isolation

A managed profile's user-data-dir, CDP port, and window color are all independent — **the agent's login state doesn't contaminate your everyday browser**.

`attachOnly: true` constrains it further to "attach only, never self-launch."

***

## Section Summary

1. **Not a headless browser** — `connectOverCDP` attaches to a real Chrome/Brave/Edge instance, carrying a full fingerprint and login state and evading anti-bot detection.
2. **Four sources**: managed profile (**an orange window marker** shows the agent is using it), Chrome extension relay, remote CDP (cloud browsers), node proxy (another machine).
3. **Snapshots are accessibility text trees, not screenshots** — semantics before pixels, an order of magnitude better on tokens; the model acts on nodes precisely via stable `ref` handles.
4. **Dialogs and file choosers use pre-arming** to avoid async races; the tab registry keeps multiple sessions sharing one browser from interfering.
5. **The SSRF guard's key insight**: there's a TOCTOU gap between DNS pre-check and actual connection, and **an environment proxy renders the pre-check meaningless** — strict mode fails closed when proxy environment variables are detected.
6. **`dangerouslyAllowPrivateNetwork` defaults to `true`** — reasonable for a personal machine at home, hazardous on a shared network; the `dangerously` prefix is the warning.
7. **Auth bootstrap closes off bare loopback services** — **loopback does not mean safe**; any process on the machine can reach it.
