File size: 16,676 Bytes
d086025
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# Browser Live Agent

Oxide Browser Live is an autonomous headless-browser capability. The agent has
full control over a browser session: it can open any URL, observe pages, execute
actions, fill forms, submit data, extract structured data, and close the session.
The browser is controlled by a local `browser-sidecar` container running a native
Rust binary (`oxide-browser-sidecar`) that talks the Chrome DevTools Protocol
(CDP) directly to a headless Chromium over a single WebSocket.

> **Warning:** Browser Live runs in Yolo mode. The agent is allowed to type
> passwords, secrets, and other sensitive data into web pages, and to submit
> forms on your behalf. It acts as an extension of your own credentials. Use it
> only on sites and tasks you trust.

## What is supported

- `browser_start` / `browser_observe` / `browser_execute` / `browser_extract` / `browser_debug` / `browser_save_screenshot` / `browser_close` tools
- Navigation to any URL the Chromium instance can reach, including SPA hash-based URLs with `force_reload`
- Semantic form input via `fill` and `type_text` using native value setters and framework-visible events
- Strict `BrowserAction` schema: per-variant `oneOf` with required fields, numeric bounds, and `additionalProperties: false`
- Deterministic DOM value/attribute extraction through `browser_extract` without ad-hoc JavaScript
- Screenshot artifacts, DOM/a11y snapshots, network and console summaries
- Post-action observation freshness diagnostics: result-only vs capture-after actions, structured DOM snapshot errors
- Web UI preview panel and Telegram milestone/blocked/final reporting

## What is not supported

- Manual control, iframe/VNC, or direct user manipulation of the browser
- Vision-based decision layer or screenshot analysis as a browser control mechanism
- MiMo or any intermediate model deciding actions; the main agent directly plans and executes actions

## Page interventions (diagnostic mode only)

Two optional page interventions are available — network-level ad blocking and
cookie consent banner auto-dismissal. They run only in explicit diagnostic
sessions (`diagnostic_debug: true`) and are skipped entirely in the default
`stealth_clean` mode. Diagnostic sessions are not stealth-guaranteed: ads not
loading and consent dialogs closing are intended, observable effects.

### Ad blocking

Network-level ad blocking for diagnostic sessions: ad and tracking requests are
blocked before they reach Chromium, giving the agent cleaner screenshots, cleaner
DOM snapshots, faster page loads, and better privacy.

### Ad blocking configuration

Ad blocking is enabled by default when filter lists are available. The Docker
image includes EasyList and EasyPrivacy at `/opt/adblock/` and sets
`ADBLOCK_FILTERS` in the Dockerfile. The engine activates for diagnostic
sessions automatically; in stealth-clean sessions it is skipped entirely.

To disable ad blocking globally, set:

```bash
ADBLOCK_ENABLED=false
```

`ADBLOCK_FILTERS` is pre-set in the Dockerfile. Only `ADBLOCK_ENABLED=false`
needs to be set at runtime to opt out.

### What ad blocking covers

- Ad scripts (doubleclick.net, googlesyndication.com, etc.)
- Tracking pixels and beacons (google-analytics.com, facebook.net, etc.)
- Third-party ad iframes and resources
- Crypto mining scripts

### Consent auto-dismiss configuration

Consent auto-dismiss is enabled by default when a rules file is available. The
Docker image bundles a merged Consent-O-Matic rules file (203 CMP variants) at
`/opt/consent/rules.json` and sets `CONSENT_FILTERS` in the Dockerfile. The
engine activates for diagnostic sessions automatically; in stealth-clean
sessions it is skipped entirely.

To disable consent auto-dismiss globally, set:

```bash
CONSENT_AUTO_DISMISS=false
```

`CONSENT_FILTERS` is pre-set in the Dockerfile. Only `CONSENT_AUTO_DISMISS=false`
needs to be set at runtime to opt out.

## Requirements

- Docker with Compose
- The `browser-sidecar` service built from `docker/Dockerfile.browser-sidecar` (native Rust binary + Chromium only)

## Configuration

Copy the Browser Live section from `.env.example` and set a non-empty token:

```bash
# .env
BROWSER_AGENT_SIDECAR_TOKEN=<set-a-long-random-token>
BROWSER_AGENT_ENABLED=true
BROWSER_AGENT_SIDECAR_BASE_URL=http://127.0.0.1:8787
```

Maximum concurrent sidecar sessions (default 8):

```bash
# BROWSER_AGENT_SIDECAR_MAX_SESSIONS=8
```

## Deployment

Unified stack:

```bash
docker compose -f docker-compose.yml up --build -d
```

The sidecar REST port is bound to `127.0.0.1:8787` by default. The app service
connects to this loopback address because it runs in host-network mode. Do not
expose the sidecar port on a public interface.

## Verify

Sidecar health:

```bash
curl -fsS http://127.0.0.1:8787/healthz \
  -H "Authorization: Bearer ${BROWSER_AGENT_SIDECAR_TOKEN}"
```

Sidecar self-test (integration tests, requires Chromium):

```bash
cargo test -p oxide-browser-sidecar --test rest_contract -- --ignored --nocapture
```

Web app health:

```bash
curl -fsS http://127.0.0.1:8080/health
```

Expected sidecar response:

```json
{"ok": true, "native": true}
```

## Tools

### `browser_start`
Start a task-local autonomous headless browser session. Optional `start_url`,
`timezone`, `locale`.

### `browser_observe`
Return compact browser state (url, title, loading state, network/console
summaries, optional DOM snapshot) and attach the latest screenshot as a native
image for vision models. Set `fresh: true` to capture a new screenshot instead
of reusing the cached one. `include_dom` defaults to true. Set `include_a11y:
true` to attach an accessibility-tree summary. The DOM sample contains only
interactive elements (links, buttons, inputs, selects) — use `browser_extract`
with a CSS selector for page content.

### `browser_execute`
Execute a single concrete browser action. The `action` field uses a strict
`oneOf` schema with a literal `kind` discriminator. Variants:

| Kind | Fields | Notes |
|------|--------|-------|
| `click_xy` | `x`, `y`, `target_description?` | Coordinate click |
| `click_selector` | `selector` | CSS selector click |
| `fill` | `selector`, `value` | Semantic input via native setters + framework events |
| `type_text` | `selector`, `value` | Same semantic input primitive as `fill` |
| `press` | `key` | Key press |
| `scroll` | `delta_x`, `delta_y` | Scroll deltas |
| `get_element_value` | `selector` | Read scalar value (result-only, no post-observation). For `input[type=checkbox|radio]` returns `"true"`/`"false"` (checked state), not the `value` attribute |
| `execute_javascript` | `expression` | Expression eval; captures post-observation |
| `wait` | `timeout_ms` | Wait (1–60000 ms; no `ms` alias) |
| `wait_for_selector` | `selector`, `timeout_ms` | Wait for element |
| `wait_for_text` | `text`, `timeout_ms` | Wait for text |
| `script` | `steps` | Sequence of non-script actions |
| `navigate` | `url`, `force_reload?` | Navigate; `force_reload: true` restarts browser process for fresh SPA state |

For SPA hash-based URLs (e.g. one-time secret pages) use `navigate` with
`force_reload: true` to guarantee a clean page state — the sidecar replaces the
browser process without profile purge, then opens the exact target URL.

### `browser_extract`
Extract structured data from the current page. Sources:

- **`dom`**: CSS `selector` selects root rows. Two modes:
  - **Legacy single-field**: `attribute` (defaults to `innerText`) returns
    `matches[].value` with `attribute_source` (`property`/`attribute`/`missing`)
    and `found` flag. Raw `properties` and `attributes` are included for
    diagnostics. No ad-hoc `execute_javascript` querySelector hacks needed for
    normal form values.
  - **Structured `fields`**: a `fields` array (up to 20) of `{ name, selector?,
    attribute?, max_chars? }` evaluated relative to each root row. Each match
    returns `matches[].fields.<name>` with `value`, `source`, `found`,
    `truncated`, and `original_chars`. Use this for marketplace/search result
    tables instead of multiple single-field calls. Bounded by `max_results`
    (default 10), `max_value_chars` (default 512), and `max_total_chars`
    (default 16 000).
- **`network`**: Filter by `url_pattern`, `method`, `status_code`; includes
  response bodies when `include_bodies` is true. Network data exists only for
  `diagnostic_debug` sessions.

### `browser_debug`
Fetch browser console/network debug summaries as compact artifact-backed
diagnostics. Supports `since_action_seq` and `limit`.

### `browser_close`
Close a browser session and finalize retained browser artifacts. The Chromium
profile lives in a per-session temp directory that is always cleaned up on
close (the `purge_profile` flag is accepted for contract compatibility and
echoed in the response, but profiles are ephemeral by design).
`keep_artifacts` defaults to true (screenshot artifacts are preserved for
debugging).

### `browser_save_screenshot`
Save the latest screenshot of a browser session to the sandbox filesystem as a
JPEG file. This bridges browser-live screenshots to sandbox-based tooling
(`ffmpeg`, OCR, `describe_image_file`, etc.) or makes them downloadable later.
Call `browser_observe` or `browser_execute` first to capture a screenshot.
Requires an active sandbox; the destination defaults to
`/workspace/browser-screenshots/step-NNNN.jpg` (override with `path`).
Returns `path`, `bytes_written`, `sha256`, and `action_seq`.

## Post-action observations

State-changing actions (`click_*`, `fill`, `type_text`, `press`, `scroll`,
`execute_javascript`, `script` with visual steps, `navigate`) return a fresh
post-observation with DOM snapshot or a structured `dom_snapshot_error`.
Read-only actions (`get_element_value`, `wait`) are result-only and skip
post-observation.

Tool output includes `post_observation_diagnostics` with:
- `mode`: `capture_after` or `result_only`
- `source`: `sidecar` or `fallback_observe`
- `fresh_observation` / `fresh_screenshot`: whether observation/screenshot changed
- `action_seq_current`: latest action sequence number
- `dom_snapshot.status`: `captured`, `captured_empty`, or `error`
- DOM snapshot elements include `tag`, `selector`, `attributes`, `href`, `value`,
  and `text`. For form inputs (`input`, `textarea`, `select`), `value` holds the
  current runtime value; `text` is `innerText` and is empty for inputs.

## Web UI usage

1. Start the web compose stack and open the console.
2. Create a task and ask the agent to use the browser, e.g. "Open a browser,
   go to example.com, and tell me what you see".
3. The agent calls `browser_start`, `browser_observe`, `browser_execute`,
   `browser_extract`, `browser_save_screenshot`, and `browser_close` as needed.
   The Browser Live panel shows the latest screenshot artifact and action
   status. There is no manual browser control.

## Limits and warnings

- Browser sessions are ephemeral; the Chromium profile (cookies, localStorage,
  cache) lives in a per-session temp directory that is cleaned up on
  `browser_close`. Artifacts are preserved when `keep_artifacts` is true.
- The sidecar requires a shared bearer token; keep it secret and out of logs.
- The app and sidecar communicate over loopback only.
- Screenshots are persisted to durable storage (Postgres `BYTEA`) keyed by
  `artifact://browser/<task>/<session>/...` refs; raw bytes are not embedded in
  chat history sent to the model — they are attached as native image
  attachments at call time. A retention sweep on `browser_close` deletes
  artifacts older than the configured retention period.
- Large or repeated pages are bounded by the live-frame byte cap and ring-buffer
  eviction.
- The agent is allowed to submit forms, type secrets, and interact with any
  page it can reach. Review agent actions before trusting them on sensitive sites.

## Sub-agent access

Browser tools are available to sub-agents when the parent agent explicitly
requests them in the `allowed_tools` whitelist of a `spawn_sub_agents` call.
Sub-agents inherit the parent's `browser_live_context` (storage, user ID,
context key) so screenshot artifacts are stored under the parent's session
scope, not the ephemeral sub-agent scope.

When browser is disabled (feature not compiled or `BROWSER_AGENT_ENABLED=false`),
no browser tools are registered for sub-agents and the context is `None` — zero
behavioral change.

## Sidecar session cap

The sidecar enforces a maximum number of concurrent browser sessions to prevent
OOM under load. When the cap is reached, new `browser_start` calls are rejected
with a `sidecar_at_capacity` error. The agent receives a human-readable message
advising it to close an existing session before retrying.

Configuration:

- `BROWSER_AGENT_SIDECAR_MAX_SESSIONS` — env var on the sidecar binary (default
  `8`). Set in `docker-compose.yml` as `BROWSER_AGENT_SIDECAR_MAX_SESSIONS`.
- `None` (unset via `SessionManager::default()`) means unlimited — backward
  compatible for tests.

## Troubleshooting

- **App fails to start with `BROWSER_AGENT_ENABLED=true requires BROWSER_AGENT_SIDECAR_TOKEN`**
  Set a non-empty `BROWSER_AGENT_SIDECAR_TOKEN` in `.env` and restart both the
  app and sidecar services.

- **Browser tools do not appear in the agent tool list**
  Check that `BROWSER_AGENT_ENABLED=true` and the token is set. Check the
  capability list with the binary for the relevant profile.

- **Browser tool calls fail with `Browser sidecar request was rejected`**
  Verify the sidecar is running, the token is correct, and the REST URL is
  reachable at the configured `BROWSER_AGENT_SIDECAR_BASE_URL`. Check the
  sidecar logs with `docker compose -f docker-compose.yml logs -f browser-sidecar`.

- **Browser starts but actions fail with timeout**
  Some sites require longer waits or use anti-bot measures. Increase
  `timeout_ms` (up to 60000) or use `wait_for_selector`/`wait_for_text` before
  acting.

- **No screenshot preview in Web UI**
  Confirm the artifact directory is writable and the sidecar created the artifact
  volume. Screenshot artifact refs are named `artifact://browser/<task>/<session>/`.

- **SPA hash navigation caches stale state**
  Use `navigate` with `force_reload: true`. The sidecar replaces the browser
  process to get a fresh JS heap while preserving profile data and the target
  URL/hash.

- **`type_text` does not trigger SPA state updates**
  Both `fill` and `type_text` use the same semantic input primitive with native
  value setters and framework-visible events (`focus`, `focusin`, `beforeinput`,
  `input`, `change`, `keyup`). If an input still fails, check the selector and
  the post-action DOM snapshot diagnostics.

- **`browser_start` fails with `sidecar_at_capacity`**
  The sidecar has reached its maximum concurrent session count
  (`BROWSER_AGENT_SIDECAR_MAX_SESSIONS`, default 8). Close an existing browser
  session with `browser_close` before retrying, or increase the cap in the
  sidecar environment.

- **DOM value extraction returns `found: false`**
  Check `attribute_source` in the diagnostics. The selector may not match, or
  the requested attribute may not exist. Raw `properties` and `attributes` in
  each match entry show what the element actually has.

- **DOM snapshot shows empty `text` for input/textarea fields**
  This is expected. DOM snapshot `text` is `innerText` — always empty for form
  inputs. The current runtime value is in the `value` field of each snapshot
  element. Use `value` (not `text`) to verify form input state after `fill` or
  `type_text`. Use `get_element_value` to read a single element's value; for
  `input[type=checkbox|radio]` it returns the checked state (`"true"`/`"false"`)
  rather than the `value` attribute.

## Staging checklist

- [ ] `BROWSER_AGENT_SIDECAR_TOKEN` set in `.env` for both app and sidecar
- [ ] `BROWSER_AGENT_ENABLED=true` set in `.env`
- [ ] `BROWSER_AGENT_SIDECAR_BASE_URL=http://127.0.0.1:8787`
- [ ] Sidecar health returns `{"ok": true, "native": true}`
- [ ] Sidecar integration tests pass (`cargo test -p oxide-browser-sidecar --test rest_contract -- --ignored`)
- [ ] Web app health returns `{"status":"ok"}`
- [ ] A test task can open a browser and observe `https://example.com`
- [ ] `browser_close` returns `sidecar_errors: 0`
- [ ] No browser token is present in logs or chat history

## Rollback

Disable the feature without rebuilding:

```bash
# .env
BROWSER_AGENT_ENABLED=false
```

```bash
docker compose -f docker-compose.yml up -d --force-recreate
```

Or stop the sidecar service while leaving the web app running:

```bash
docker compose -f docker-compose.yml stop browser-sidecar
```