Skip to main content
Glama
lyra-browser

lyra-browser

Official
by Intrect-io
README.md
# lyra

A **headful, collaborative browser** MCP server for AI agents. The agent drives a
single **visible Chromium window** that the user can watch and **take over** at any
time — co-browsing, not headless scraping.

The same server runs **headless** when nobody sits at a window — for example under
Hermes, where the user is reached through chat (see
[docs/HERMES_INTEGRATION.md](https://github.com/Intrect-io/lyra-browser/blob/master/docs/HERMES_INTEGRATION.md)), or as a remote server (see
[docs/CLOUDFLARE.md](https://github.com/Intrect-io/lyra-browser/blob/master/docs/CLOUDFLARE.md)).

> **Names.** The project is **lyra**; the repository is `lyra-browser`. The command
> (`lyra-browser`), the Python package (`lyra_browser`) and the environment variables
> (`LYRA_BROWSER_*`) keep the `lyra-browser` names for now. The UAT runner is `lyra-uat`.

> Built on Playwright (headful, persistent profile) and exposed over
> [FastMCP](https://github.com/jlowin/fastmcp), so any MCP client can use it with a
> single entry in its configuration.

## Why

An agent that is local-first and model-agnostic needs a browser the user shares: the
agent reads the page, clicks, and types, while the user can step in for the things an
agent must not do alone (passwords, CAPTCHAs, 2FA, payments) and grab full control
whenever they want. Every action is written to an append-only audit trail.

## Architecture

```
agent loop ──(MCP: stdio/http)──> lyra-browser server ──> Playwright ──> visible Chromium window
                                        │                                      ▲
                                        ├─ audit.jsonl (every action)          │ user watches / takes over
                                        └─ approval + takeover gating ─────────┘
```

- **Standalone MCP server** — registered in the MCP client's configuration; the client
  needs no code change.
- **Python, no browser download** — the only required pin is `fastmcp>=3.2`. The default
  driver talks to the Chrome or Edge already installed; Playwright is an extra
  (`lyra-browser[playwright]`) for the drivers that use it.
- **Dedicated headful window** — `launch_persistent_context(headless=False)` with a
  persistent profile, so logins survive across sessions. One server at a time holds
  that profile (an `flock` on `<data_dir>/profile.lock`, taken when the browser opens,
  not when the server starts). A second server on the same data dir opens a private,
  empty profile at `<data_dir>-instances/<pid>/profile` instead of failing, and
  `open_browser` says so (`profile: "instance"`, "no saved logins in this instance").
- **No setup tax** — reuses the user's **installed Chrome/Edge** by default
  (`channel="chrome"` → `"msedge"` → bundled Chromium), so `playwright install` is not
  needed when either is present — and neither is Playwright itself. If no browser is found, tools return a
  `browser_unavailable` envelope that the client can turn into an install prompt.
- **Full preset** — human-in-the-loop (highlight, ask-the-user, approval gate),
  takeover/handoff, bot-check detection, audit trail, CI + lint + pre-commit.

## Tools

| Group | Tools |
|---|---|
| Navigation | `open_browser`, `navigate`, `go_back`, `reload_page`, `close_browser` |
| Tabs | `tabs` |
| Waiting | `wait_for` |
| Interaction | `click`, `type_text`, `press_key`, `hover`, `scroll`, `handle_dialog`, `run_steps` |
| Downloads | `list_downloads` |
| Forms | `read_form`, `select_option`, `set_editor`, `upload_file`, `read_draft`, `save_draft`, `publish` |
| Reading | `get_url`, `read_page`, `screenshot`, `read_image`, `inspect_layout` |
| Tasks | `drag`, `evaluate_readonly`, `read_download`, `save_deliverable`, `set_emulation` |
| DevTools | `console_messages`, `network_requests`, `network_request`, `page_performance`, `storage`, `export_har`, `evaluate` |
| Collaboration | `highlight_element`, `ask_user_to_do`, `request_takeover`, `resume_after_takeover` |

### Filling a real form

`click` and `type_text` cover what every page has, but a form on a real site needs
more. Each of these was measured on KVR's developer forms before it was
written:

- `read_form` — a form's `name`, `type`, `label` and `<select>` options.
  `read_page` returns `innerText`, so a 188-field product form arrives as a wall of
  labels with nothing to address. Hidden inputs are counted, not dumped. Every
  field carries `usable` — false means it is in the DOM but hidden or disabled
  right now, which is how a form keeps a section it has not revealed (measured on
  KVR: `event_country` sits in the Deal/Offer block). Check `usable` instead of
  finding out through a 30s locator timeout. `whole_page=true` adds the controls a
  page attached outside the form. A picker or editor dialog is often appended to
  the body, and a field found there is still posted with the form.
- `select_option` — a `<select>` is not a click target. Chooses by `value`,
  `label` or `index`, and fires `change` the way a page listens for it. Pass
  `submits=true` when the choice posts. Answers `hidden` or `disabled` by name
  when the control cannot be used as it stands.
- `set_editor` — CKEditor/TinyMCE keep the editable body in an `iframe` and leave
  the `<textarea>` the form posts hidden and empty, so `type_text` on that
  textarea does nothing. `html=true` writes markup and syncs the editor's own
  data. Leave `selector` empty to use the first editor on the page.
- `upload_file` — attaches local files to an `input[type=file]`. A styled picker
  usually keeps it hidden, which is fine. The `UPLOAD` prompt names each file (its
  resolved path, so a link is named by what it points to) and its size, above the
  model's reason (labelled as the agent's), and the approval covers exactly those: a file
  that changed after the yes (even at the same size) is not sent, and the resolved paths
  are what is handed over. A list too long to show whole (over 4000 characters) is not
  asked about at all: a clipped prompt's yes would cover what was cut off. The page
  reads the file when it sends it, so the file itself should not be rewritten until
  then. A missing path is reported only after that prompt, so the tool
  cannot be used to probe which files exist. `evaluate`'s prompt likewise shows the
  expression itself.
- `save_draft` — sends the form while keeping the item private. It names the
  control that sends (`submit`, from `read_form`'s `submitText`), first confirms
  the publish control is still on its private setting and refuses otherwise, and
  asks for `SUBMIT` but never `PUBLISH` — so it cannot release an item, and a
  page left armed by anything else will not slip out through it.
- `read_draft` — everything a human needs to approve an item, in one answer: the
  filled fields, each editor's real content (a separate document `read_page` never
  shows), the attachment slots, the submit control, and whether the item is a
  draft or already public. A read, so it needs no approval.
- `publish` — the one action that sends an item to an audience. Kept apart from
  every other tool so that writing a draft can never release it: it asks for
  `PUBLISH`, which nothing implies, and it is the only tool that does. A site
  splits the act across two controls and means neither alone — measured on KVR,
  the publish radio only arms the form and the item travels on the form's own
  Submit — so it takes both `selector` (the live control) and `submit` (the one
  that sends). Giving only the first is refused rather than left half-done:
  arming a form with no way to send it would leave the page primed to publish on
  someone else's next click.

### Drafts and release

Writing an item and releasing it are different acts, and the tool surface keeps
them apart. Every writing tool can be driven to completion with the item still
private; `publish` is the only way out, and it is `PUBLISH`-gated and single-use.
The intended flow is: fill the form → `read_draft` → show the human → only then,
on an explicit yes, `publish`.

On KVR this matches the page: a new item opens on `Draft` (`is_draft=1`) and stays
there until the publish radio is switched. That radio is `input[name=is_draft][value='0']`
on a news item and `input[name=is_live][value='1']` on a product; the form's own Submit
(`Submit` on a news item, `Add` on a product) is what sends it, so a form that is merely filled is not visible to
anyone. A form sent without the publish control set saves as a draft — which also
means every writing tool must stay away from Submit, since KVR has no separate
"save draft" button. That is why `publish` sends the form itself rather than
leaving the send to `click`.

`UPLOAD` and `PUBLISH` are single-use: a file handed to a page, and content shown
to an audience, cannot be recalled.

### Handing a step to the person

Each of these assumes somebody is looking at the window. Headless, each answers
`unattended` and changes nothing.

- `ask_user_to_do(instruction, selector)` is for what the agent must not do itself:
  credentials, a CAPTCHA, 2FA, a payment. It highlights `selector` and answers
  `awaiting_user`. Relay the instruction, then watch with reading tools (`read_page`,
  `get_url`, `screenshot`, `wait_for`).
- Until the agent's next acting call, the window is the person's. The pages they open
  and the forms they send are not judged against the agent's approvals. That next call
  takes the window back, so do not act until the step is done.
- `request_takeover(reason)` hands the window over. Every acting tool answers
  `takeover_active` until the person hands it back.
- `resume_after_takeover` takes the window back once the person says so. It is asked of
  them through the consent channel, and nothing else answers for them: not the agent's
  live approval on the site, a trusted list, bypass mode or the `autonomous` channel.
  When nobody can be asked it answers `needs_approval` and the window stays theirs. On a
  client without elicitation at all (channel `legacy`, or `auto` falling back) the person
  hands back in chat, and the release is recorded as the model's own assertion
  (`consent_channel=legacy`). Under `elicit` or `autonomous` on such a client nobody
  could hand it back, so `request_takeover` answers `unattended` instead of handing over.
- `highlight_element(selector)` outlines what the agent means.

## Reading and acting on a page

### Reading: `read_page`

`read_page` has two modes, both read-only (no approval, works during a takeover):

- `mode="text"` (default) — the rendered text (`innerText`), not HTML.
  `links=true` adds the visible links as `{text, href}` (absolute, de-duplicated,
  at most 100, with `links_truncated`).
- `mode="tree"` — one line per thing that can be acted on (links, buttons,
  inputs, selects, checkboxes, tabs, menu items), each with a ref:

  ```
  aria-ref=e12 link "Pricing" -> /pricing
  aria-ref=e15 button "Save"
  aria-ref=e16 checkbox "Remember me" [checked]
  ```

  Input values are never shown. The reply carries `elements` and `refs`, plus
  `in_viewport` (on-screen elements come first) on Playwright 1.60+.
  `read_page(mode="tree", scope="viewport")` lists only what is on screen now and
  counts what lies under it in `below_viewport` (scroll to reach those); on a long
  page that is a fraction of the whole tree. A driver that gives no geometry
  answers `scope_applied: false` with the whole tree. `scope="viewport"` in text
  mode, or any scope but `page`/`viewport`, is an `error`.

`selector` limits either mode to one region (first match; `not_found` at once
when nothing matches). `offset` and `max_chars` page through long output:
`total_chars` is the full length, `truncated` says more follows and `next_offset`
is where to continue. Tree pages break on whole lines, so a ref is never cut in
half. A reply that finds a bot check also carries `challenge` and a `hint`; see
[Bot checks](#bot-checks-challenge).

### Addressing an element: `aria-ref`

`read_page(mode="tree")` → pass the token `aria-ref=eN`, exactly as written, as
the `selector` of `click` or `type_text`. A ref reaches what a CSS or text
selector cannot name: icon-only links, several links with the same text, elements
inside open shadow roots and iframes. A ref is a handle into the *latest* tree
read, not a query over the live page: a newer read (a region read included), a
navigation or a removed frame ends it, and so does the element being removed. A
stale ref answers `not_found` (or `hidden` for an element that is gone but still
counted) with a hint to read the tree again; refs get no waiting window, because
they cannot appear later.

**The Playwright drivers need `playwright>=1.59`.** Refs come from
`aria_snapshot(mode="ai")`, which 1.59 introduced; on 1.58 the tree still works but
answers `refs: false` and its lines carry no ref — address elements with
`role=link[name="Pricing"]` or `text=` selectors instead. The default `native` driver
builds the same tree from Chrome's accessibility tree and has no such floor.

### When an action cannot be done: `click` / `type_text`

Both fail fast and explain, instead of holding the call for Playwright's 30s:

| `status` | Meaning |
|---|---|
| `not_found` | Nothing matches the selector, even after up to ~3s for a page that builds its controls late |
| `hidden` / `disabled` | The match is in the page but stayed invisible / disabled for that window (present-but-not-ready controls are re-checked until ready, so a button enabled 0.8s after load still works) |
| `timeout` | The action outran `timeout_ms`. The click may have landed — look at `get_url`/`read_page` before repeating it. When it started a navigation the server never answered, the reply also names it (`pending_url`) and that load is stopped (`stopped: true`), so the tab stays on, and can read, the page it was on (see [A navigation that never commits](#a-navigation-that-never-commits)) |
| `element_not_actionable` | Covered by another element (the hint names it), detached, read-only, not a text field, unstable or outside the viewport |
| `page_closed` | The tab died under the call (a popup that closed itself, a closed window) |

Each carries `selector`, `url` and a `hint` with the next move. `timeout_ms`
(default 10000, at most 30000; 0 is raised to 1ms, never "no limit") bounds the
action itself. The usability check runs *before* permission is asked, so an
unusable control neither prompts nor leaves a single-use grant behind; the same
driver failures during the action are converted into these envelopes (and
audited) rather than raised. A successful `click` also reports `matches` (how
many elements the selector hit — the first is clicked) and `clicked`
(`tag`, `role`, `name` of what was hit), with a hint when `matches > 1`.

### What an action set off: `blocked_by_policy`, `new_tab`

`click`, `type_text`, `press_key` and `hover` answer when the driver reports the action
done, and two things can still be true of that moment:

- **The guard refused a navigation the action caused** (a link to a site no approval
  covers, a form sent without `submits=true`, a page that redirected itself). The refusal
  leaves the tab where it was, so the reply used to read `ok` with the same `url` and
  the agent had no idea why nothing happened — the audit trail was the only account.
  It is now `blocked_by_policy` with `url` (where the tab stands), a `hint` and, for a
  refused redirect, `redirected_to`; the fields the reply already had (`matches`,
  `clicked`, `dialogs`) are kept, and the audit row of the action carries the same
  status. The hint is the way out: `navigate` to the destination (that asks the user),
  or repeat the action with `submits=true` (`submit=true` on `type_text`) when it was
  meant to send a form. A file the call saved stays `ok` with its `download`, and a
  download the browser started and the call cancelled keeps `download_blocked`. In
  `observe` mode nothing is refused, so the reply stays `ok` and the audit says
  `would_deny`.
- **The action opened a tab** (`target=_blank`, `window.open`). The session follows
  onto it while `url` is still the page the action was made on, so the reply carries
  `new_tab: true` and `tab_count`, and a hint to use `tabs`. `get_url` and
  `open_browser` carry `tab_count` too. A popup whose first navigation the guard
  refused opens no tab at all, and the reply is `blocked_by_policy` instead.

Neither costs a click a wait of its own. The driver holds a click until the navigation it
started has been judged, so that verdict is in before the call returns (0.5 to 48 ms
before, measured over playwright and patchright, both guard backends, headless and
headful). What it does not hold for lands 3 to 22 ms after — a popup's tab, a form posted
from a frame, a page's own `setTimeout(0)` — inside the `download_settle_s` window every
click and key press already listens for. `hover` and `type_text` have no such window, so
they linger up to 40 ms after the driver returns, and only while nothing has shown (their
navigation reaches the guard 1 to 8 ms after they return); a page timer that fires after
that is only on the audit trail. Numbers in `scripts/verify_click_refusal_e2e.py`
(`INFO` lines).

### Several steps in one call: `run_steps`

When the next few actions are already known — fill these fields, pick that option,
press Next — `run_steps` does them in one call and reads the page once at the end:

```json
{"steps": [
  {"tool": "type_text", "args": {"selector": "#email", "value": "a@b.c"}},
  {"tool": "select_option", "args": {"selector": "#plan", "label": "Pro"}},
  {"tool": "click", "args": {"selector": "text=Next"}},
  {"tool": "wait_for", "args": {"text": "Step 2"}}],
 "observe": "tree"}
```

It is a list of tool calls, not a script. A step may be `navigate`, `click`,
`type_text`, `press_key`, `hover`, `scroll`, `select_option`, `wait_for`, `read_page`,
`get_url` or `tabs` (list/switch), at most 20, each with the arguments that tool takes.
Each step calls that very tool inside this one MCP request, so declared intent
(`submits=true` in the step that sends), consent (asked during the call), the navigation
guard, the audit trail and the envelopes are the tool's own: nothing is approved because
it is in a batch. `publish`, `evaluate`, `upload_file`, drafts and the collaboration
tools cannot be steps, and neither can `capture=true`.

- The whole list is checked first. An unknown tool, a tool this session is not offered,
  or an argument the tool does not take answers `error` with the step's `index`, and
  nothing runs.
- The batch stops at the first step whose reply is not `ok`. The reply's `status` is
  that step's status (`needs_approval`, `blocked_by_policy`, `not_found` …, meaning what
  they mean from that tool), `stopped` names it (`index`, `tool`, its `reply`) and
  `completed` says how many ran; the steps after it did not.
- When every step ran, `observe` (`tree` default, `text`, `none`) reads the page once.
- `steps` lists the steps that went well briefly: `index`, `tool`, `status`, the `url`
  only when it changed, `changed` (whether the screen did) and anything unusual the tool
  said (a `hint`, `new_tab`, a dialog, a download, a bot check). A read step
  (`read_page`, `get_url`, `tabs`) keeps its whole `reply`, and so does the stopping
  step in `stopped`. `LYRA_BROWSER_STEPS_REPLY=full` gives every step's whole `reply`
  instead, as before 2026-12-02. On the flow suite's batches the steps' replies were 70%
  of a batch's reply, each repeating the url and a `visual_change` box.
- The audit trail has one `run_steps` row when the batch starts and one when it ends,
  and every row a step writes carries `batch: {id, index}`. Under `lyra-uat`, each step
  is budgeted, guarded (a card number typed in a step is refused) and traced as a call
  of its own, with the same `batch`.

Measured 2026-12-01 by `scripts/verify_steps_e2e.py` (loopback, Chrome 157.0.8103.38,
headless, `native` and Playwright 1.65.2 drivers): a five-step fill whose last step is
a declared, approved submission sends exactly that form; an undeclared submission in
step 3 is answered `blocked_by_policy` with `stopped.index` 2 and the site never hears
from steps 4 and 5 (route and cdp guards); a step needing an approval nobody gave stops
the batch with its index; a disallowed tool refuses the batch before step 1 runs.
On 2026-12-02 the same gate ran one five-step batch both ways on `native`. The compact
reply was 459 characters against 1,124 for the full one. The final observation and the
stopping step's reply were identical in both.

### Waiting: `wait_for`

`wait_for` holds until the page is ready instead of a sleep — or a click used to
pass time. Give exactly one condition: `text` (in the visible text `read_page`
shows; `state="hidden"` waits for it to vanish), `selector` (reaches `state`:
`visible`, `hidden`, `attached`, `detached`), `url` (a glob over the whole URL,
e.g. `**/checkout**`) or `load_state` (`load`, `domcontentloaded`,
`networkidle`). It waits up to `timeout_ms` (default 10000, capped at 30000) and
returns `ok` with `waited_ms`. Running out of time is an answer, not an error:
`{"status": "timeout", "waited_ms", "last_seen"}` with a short page excerpt (the
URL for a `url` wait). Bad arguments return `error`. It only observes: no
approval, and it keeps working while the user holds a takeover.

### Tabs: `tabs`

The session follows onto any tab a page opens (`target=_blank`, `window.open`),
so the agent is never left reading the page that opened it. A `click` or
`press_key` that opened one says `new_tab: true` and `tab_count`, and `get_url` and
`open_browser` carry `tab_count`. `tabs` covers the rest:

- `action="list"` (default) — `tabs: [{index, url, title, active}]` plus
  `tab_count` and `active_index`. A read; a tab stuck in a script loop is listed
  without a title rather than hanging the list.
- `action="switch"`, `index=N` — make that tab the one to read and act on, and
  bring it to the front so the user sees what the agent sees.
- `action="close"`, `index=N` — close it. Closing the active tab returns to the
  tab that opened it, else the newest one; closing the last tab leaves a blank one
  (closing headful Chrome's last window would quit the browser).

Indexes shift whenever a tab opens or closes, so list again before using one; a
bad index answers `not_found` with `tab_count`. Switching and closing are
mutations: they stand down for a takeover, are audited, and ask for `INTERACT`
on the **tab's own site**, not the active page's — being approved for one site is
no licence to read or close another's. A tab that closes itself (a sign-in popup)
sends the session back to its opener; if the active page is ever closed, the next
tool moves onto the opener, else the newest tab, else a fresh blank one, instead
of failing on a dead page.

### What `navigate` reports

`ok` means the navigation happened, not that the page is good. `navigate`,
`go_back` and `reload_page` report `http_status` (404, 500 …) and `content_type`
(media type only, lower-cased, e.g. `application/pdf`) of the document that
answered; both are `null` when no HTTP response was involved (`about:blank`,
`data:`, a page the browser restored from history). `wait_until` chooses how much
of the load to wait for: `domcontentloaded` (default), `load`, `commit` or
`networkidle` (which never settles on a page that keeps polling); anything else is
an `error` before any prompt. A page that draws itself after loading needs
`wait_for`. A URL that turns out to be a file download does not move the tab: see
[Downloads](#downloads) for `download=true` and `download_blocked`. Only when the
driver announced a download the browser never reported does it answer
`{"status": "download_started", "url", "requested_url", "hint"}`; this server then wrote
no file to the download dir. If the page that answered is a bot check, `navigate`
answers `status: "challenge"`; see [Bot checks](#bot-checks-challenge).

### A navigation that never commits

While a main-frame navigation is pending, Chrome does not let the page's own
context answer: a tool that merely gave up waiting would leave a tab whose next
`read_page` hangs with it. So a tool that gives up on such a navigation stops it.

- `navigate` waits at most `timeout_ms` (default 30000, at most 120000). A server
  that has not answered by then gets
  `{"status": "timeout", "url", "pending_url", "stopped": true, "hint"}`: the load is
  stopped (CDP `Page.stopLoading`) and `url` is the page the tab is still on. A
  page that arrived but never reached `wait_until` is also `timeout`, without
  `pending_url`: what has loaded can be read.
- `click`, `press_key` and the other actions answer `timeout` as before; when the
  action started a navigation that never committed, the reply adds `pending_url`
  and `stopped` the same way. Its hint says how to go on: `navigate` to
  `pending_url` with a larger `timeout_ms`, or repeat the action when it sent a
  form (navigating would not send it again).
- `stopped: false` means the stop itself failed; the hint says the tab may not
  answer until that navigation ends.

This changes one earlier behaviour: a page that was only slow used to go on
loading after the action's `timeout_ms` had run out (with the tab unreadable
meanwhile). It is now stopped; `navigate(pending_url, timeout_ms=...)` reaches it.

Measured 2026-12-01 by `scripts/verify_stall_e2e.py` (a loopback `/hang` that
answers nothing; Chrome 157.0.8103.38, headless, `native` and Playwright 1.65.2
drivers, route and cdp guards): `navigate(timeout_ms=3000)` and
`click(timeout_ms=3000)` answer within the budget plus 5 s, `read_page` reads the
previous page within 5 s after either, a response released afterwards does not
move the tab, and the next action works. Before this, on the same gate, the click
answered `timeout` in time but the next `read_page` was still blocked 10 s later,
on both drivers, and `navigate` had no budget but the driver's 30 s.

### Bot checks: `challenge`

A page that asks "are you a robot" is not a failure of the tool, and it is not a page
to get past. It is a page a person has to answer. lyra names the check and stops:

- `navigate` answers `status: "challenge"` when the page it landed on is a bot check,
  and `read_page` adds a `challenge` field (the text is still returned, so the agent
  can see what it is).
- The reply carries `challenge: {vendor, kind, evidence}`. `kind` is `interactive`
  (a person has to solve it: a checkbox, a puzzle, press-and-hold) or `blocked` (refused
  outright, e.g. an HTTP 403 "Access Denied"). `vendor` is `cloudflare`, `datadome`,
  `recaptcha`, `hcaptcha`, `perimeterx`, or `unidentified` when the text names a check
  without a known host.
- The `hint` depends on who is watching. With a person at the window it says to ask them
  (`ask_user_to_do`, then `read_page` to see whether it cleared). With nobody there it
  says not to wait and not to look for another way past, to report the task as blocked
  (`finish` with `outcome=blocked`) and carry on with what remains.

lyra itself solves, waits out or retries no check. Detection reads the frame hosts, the
page title and the first 3000 characters of visible text; an article that quotes a
check's wording further down is not named. A detection in `navigate` is audited as
`challenge_seen` (with the attempt number); `read_page` only reports it in its reply.

- **The same wall again.** `navigate` counts each check by vendor and site. The reply
  carries `attempts` and `max_attempts`; when the same check stops the agent for the
  `LYRA_BROWSER_CHALLENGE_MAX_ATTEMPTS`th time (default 3) the status is
  `challenge_abandoned` and the hint says to stop and report it as blocked. Coming back
  to the same check is not progress, and a site that sees it is right to harden against
  the account.
- **An operator's solver.** `LYRA_BROWSER_CAPTCHA_SOLVER=package.module:function` names
  a callable lyra hands an `interactive` check to when nobody is watching (never a
  `blocked` one, never with a person at the window). It is called as
  `solver(info, page)` with `info = {vendor, kind, evidence, url, attempt}`, may be
  async, and whatever it does is its own responsibility; lyra ships none. Its answer is
  reported (`solver`), never trusted: the page is checked again, and only a page that is
  no longer a check answers `ok` with `challenge_solved`. Audited as `challenge_solver`.

### Hover and scroll

- `hover` — move the pointer over an element, for menus and tooltips that open only
  while it is on their trigger: `hover`, then `click` the item that appears. Nothing
  is pressed, so no form is sent. Fails fast like `click` (`not_found`, `hidden`,
  `disabled`, `timeout`, `element_not_actionable`, `page_closed`, `timeout_ms`) and
  reports `matches` and `hovered` (`tag`, `role`, `name`). Needs `INTERACT`.
- `scroll` — give exactly one of `to` (`top`/`bottom`), `by_y` (pixels, negative up,
  at most 20000 per call, done with the mouse wheel) or `selector` (bring it into
  view). The reply is `scroll_y`, `scroll_height` and `at_bottom` once the position
  has settled. It moves the **window** only: a feed or panel that scrolls inside its
  own container needs `scroll(selector=...)` on an element inside it, and a scroll
  that moved nothing says so. Lazy lists grow after a scroll, so repeat
  `scroll(to='bottom')` until `at_bottom` is true.

### Downloads

A file a page hands to the browser is kept **only when the call declared it**.
Chromium accepts a download the moment a page offers one, and the navigation guard
judges requests, not responses, so this is a separate gate on the file as it
arrives:

- `download=true` on `click`, `press_key` or `navigate` declares it and buys a
  single-use `DOWNLOAD` grant (asked like any other, never implied by a trusted
  origin) inside that call. The grant pays for exactly one file and is retired when
  the call stops waiting. The reply carries `download`:
  `{filename, path, bytes, url_origin}`.
- An **undeclared** download is cancelled and deleted before anything reaches the
  download dir, and the call answers `download_blocked` (`blocked_download`:
  `filename`, `url_origin`) — repeat it with `download=true`. A declared call that
  produced no file answers `download_not_started`; one whose file was not kept
  answers `download_failed` with a `reason` (`too_large`, `timeout`, `error`).
  `go_back` and `reload_page` cannot declare one; their hint points at `navigate`.
  Chrome reports a reload or history step that turns into a download as
  `net::ERR_ABORTED` (not "Download is starting"); an abort that a download follows
  within 2 s is answered as that download, and any other abort is still an error.
- With `LYRA_BROWSER_ENFORCEMENT=observe` ("record, do not block") nothing is cancelled
  either: an undeclared download is **saved** like a declared one — same name rules,
  caps and ledger — and answered as `download` plus `observed: true`, audited as
  `would_block`. Observe never spends a grant (like the navigation guard), so it
  under-reports a second file in one call that enforce would have cancelled. A
  download a `DOWNLOAD` grant covered is audited `saved` and is not flagged.
- The site picks the file name, so it is treated as hostile: only the last path
  component survives, control and right-to-left-override characters, characters
  Windows forbids, leading dots and reserved device names are removed, long names
  are cut keeping their extension, and a taken name becomes `name (1).ext`. Nothing
  is ever written outside `LYRA_BROWSER_DOWNLOAD_DIR`.
- Size and time are capped (`LYRA_BROWSER_DOWNLOAD_MAX_BYTES`,
  `LYRA_BROWSER_DOWNLOAD_TIMEOUT`), and the dir is pruned oldest-first to
  `LYRA_BROWSER_DOWNLOAD_KEEP` using a ledger, so files that are not this server's
  are never deleted.
- While the user holds a **takeover**, or does a step `ask_user_to_do` asked of them,
  the gate stands aside and their own downloads are saved, recorded as `user_driven`,
  as with navigation.
- `list_downloads` — the files this session saved (`filename`, `path`, `bytes`,
  `url_origin`), oldest first, plus `download_dir`. A read: no approval, works
  during a takeover, does not open the browser. Blocked and failed downloads are
  not listed.

The listener is **per tab** (popups included), not `BrowserContext`'s `download`
event: that only exists from Playwright 1.60 while this project supports 1.58,
where a context listener would never fire and every download would go unjudged.

### Native dialogs

`alert`, `confirm`, `prompt` and `beforeunload` stop a page until answered, and a
listener that leaves one open freezes the tab. So one context-level listener
**always answers** the moment a dialog appears. The default is what a browser with
no listener does: alerts and `beforeunload` are accepted, `confirm` is dismissed
(`false`) and `prompt` is dismissed (`null`).

- What was raised is reported as `dialogs` (`type`, `message`, how it was answered)
  in the reply of the `click`, `type_text` or `press_key` that raised it — only
  present when there were any. The message is the page's text, not the user's. The
  form tools (`save_draft`, `publish`) use the same handler and fold dialog text
  into their `errors`.
- `handle_dialog(accept, text)` chooses the answer for the dialog **the next browser
  action raises**: call it *immediately before* that action. `accept=false` answers
  no; `text` is what a `prompt` receives (empty accepts the default). Like a one-shot
  grant it belongs to that one call — `click`, `type_text`, `press_key`, `hover`,
  `scroll`, `navigate`, `go_back`, `reload_page`, `select_option`, `set_editor`,
  `upload_file`, `save_draft`, `publish` or a `tabs` switch/close — and ends with it,
  used or not, even when the call was refused (arm again before retrying). A dialog
  raised after it, by a page's own timer or on a page reached later, gets the default,
  so a yes armed for one click cannot answer a later `Delete this?`. Reading
  (`read_page`, `screenshot`, `get_url` …) does not use it up, and about 60s is the
  most it ever waits. It asks nobody (the click that raises the dialog was already
  asked for), stands down for a takeover, is audited, and the prompt text is never
  written to the audit log.
- Nothing here judges the answer: accepting a `confirm` that goes on to post a form
  is still stopped where the request leaves unless it was declared (`submits=true`).

### Task tools: drag, a read-only look, downloads, deliverables, place and language

What a task needs beyond reading and clicking (`src/lyra_browser/tools/tasks.py`):

- `drag(source, target)` — presses the pointer on `source`, moves it onto `target` in
  steps and releases it, after checking both ends as `click` checks its target. Asks to
  interact, like `hover`. For sliders, sortable lists and boards that follow the pointer.
- `evaluate_readonly(expression)` — a JavaScript expression that only reads. Chrome
  evaluates it with `throwOnSideEffect`, so an assignment, a DOM change or a request is
  refused by the engine before it runs (`refused_side_effect`), not by a pattern match;
  that is why it needs no approval, unlike `evaluate`. Cookies, web storage and a
  password field's value are refused too, however the expression spells them: for the
  span of the call their getters (in the page and in every same-origin frame) are
  wrapped (wherever they are defined: on the prototypes and on any own accessor a site
  put in front, such as React's value tracker or a consent manager's cookie shim, and in
  the same-origin windows the page can reach) so that reading one counts as a side
  effect, and Chrome refuses it (`refused_side_effect`); the page is put back afterwards.
  The values themselves are read first, and a result that contains one as it is is
  refused (`refused_storage`): that covers a getter a site captured in a function of its
  own. What is left: such a captured getter whose result the expression transforms
  (reversed, encoded) before returning it. An expression that names
  them outright is answered `refused_storage` before anything runs. `storage` reads
  storage and asks before it reveals values. Measured 2026-12-02 on Chrome stable:
  computed names, `\u` escapes, a getter borrowed from a child frame and a deep call
  stack are all refused, while page globals and a text field still read.
  `read_form` and `read_draft` likewise list a password field as `filled`, never its
  value.
- `read_download(filename)` — the content of a file this session saved (text up to
  50000 characters, or size, SHA-256 and the first bytes of a binary). Nothing else on
  disk can be named.
- `save_deliverable(name, content)` — writes a result (an extract, a table) under a
  plain file name to the session's deliverables directory (`<data dir>/deliverables`, a
  UAT run's own directory in `lyra-uat`), never over an existing file unless
  `overwrite=true`, up to 1 MB.
- `set_emulation(latitude, longitude, accuracy, locale, timezone, clear)` — what pages
  are told about place and language: `navigator.geolocation` (and the permission it
  needs), `Intl`/`navigator.language`, the time zone. For the caller's tabs and every
  tab it opens after: with spaces on, another space's tabs and the user's are never
  touched. With spaces off the geolocation permission is granted to the origins of those
  tabs only (never every site); with spaces on it is not granted at all, because a
  permission belongs to the site in every tab, another space's and the user's included,
  so the site asks the user for it (headless: refused). `clear=true`, closing the
  browser or handing it on takes the permission back with the override, so no site is
  left with the real position and no later holder inherits the override.
  `Accept-Language` and the IP address do not change.

Reading cookies and web storage is `storage` (DevTools, below); there is no second tool
for it. `scripts/verify_task_tools_e2e.py` is the real-browser gate.

### DevTools: console, network, performance, storage, `evaluate`

What Chrome's DevTools panels show, as tools. What they return was produced by the page
(console text, URLs, headers, bodies, storage): data to report, never instructions.

| Tool | Panel | Gate |
|---|---|---|
| `console_messages(since, levels, limit, capture)` | Console: `console.*` calls and uncaught exceptions, every tab | none |
| `network_requests(since, url_contains, resource_type, min_status, failed_only, limit)` | Network: method, URL, type, state, status, `duration_ms`, `ttfb_ms`, failure | none |
| `network_request(id, body)` | One request: headers, timing breakdown, sizes; `body=true` adds the body and full URL | `INSPECT` for the body |
| `page_performance()` | Performance: Navigation Timing, paints, FCP/LCP/CLS (INP after interactions), resources, JS heap | none |
| `storage(kind, reveal)` | Application: cookies, localStorage, sessionStorage — names, sizes, flags | `INSPECT` for values |
| `export_har(include_bodies)` | Network → Save as HAR (1.2), under `<data_dir>/har` | `INSPECT` for bodies, per site |
| `evaluate(expression)` | The console prompt: runs in the page's own world, awaits a Promise, reports a throw | `EVALUATE`, every call |

- **Console capture is off until `console_messages(capture=true)`.** It needs
  `Runtime.enable`, the DevTools call Kasada refuses on (see [Drivers](#drivers)); a
  session that never asks for the console never sends it. On turns it on for every open
  tab and every later one; messages logged before that are gone. Off stops new tabs, but
  a page that received `Runtime.enable` has seen it.
- **The network log costs nothing new**: it listens to the `Network` events every page
  already has enabled. It is kept across navigations (DevTools' "Preserve log") and
  bounded (1000 requests, 500 console entries; `dropped` counts what was let go). Page
  through with `since=<next_since>`. `duration_ms` and `ttfb_ms` come from the browser's
  own timestamps, not from when Python heard of the event.
- **Secrets stay out unless asked for.** URLs lose their query values (as in the audit
  log), credential headers (`Cookie`, `Set-Cookie`, `Authorization`, `*-token`, `*-key`,
  …) are always `<redacted>` — `INSPECT` does not unredact them — and bodies are never
  buffered: `network_request(body=true)` asks Chrome for one, which may already have let
  it go (`body_error`). A URL inside a header (`Location`, `Referer`, `Content-Location`,
  a `Refresh`'s `url=`) loses its query values like any other URL. `url_contains` matches
  the URL as the row shows it, so it cannot spell out a hidden query value one character
  at a time; with `INSPECT` held on that site it searches the whole URL. `INSPECT` is per
  site: `export_har(include_bodies=true)` asks it for the page's site and opens bodies
  and full URLs only for the sites it is held for; every other site's traffic stays as
  `network_requests` shows it and is named in `withheld`, so it can be asked for on its
  own (`network_request(id, body=true)`).
- **`evaluate` is gated because the guard cannot see what it does.** A `fetch()` POST is
  not a document request, so the navigation guard never judges it; the single-use
  `EVALUATE` grant, whose prompt shows the expression, is the only gate. The expression is
  audited in full. The `autonomous` channel refuses `EVALUATE` and `INSPECT`.

Measured 2026-11-04 by `scripts/verify_devtools_e2e.py` (loopback fixture, headless,
native driver and Playwright 1.6x, Chrome stable, N=1 run each): every step passed on
both drivers, including an `/api` call the server delays 300 ms reported with
`duration_ms` ≥ 270 and `ttfb_ms` ≤ `duration_ms`, a 404, a refused connection as
`failed`, FCP/LCP and navigation timing, a HAR with no cookie, API key or query value in
it, `evaluate` reaching `window.appState` (the page's world) and an approved `fetch()` POST
reaching the server.

## Seeing the page

`screenshot` (the viewport or the full page) and `read_image` (one element —
an `img`, a `canvas`, an `svg`, a chart) write a PNG to disk and return its
**path**:

```json
{"status": "ok", "image_path": "…/captures/page-20260917T123557Z-fd1a0721.png",
 "mime_type": "image/png", "width": 1280, "height": 800, "bytes": 115889}
```

The file is the handoff. Measured on the same client: a tool result is shown to the
model as its text blocks, so a base64 PNG inside the JSON arrives as tens of
thousands of tokens of prose and no picture. A path costs nothing, and a client that
can read the server's files attaches the file to the model's next turn as an image.
Captures go to `<data_dir>/captures` unless `LYRA_BROWSER_CAPTURE_DIR` says otherwise.
Everything lyra keeps there is from the person's logged-in browser, so the data dir and
every directory lyra makes for captures, HARs, downloads, deliverables, the audit trail
and a profile import's staging is owner-only (0700), and each file it writes is 0600,
whatever the umask. An existing data dir is closed to 0700 when lyra starts; a download,
capture or deliverables dir the operator made elsewhere keeps the mode they gave it.
`inline=true` adds the base64 for a client with no access to this filesystem.

Captures are written atomically and pruned oldest-first
(`LYRA_BROWSER_CAPTURE_KEEP`, default 200), so an agent that looks every turn
does not fill the disk. The audit records the path and size, never the pixels.
`read_image` fetches nothing — it captures what the element renders, so no
request leaves the browser and nothing is gated.

### Marks, scale and acting on a point

`screenshot(annotate=true)` draws numbered boxes on the image for what can be acted on on
screen and returns `marks`: per box `n` (the number drawn), `ref` (use `aria-ref=<ref>` as
a selector), `role`, `name`, and the box as `[left, top, width, height]` in CSS pixels
(`box_css`) and image pixels (`box_px`). The boxes come from the same tree `read_page(mode="tree")`
reads, so a mark and a tree line name the same element; like a tree read, it replaces the
refs of the read before it. They are drawn on the PNG (Pillow), never in the page.

Every capture reports `scale`, image pixels per CSS pixel, measured from the image (the
page's `devicePixelRatio` is not always what the driver captured at). Captures longer than
`LYRA_BROWSER_CAPTURE_MAX_EDGE` (1568 px) are downscaled first. `click(x=, y=)` and
`hover(x=, y=)` take pixels of the latest screenshot of the page and divide by its scale,
for what has no element to name: a canvas, a map, a drawn button. They ask for the same
permissions as a selector click (`submits=true`, `download=true`), the enforcement layer
judges what they set off, and a point that is no longer on screen answers
`outside_viewport`.

Measured 2026-11-18 (Chrome 157, `scripts/verify_visual_e2e.py`, native and Playwright
1.65.2 headless, native headful): a mark for each of the 8 controls on the test page, every
box matching its element's rect with IoU >= 0.9, every ref clicking its own element, the
page's `MutationObserver` silent while annotating; a dot drawn only on a canvas hit within
2 CSS px at scale 1, downscaled to 1000 px, and at a device pixel ratio of 2; a form sent
by a coordinate click without `submits=true` stopped before it reached the server.
Playwright's own screenshot writes a style on the page's inputs to hide the caret (2
mutations per capture, measured); lyra asks it not to (`caret="initial"`).

### Zoom: `screenshot(region=[x, y, width, height])`

A region of the latest screenshot (its pixels) is captured again on its own, rendered by
Chrome at up to 4x (`Page.captureScreenshot` with `clip.scale`, as large as
`LYRA_BROWSER_CAPTURE_MAX_EDGE` allows), so small text, a dense chart or a fault of a pixel
or two gains real detail rather than being upsampled. The reply carries the zoom's own
`scale`, `origin` (its top-left in viewport CSS pixels) and `region_css`; `click(x=, y=)` and
`hover(x=, y=)` then take pixels of the zoomed image. A region needs a screenshot of the page
first; an empty one answers `empty` and one that is no longer on screen `outside_viewport`.
Nothing is written to the page.

Measured 2026-11-19 with Chrome 157.0.8103.38 (`scripts/verify_zoom_e2e.py`, native and
Playwright 1.65.2 headless, native headful under Xvfb): the zoom of four colour blocks,
brought back to the full capture's size, differs from it by a mean of under 8/255 per
channel at device pixel ratio 1 and 2; of 1 CSS px stripes that a capture downscaled to
1000 px shows 67 of 119 edges, the zoom shows all 119, at 4x its density (scale 4.0 against
0.78); a click at a point of the zoom lands within 1 CSS px of the centre of a 4x4 CSS px
target, after scrolling and at a ratio of 2 too; a hover there reaches it; the page's
`MutationObserver` records 0 mutations.

### Did it change? `visual_change`, `capture=true`, `visual_stable`

`click`, `type_text`, `press_key`, `hover`, `scroll` and `select_option` take a small
thumbnail of the viewport before and after they act (DevTools `Page.captureScreenshot` at a
quarter scale: no page script runs) and answer
`visual_change: {changed, ratio, region}`, `region` being what changed as
`[left, top, width, height]` in CSS pixels. A click that missed or did nothing says
`changed: false` without the agent looking at an image. The after-thumbnail is taken 50 ms
after the action; what arrives later (a fetch, a slow animation) is for
`wait_for(visual_stable=true)` or a screenshot. The cursor's own box is left out of the
comparison (the overlay is drawn unscaled in a clipped capture, so it is masked where it
stands and where the capture shows it).

The reply also points at the next look. `visual_change.region_px` is the same region in
pixels of the page's latest screenshot (its scale applied, and the scroll of a full-page
capture), so it can go straight into `screenshot(region=...)` to zoom on what changed; it is
left out when there is no screenshot of the page, when the latest is itself a zoom, or when
the page has scrolled since. When `screenshot(name=...)` snapshots are held and the action
changed the page, the reply lists them (`snapshots`) and `compare_hint` names the latest:
`screenshot(compare_to="before") shows what changed since that snapshot.` Measured
2026-11-19 (`scripts/verify_evidence_e2e.py`, Chrome 157.0.8103.38, native and Playwright
1.65.2, native headful): `region_px` on a toast overlaps it in the screenshot with IoU >= 0.5
at scale 1 and downscaled to 1000 px; the hint appears for a change with a snapshot held, not
for a no-op or with none held; evidence still adds 80-81 ms to a click at the median (N=20).

`capture=true` on any of those tools also returns the image after the action, cursor and
all (`image_path`, attached as an image for clients that render them, and its `scale` for a
following `click(x=, y=)`).

`wait_for(visual_stable=true)` waits until two thumbnails 150 ms apart are the same (web
fonts first), up to `timeout_ms`, and answers `stable`. A `screenshot` does the same for up
to `LYRA_BROWSER_CAPTURE_SETTLE_MS` (1000) first and says `settled: false` when the page
was still moving.

Measured 2026-11-18 (Chrome 157, `scripts/verify_evidence_e2e.py`, native and Playwright
1.65.2 headless, native headful): a no-op click `changed: false`; a click showing a toast
`changed: true` with the region over the toast; typing a change; a 700 ms transition
settled within the wait, a never-ending animation answered `timeout` within 1.6 s of a 1 s
budget. Median time evidence added to a click, N=20 clicks per arm taken in alternation
(cursor off in both arms): 79–81 ms over four runs (native headless and headful).

### Layout faults from the page itself: `inspect_layout`

Looking misses what is a shade or a pixel off. `inspect_layout(selector="", max_findings=30)`
reads the computed styles and geometry of what is visible and names three kinds of fault:
`low_contrast` (text under WCAG AA against what is painted behind it, 4.5:1 or 3:1 for large
text, with the ratio and both colours; disabled controls are exempt, as in WCAG 1.4.3),
`clipped` (text cut off by its own box or by an ancestor that clips, or spilling out of the
bordered or filled box that holds it) and `covered` (text or a control with something
painted on top). What is behind a text comes from the page's own paint order at that point
(`elementsFromPoint`), and colours in any CSS space (oklch, lab, `color-mix`) are converted
through a canvas that is never attached to the page. Text over an image, a video, a canvas or
a gradient is counted (`unknown_background`), not guessed. Not faults, by design: text that is
not visible (scrolled out of its scroller, clipped away, `opacity: 0`, visually-hidden
`sr-only` text), text under a sticky element or a bar fixed along a viewport edge (counted,
`under_fixed`), a transparent
click-catcher over a card, and text that cannot be hit-tested (`pointer-events: none`: its
background counts as unknown, its cover check is skipped and counted). Open shadow roots are scanned; `selector` takes CSS or the other tools' `aria-ref=`,
`text=` and `role=` forms. Each finding has `box_css` and, when there is a screenshot of the
page, `box_px` for `screenshot(region=...)`. It only reads: no permission, nothing written to
the page, and a control is labelled by its placeholder, `aria-label` or type, never by the
value typed into it.

Measured 2026-11-19 with Chrome 157.0.8103.38 (`scripts/verify_layout_e2e.py`, native and
Playwright 1.65.2, headless and headful, one 1280x1400 viewport), on a page with planted
faults and look-alikes. Found: `#c2c2c2` text on `#fafafa` (ratio under 2), pale text on an
oklch background, a pale placeholder, faint text inside a shadow root, white on black inside
a half-faded card (opacity applied once, to text and background alike), an absolutely
positioned tooltip that escapes a clipping card, a visible crop; text cut off by
`overflow: hidden` sideways and below its box, text cut off by an `overflow-x: hidden`
parent, text spilling out of its card; text with a box over it, text under an opaque modal
whose transparent inner box is what the hit-test returns, a button under an overlay, a button
under a fixed chat bubble, and a password field and a textarea under overlays (neither's
content in the reply). Not reported: `#222` text, 26 px text at 3.5:1 (checked and passed),
white on an oklch dark background, a disabled control, text over a dark canvas (also one with
`pointer-events: none`) and on a gradient (counted as unknown), rows scrolled out of a
scroller, `sr-only` and faded-out text, a line that scrolls inside a `pre`, a child over its
parent's text, a card under a transparent stretched link, and text under a bar fixed to the
viewport's edge (counted), text over a `pointer-events: none` colour scrim or a `::before`
fill (unknown), the button beside an ellipsis, a float beside wrapped text, an invisible file
input over its label, a checkbox, a box that scrolls sideways, a filled link's transparent `::after`
over its card, and a `pointer-events: none` caption over a dark canvas (unknown). Element descriptors stay
under 200 characters even for a 300-char
id. The page's `MutationObserver` records 0 mutations; a scan of that page (about 50 cards)
took 13-15 ms at the median (N=20), and the page script stops itself after 3.5 s
(`truncated: "time"`) before the tool's 5 s wait runs out. Four review rounds (each finding
verified by separate reviewers trying to refute it) found 31, 16, 11 and 2 cases; each one that
held is fixed, and all but two (html/body overflow on a scrolled page, the time budget while
gathering on a huge page) are pinned in the gate or the unit tests.

`lyra-uat` personas do not get `inspect_layout` by default (`DEFAULT_TOOLS`): the visual eval
measures what a model sees, and a DOM reading of contrast and overlap would answer its v2
tasks without looking.

### Before and after: `screenshot(name=...)`, `screenshot(compare_to=...)`

`visual_change` compares around one action. To check a change across a reload, a rebuild
or a fix made elsewhere, keep a capture under a name and compare a later one with it:
`screenshot(name="before")`, make the change, `screenshot(compare_to="before")`. The reply's
`diff` holds `changed`, `ratio` (the share of pixels that changed), `boxes` around the
changed regions (`box_px` in the image, `box_css` in the viewport, largest first, at most
20) and `url_changed`; the attached image is the new capture with each box outlined. An
element that moved is one box, not one per edge. Both captures are taken with lyra's cursor
off the screen, so its moving is not a change. Two captures at a different scroll position,
viewport size or scale are not compared pixel by pixel: `diff` says `mismatch` and which.
Snapshots are kept in memory only (8 at most and 48 MiB, oldest dropped) and are dropped
when the browser closes or another session takes it.

Measured 2026-11-19 with Chrome 157.0.8103.38 (`scripts/verify_compare_e2e.py`, native and
Playwright 1.65.2, headless and headful under Xvfb): a reload of an unchanged page compares
as `changed: false`, ratio 0; one tile of twelve moved by 3 CSS px, and one recoloured from
`#e5e7eb` to `#d4d8de`, each gives exactly one box on that tile (IoU >= 0.5); the cursor
moving between the captures gives no box; a scroll and a viewport change answer
`mismatch`. `screenshot(compare_to=...)` took 283–300 ms at the median over N=20 per run,
of which the pixel diff 19–25 ms.

### The virtual cursor

Before `click`, `hover`, `type_text` and `select_option` act, a cursor travels from where
it last stood to the element's centre, and the real mouse travels the same path, so the
page sees `pointermove`s and hover styles the way it would from a person. Then the action
runs, and the cursor stays where it acted: a person at the window (or at the VNC viewer)
sees what the agent pointed at, and so does the next `screenshot`, which draws it again
after a navigation cleared it. `request_takeover` and `ask_user_to_do` take it off the
screen. `LYRA_BROWSER_CURSOR=off` removes the cursor and the travel.

It is drawn with the DevTools overlay (`Overlay.highlightQuad`), not with the page's DOM,
so page scripts cannot see it and it cannot take a click. Measured 2026-11-18 with Chrome
157.0.8103.38 on Linux, `scripts/verify_cursor_e2e.py`, both drivers (native, Playwright
1.65.2), headless and headful under Xvfb: the click lands once after at least 5
`pointermove`s; the cursor's colour is in the screenshot at the click point and on the X
display; the page's `MutationObserver` records 0 mutations, the node count does not change
and `read_page` text and tree are identical before and after. Median time it added to a
click over N=20: 318–383 ms headless, 317–467 ms headful (default 300 ms travel), against
117–213 ms for a click without it. An element inside an iframe is clicked without the
cursor travel, since its box is in the frame's coordinates.

Bot checks: the overlay and DOM agents are switched on only when the cursor first moves,
i.e. on a pointer action, never by `open_browser` or `navigate`, so the launch and
navigation measured under "Looking like the user's Chrome" are unchanged. Whether a site
notices them during interaction was measured 2026-11-19 with `scripts/measure_compat.py
--headful --cells cursor-on,cursor-off --sites etsy,hyatt --reps 5 --gap 12` (Chrome
157.0.8103.38, native driver, `cdp` guard, Xvfb, fresh profile per visit; each visit
navigates, waits for the page to settle, hovers at a point of a screenshot, then judges the
page again): **etsy.com 5/5 with the cursor and 5/5 without; hyatt.com 5/5 and 5/5**, every
page answering 200 with its own title after the hover. On one hyatt visit with the cursor the
hover answered `blocked_by_policy` (a navigation started after it that nothing had declared)
and the tab ended on hyatt.com's `/loyalty` page, judged fine; what started it was not traced. The cursor therefore
stays on by default; `LYRA_BROWSER_CURSOR=off` is the switch for a site that does notice.

### Measured: tasks that need sight (`docs/measurements/visual-eval`)

`scripts/eval_visual.py` serves eight loopback tasks whose answer is only in pixels (a
target drawn on a canvas, icon-only buttons, a code shown for 2.5 s, a CSS colour, a dialog
whose close button is drawn, a chart value, text spilling out of its box, a panel that
changes colour; the page data is obfuscated, so reading the DOM does not give it away). The
site scores what the page saw the agent do, never the agent's own account. Each task is a
`lyra-uat` persona run with the `claude-code` brain, headless, step budget 25, every
episode on a fresh round of its task. `--brain scripted` is the oracle self-test, a gate:
each task played right and wrong through a real browser, the right play accepted and the
wrong one refused.

| | `baseline.json` | `after.json` |
| --- | --- | --- |
| date, lyra commit | 2026-11-18, `fff31878b9d1` (before marks, coordinates, evidence and the cursor) | 2026-11-18, `85e47120e610` |
| brain, model, Chrome | `claude-code`, Sonnet, Chrome 157.0.8103.38 | same |
| episodes (8 tasks x 2) | 16 | 16 |
| success rate | **0.625** (10/16) | **0.875** (14/16) |
| `canvas_target`, `canvas_modal` | 0/2 each | 2/2 each |
| `chart_value` | 0/2 | 0/2 |
| the other five | 2/2 each | 2/2 each |

What changed for the two canvas tasks is `click(x=, y=)` at the pixels of a screenshot.
Both `chart_value` failures in `after.json` are the same step: the model typed the value it
read and pressed Check with `submits=true`, which asked for permission to send a form; the
run's closed policy answers no prompt, so it was refused (`needs_approval`) and the value
never reached the page. Whether the values read were right is not measured, since the page
never saw them. That refusal is the consent layer working as documented: a declared
send is asked about even where nothing would be posted, because the declaration also
covers a send by `fetch` that the enforcement layer cannot see. N=2 per task is small; the
per-task numbers say which tasks moved, not by how much.

### Measured: harder tasks, before and after zoom and compare (`docs/measurements/visual-eval/v2`)

`scripts/eval_visual.py --suite v2` serves eight harder tasks, each answered by a click so
that no consent prompt is involved: 4-character codes drawn 5 px tall among one-character
near misses, the tallest of 60 bars (the top two 1 px apart), a target 2,600 px below the
fold, labels drawn only while the pointer is over a nameless button, the one tile that moved
1 px or was shaded slightly after Deploy, a card whose text is cut off by a box of the card's
colour, the card whose text has the lowest contrast, and the one of 36 boxes 1-2 px out of
line. Same harness as above (`claude-code` brain, headless, step budget 25, 2 repeats,
Chrome 157.0.8103.38). A first cut with easier settings was solved 16/16 by Sonnet and is
kept as `pilot-first-cut.json`.

| | before (master `6765bfb`/`a1cd4c6`, no zoom or compare) | after (`6526831`, zoom and compare) |
| --- | --- | --- |
| Sonnet (`baseline.json` → `after.json`) | **16/16** | **16/16** |
| Haiku (`baseline-haiku.json` → `after-haiku.json`) | **12/16** | **12/16** |
| Haiku `tiny_find` | 1/2 | 2/2 |
| Haiku `overlap` | 1/2 | 0/2 |
| Haiku `regression`, `faint_text` | 1/2 each | 1/2 each |
| Haiku, the other four | 2/2 each | 2/2 each |

Sonnet solves every v2 task with plain screenshots, marks and hovers, so this suite cannot
show a tool helping it; it shows that nothing regressed. Haiku used the new tools: in the
after run 7 of its 16 episodes zoomed (`screenshot(region=...)`), 4 kept a named snapshot,
and 1 compared with one. Its tiny-text task went from 1/2 to 2/2, both times after zooming
in on the tiles; overall it stayed at 12/16. Its one `regression` miss is the same step in
both runs: it pressed Deploy and finished without picking a tile (in the after run having
named a snapshot first, never compared with it). N=2 per task: this says which tasks a
model gets wrong and whether it reached for the tools, not that zoom raises a success rate.

#### Haiku at 5 repeats, before and after `region_px` and `compare_hint` (`haiku-r5-*.json`)

The same v2 suite with Haiku, 5 repeats per task (40 episodes), every episode recording
which seeing options its screenshots used (counted from the server-kept trace). Before:
master `e0d1e4a` (zoom and compare already there); after: `b6fcb83`, whose action replies
add `visual_change.region_px` and, with a snapshot held, `compare_hint`. Both measured
2026-11-18, Chrome 157.0.8103.38, step budget 25.

| | `haiku-r5-baseline.json` | `haiku-r5-after.json` |
| --- | --- | --- |
| success | **32/40** (0.800) | **32/40** (0.800) |
| `tiny_find` | 3/5 | 5/5 |
| `regression` | 4/5 | 5/5 |
| `faint_text` | 4/5 | 1/5 |
| `overlap` | 1/5 | 1/5 |
| `tall_bar`, `far_target`, `hover_tip`, `misaligned` | 5/5 each | 5/5 each |
| episodes that zoomed (`region`) | 19 | 13 |
| episodes that named a snapshot (`name`) | 9 | 16 |
| episodes that compared (`compare_to`) | **0** | **5** (3 of them `regression`) |
| episodes with marks (`annotate`) | 15 | 21 |
| mean steps, mean seconds per episode | 12.1, 24.6 s | 11.4, 20.3 s |

What the change did: Haiku went from never comparing to comparing in 5 episodes, three of
them on the task that is about a change (`regression`, now 5/5), and it finished episodes a
little faster. What it did not do: raise the overall rate, which is the same 32/40. The
`faint_text` drop (4/5 to 1/5) is not a tool effect in the traces: each miss is one
screenshot and a click on the wrong card, as in the baseline's miss; N=5 per task leaves
room for that much swing. `overlap` (text cut off by a box of the card's colour) stays the
hardest task for Haiku either way.

### Measured: multi-step work, before and after `run_steps` (`docs/measurements/flow-eval`)

Suite `flow` of `scripts/eval_visual.py` is ordinary work that takes several actions over
more than one state of a page: a three-step wizard, a search with a category filter and
same-named decoys, three table rows edited one by one, settings over tabs, a form in an
iframe, a cookie banner in front of a form, a cart quantity, a form that rejects a phone
with spaces. The page reports what was done and the server judges; nothing needs sight.
What it measures is success and the number of calls the model made (`tool_calls`: its own
calls; a `run_steps` call is one, however many steps it ran).

Haiku r3 (`haiku-r3-baseline.json`, `haiku-r3-after.json`): claude-code brain, model
`haiku`, 8 tasks x 3 repeats = 24 episodes each, step budget 40, UAT policy `autonomous`
(nobody is there to approve the Add/Finish/Checkout a model declares as a send),
Chrome 157.0.8103.38, 2026-12-01/02. Baseline on lyra b577ce2 (no `run_steps`); after on
6026915. Medians per task, baseline -> after:

| task | success | tool calls | episodes using `run_steps` | seconds | tokens (in + cache + out) |
|---|---|---|---|---|---|
| `flow_wizard` | 3/3 -> 3/3 | 16 -> 13 | 3/3 | 21 -> 23 | 165k -> 182k |
| `flow_search` | 3/3 -> 3/3 | 10 -> 9 | 3/3 | 17 -> 20 | 144k -> 179k |
| `flow_table` | 3/3 -> 3/3 | 23 -> 22 | 0/3 | 33 -> 28 | 385k -> 298k |
| `flow_settings` | 3/3 -> 3/3 | 19 -> 21 | 1/3 | 28 -> 34 | 229k -> 304k |
| `flow_iframe` | 3/3 -> 3/3 | 13 -> 7 | 3/3 | 18 -> 20 | 191k -> 152k |
| `flow_cookie` | 3/3 -> 3/3 | 19 -> 17 | 1/3 | 27 -> 30 | 223k -> 233k |
| `flow_cart` | 3/3 -> 3/3 | 9 -> 10 | 0/3 | 16 -> 21 | 132k -> 157k |
| `flow_validation` | 3/3 -> 3/3 | 19 -> 14 | 2/3 | 31 -> 29 | 266k -> 259k |
| **all 24** | **24/24 -> 24/24** | **16 -> 13.5** | **13/24** | **24.4 -> 28.1** | **193k -> 210k** |

- Fewer calls, not less work: the median episode made 16% fewer calls, but took about 4 s
  longer and used about 9% more tokens, and ran more actions in all (median `steps`, which the UAT budget charges per step: 17 ->
  21.5). Cost was the same ($0.11 for 24 episodes either way).
- Where a page's next actions are known up front (a wizard, a form in an iframe, a form to
  fix) the model batched them; where each action changes what comes next (rows that turn
  into editors, a cart that opens) it mostly did not.
- Two attempts. The first after (`haiku-r3-after.attempt1.json`, lyra 29c1187) had
  `run_steps` but Haiku never called it (0/24; median 17 calls): lyra-uat gives the brain
  its own system prompt, so the one line in the server instructions never reached it.
  The second added a line to lyra-uat's persona prompt and opened `run_steps`'s
  description with what it is for; the tasks did not change.
- The 9% more tokens is within what this measurement cannot tell apart. The baseline and
  the first after did not batch at all (`run_steps` used 0/24 times there), yet their
  median tokens differ by 15% (193k vs 222k). The A/B below measures the reply size on its
  own.

#### Brief and full step lists, side by side (`haiku-r5-full.json`, `haiku-r5-compact.json`)

`run_steps` lists the steps that went well briefly (see `run_steps`); `full` is the whole
reply of each step, as in r3. To compare the two without the day-to-day drift above, both
arms ran in one systemd unit, interleaved by repeat with the first arm alternating:
`scripts/eval_ab.sh LYRA_BROWSER_STEPS_REPLY full compact 5 ...` (the parts joined by
`scripts/eval_merge.py`). Claude-code brain, model `haiku`, 8 tasks x 5 repeats = 40
episodes per arm, step budget 40, policy `autonomous`, Chrome 157.0.8103.38, lyra
7644a7f, 2026-12-02 (KST). Medians per task, full -> compact:

| task | success | tool calls | steps | episodes using `run_steps` | seconds | tokens (in + cache + out) |
|---|---|---|---|---|---|---|
| `flow_wizard` | 5/5 -> 5/5 | 10 -> 10 | 21 -> 23 | 5/5 -> 5/5 | 24 -> 26 | 182k -> 179k |
| `flow_search` | 5/5 -> 5/5 | 10 -> 11 | 15 -> 12 | 4/5 -> 2/5 | 22 -> 20 | 158k -> 176k |
| `flow_table` | 5/5 -> 5/5 | 23 -> 20 | 24 -> 27 | 0/5 -> 2/5 | 30 -> 32 | 297k -> 298k |
| `flow_settings` | 5/5 -> 5/5 | 19 -> 21 | 20 -> 22 | 0/5 -> 1/5 | 30 -> 32 | 240k -> 241k |
| `flow_iframe` | 5/5 -> 5/5 | 9 -> 8 | 14 -> 13 | 5/5 -> 4/5 | 19 -> 21 | 154k -> 152k |
| `flow_cookie` | 5/5 -> 5/5 | 21 -> 16 | 22 -> 17 | 2/5 -> 2/5 | 31 -> 28 | 247k -> 189k |
| `flow_cart` | 5/5 -> 5/5 | 10 -> 8 | 11 -> 9 | 0/5 -> 0/5 | 20 -> 19 | 135k -> 135k |
| `flow_validation` | 5/5 -> 5/5 | 18 -> 14 | 21 -> 22 | 3/5 -> 5/5 | 32 -> 30 | 256k -> 236k |
| **all 40** | **40/40 -> 40/40** | **12.5 -> 14** | **20 -> 19.5** | **19/40 -> 21/40** | **25 -> 27** | **188k -> 208k** |

- **No token difference was measured.** Total tokens, compact over full, came to 0.992,
  with a 95% interval of 0.906 to 1.081 (bootstrap within tasks, 5,000 resamples). The
  pooled median moves the other way (188k -> 208k) because it mixes tasks of different
  size. Task by task, compact is lower on four, higher on three and level on one.
- **Why the effect is too small to show.** The brief list saves about 130 characters per
  step, and an episode ran about 5.75 steps inside `run_steps`. That is about 190 tokens
  of reply, re-read on later turns as cached context: roughly 1.3k tokens, or about 0.6%
  of a ~210k-token episode. Run-to-run noise at this N is about ±9%. Most of an episode's
  tokens are page reads (about 5 `read_page` calls per episode in either arm) and their
  growing context, not step lists.
- Both arms kept every episode (40/40). Both made fewer calls than the r3 baseline
  (median 16): 12.5 for full and 14 for compact. Compact remains the default for its
  smaller replies (459 vs 1,124 characters for the five-step batch of
  `verify_steps_e2e.py`), which this measurement neither confirms nor contradicts in
  tokens.

#### Shorter tool descriptions, side by side (`haiku-r5-docs-full.json`, `haiku-r5-docs-lean.json`)

The tool descriptions were cut to their contracts (see "What a turn carries" under
Development). To check that no model lost what it needs, the build before the cut (`full`,
lyra d754f486f173, exported with `git archive`) and the build after it (`lean`, lyra
5057447e7021) ran in one systemd unit, interleaved by repeat with the first arm alternating:
`scripts/eval_ab_python.sh`, one Python interpreter per arm, each checked to import lyra
from its own tree. The two trees differ only in description text under `src/`; the tasks
and the harness came from the lean checkout for both arms. Claude-code brain, model
`haiku`, Claude Code 2.1.334, 8 tasks x 5 repeats = 40 episodes per arm per suite, Chrome
157.0.8103.38, 2026-12-02. An earlier attempt stopped at about episode 72 when its
temporary files disappeared; none of it is used.

The brain runs with `--tools ""`, and that leaves Claude Code no tool search: lyra's
schemas go out in full with every request, whatever `ENABLE_TOOL_SEARCH` says. A one-turn
probe the same day (generic client, `--tools ""`) measured 3.5k input tokens with no MCP
server, 22.8k with the full build and 15.1k with the lean one (15.0k with tool search off).

Flow suite (step budget 40, policy `autonomous`). Medians per task, full -> lean:

| task | success | tool calls | steps | seconds | tokens (in + cache + out) |
|---|---|---|---|---|---|
| `flow_wizard` | 5/5 -> 5/5 | 13 -> 18 | 21 -> 25 | 25 -> 29 | 192k -> 161k |
| `flow_search` | 5/5 -> 5/5 | 8 -> 8 | 14 -> 13 | 19 -> 18 | 155k -> 109k |
| `flow_table` | 5/5 -> 5/5 | 20 -> 23 | 24 -> 24 | 28 -> 28 | 260k -> 215k |
| `flow_settings` | 5/5 -> 5/5 | 19 -> 20 | 20 -> 21 | 29 -> 30 | 239k -> 209k |
| `flow_iframe` | 5/5 -> 5/5 | 9 -> 10 | 14 -> 15 | 20 -> 16 | 158k -> 111k |
| `flow_cookie` | 5/5 -> 5/5 | 16 -> 19 | 19 -> 22 | 29 -> 29 | 249k -> 158k |
| `flow_cart` | 5/5 -> 5/5 | 11 -> 12 | 12 -> 13 | 20 -> 21 | 153k -> 113k |
| `flow_validation` | 5/5 -> 5/5 | 15 -> 14 | 23 -> 22 | 31 -> 31 | 246k -> 186k |
| **all 40** | **40/40 -> 40/40** | **13.5 -> 14.5** | **19.5 -> 21** | **25 -> 26** | **210k -> 160k** |

V2 suite (step budget 25, policy `closed`). Medians per task, full -> lean:

| task | success | tool calls | steps | seconds | tokens (in + cache + out) |
|---|---|---|---|---|---|
| `tiny_find` | 5/5 -> 3/5 | 18 -> 21 | 19 -> 22 | 38 -> 42 | 362k -> 319k |
| `tall_bar` | 5/5 -> 5/5 | 15 -> 16 | 16 -> 17 | 27 -> 28 | 265k -> 219k |
| `far_target` | 5/5 -> 5/5 | 11 -> 14 | 12 -> 15 | 21 -> 25 | 191k -> 180k |
| `hover_tip` | 4/5 -> 5/5 | 13 -> 14 | 14 -> 15 | 30 -> 27 | 263k -> 173k |
| `regression` | 3/5 -> 5/5 | 6 -> 9 | 7 -> 10 | 17 -> 15 | 94k -> 95k |
| `overlap` | 1/5 -> 5/5 | 8 -> 10 | 9 -> 11 | 17 -> 17 | 132k -> 95k |
| `faint_text` | 1/5 -> 5/5 | 5 -> 4 | 6 -> 5 | 12 -> 10 | 73k -> 49k |
| `misaligned` | 5/5 -> 5/5 | 6 -> 6 | 7 -> 7 | 16 -> 16 | 124k -> 83k |
| **all 40** | **29/40 -> 38/40** | **9.5 -> 10** | **10.5 -> 11** | **19 -> 20** | **164k -> 116k** |

- **Success did not drop.** Flow: 40/40 in both arms. V2: 29/40 -> 38/40. The guard
  allowed lean to lose one flow episode and two v2 episodes; it lost none overall.
- **The v2 gain is not explained.** `overlap` and `faint_text` went from 1/5 to 5/5 and
  `regression` from 3/5 to 5/5, while `tiny_find` went from 5/5 to 3/5. The full arm's
  weak tasks are the ones `haiku-r5-after.json` was weak on (`overlap` 1/5, `faint_text`
  1/5). The episodes used the same tools in both arms (screenshot, read_page, click; no
  `inspect_layout`); each full-arm miss on those two tasks made one click, failed the
  server's check and finished with the persona reporting `blocked`. At N=5 per task this
  is a guard that passed, not a measured gain.
- **Tokens: 24% fewer on flow, 18% fewer on v2.** Total tokens, lean over full: flow 0.764
  (95% interval 0.719 to 0.811), v2 0.822 (0.733 to 0.917), bootstrap within tasks, 5,000
  resamples. Lean is lower on every flow task. Cache reads per model turn (an episode's
  cache reads over its calls + 1) fell from a median of 14.3k to 9.4k tokens on flow
  (15.4k to 11.4k on v2), about what the shorter list saves per request. Almost all of these tokens are cache reads, so cost fell less: flow
  $0.181 -> $0.168 for 40 episodes, v2 $0.184 -> $0.175.
- Calls and steps did not fall: the median episode made 13.5 -> 14.5 calls on flow and
  9.5 -> 10 on v2.

## Permissions

The agent declares what it intends; the browser is judged on what it actually
does. Those are separate layers because a tool cannot know what a page will do
with a click — `onclick="form.submit()"` submits from a control that looks inert,
an `input` listener submits while the agent only typed, and an element's type can
change between being checked and being clicked.

**Grants** are `(origin × capability)` and short-lived:

| Capability | Meaning |
|---|---|
| `NAVIGATE` | Load a document from this origin. Implies `INTERACT` on it |
| `INTERACT` | Click and type while staying on this origin |
| `SUBMIT` | Send a non-idempotent request. **Single-use** |
| `UPLOAD` | Give a file to a page (a picker, a drop target). **Single-use** — requested by `upload_file` |
| `PUBLISH` | Make content publicly visible — an item an audience can see. **Single-use** — requested by `publish`, implied by nothing |
| `INSPECT` | Read what the person's page holds — response bodies, cookie and storage values, full URLs. Leasable per origin, implied by nothing — requested by `network_request(body=true)`, `storage(reveal=true)`, `export_har(include_bodies=true)` |
| `EVALUATE` | Run caller-written script in the page. **Single-use**, implied by nothing — requested by `evaluate`, which shows the expression in the prompt |
| `DOWNLOAD` | Write a file to disk. **Single-use** — requested by `click`, `press_key` or `navigate` with `download=true`; the grant pays for one file and ends with the call |

Arriving on a site carries permission to use it, so ordinary clicking is not
re-asked. Sending a form and leaving for another site are separate decisions and
are asked — declare them with `submits=true` (`submit=true` on `type_text`).

**Enforcement** watches outgoing navigations at the request, so it catches a
submission or an escape whatever produced it. A refusal fails the request as
`net::ERR_ABORTED`, the one network error Chrome never turns into an error page, so the
page stays standing and the agent can recover. (It used to answer with HTTP 204, which
Chrome also ends as `ERR_ABORTED`; Playwright 1.64 reads a 204 document as a finished
navigation and then waits on it until every later action times out — measured
2026-11-01, playwright 1.64.1 vs 1.63.0, Chrome 154.)
URLs with no host — `file:`, `data:`, `javascript:` — are never "the same site"
and are asked every time. A page with no host of its own (a new tab, an `about:blank`
popup) cannot be told from another one either, so leaving one for a site buys that one
navigation (with the redirects it follows, such as a sign-in that comes back) for as
long as the call runs, not a lease: another blank tab is asked again (unless the site
is on a trusted list), and a popup some page opened on `about:blank` cannot ride the
approval to the same site afterwards. On the `cdp` backend a popup's blank page is judged
as its opener's, as Chrome itself treats it: a site's own `target=_blank` link is moving
around that site, and a popup opened by another site is that site leaving for this one. Where the guard stands — Playwright's route, or a second
DevTools connection that also sees redirect hops — is a choice, see
[Guard backends](#guard-backends).

Where the line falls, measured rather than asserted:

- **A same-origin GET navigation is interaction, not a submission.** A search box
  puts what you typed in the query string; gating that would gate every search
  box and every link with parameters. `SUBMIT` means a body or a mutating method.
- **A submission is authorised by the origin that sends it**, not by wherever the
  form points. Cross-origin form actions are ordinary — payment handlers, SSO,
  third-party endpoints — and no tool can read a form's `action` before the click
  without the TOCTOU this layer exists to avoid. The destination is recorded in
  the audit under the label `cross_origin_send` — an audit key, not a capability,
  and never purchased.
- **A page that moves itself to another host is leaving**, and is asked. A site
  bouncing to its own subdomain lands here too; the guard cannot tell that from a
  hostile page escaping. The refusal is recoverable — the original document is
  still there and the audit names the destination — so the agent can read where
  it was being sent and ask for it.
  `navigate`, `go_back` and `reload_page` answer it as `blocked_by_policy`, with the
  `url` the tab still stands on, about a second after the refusal — also when the
  page did it before it finished loading. The refusal commits nothing, so the driver
  would otherwise wait out its own 30 s timeout for a navigation that is gone
  (`scripts/verify_scriptredirect_e2e.py`; neverssl.com does exactly this). `click`,
  `type_text`, `press_key` and `hover` answer it too when the navigation was theirs
  (see [What an action set off](#what-an-action-set-off-blocked_by_policy-new_tab));
  they used to say `ok` (`scripts/verify_click_refusal_e2e.py`).
- **A redirect hop is judged like the navigation it leads to.** A 301/302/303/307/308
  to another origin is classified exactly as a first request there would be: leaving
  the site is `navigate` and is asked, a 307/308 that repeats a POST body is `submit`,
  and a hop that stays on the origin that sent it (or upgrades it from `http` to
  `https`) is not judged at all. The audit row carries `redirect_from`, and an
  approved site that answers 302 to an unapproved one is refused like the same
  destination asked for directly: `navigate`, `go_back` and `reload_page` answer
  `blocked_by_policy` and the tab stays where it was. The agent asked for one URL and
  was turned away from another, so that answer also carries `redirected_to`, the
  origin it was sent to (never the path or the query), for the agent to ask for.
  Playwright never shows a hop to a route handler, so the guard hears of it from the
  `request` event, *after* the request was sent, and cancels the load there
  (`scripts/verify_redirect_hop_e2e.py`; what that leaves open is listed below).

Verified against the shipped defaults: four undeclared POSTs (space key, JS
`form.submit()` from a `type="button"`, an `oninput` listener, and an attribute
flipped after the check) are all stopped, while the declared submit goes through.

**What this does not cover**, stated rather than discovered later:

- With the default `route` backend, an HTTP redirect hop is judged after it has left, not
  before. The request to the first hop that no grant covers is sent — with that site's
  cookies, and the body of a 307/308 POST — and only the rest of the chain is cut. A
  server that answers before the cancellation lands commits the page first, and loopback
  or a LAN, where the targets most worth refusing live, always does: the guard then
  replaces the tab with `about:blank` so the agent does not read it, the audit records
  `not_stopped`, and the call still answers `blocked_by_policy`. Seeing a hop before it
  leaves is not possible from `context.route`: Playwright continues every hop itself,
  also one that follows a `route.fulfill(302)`, and answering each document from Node
  (`route.fetch`) to see the redirect first puts a Node TLS and HTTP/1.1 fingerprint on
  every page while still leaving the later hops unseen (measured).
  `LYRA_BROWSER_GUARD=cdp` judges every hop *before* it leaves, so a refused hop's
  destination sees nothing; see [Guard backends](#guard-backends).
- A page can ask the browser to *prefetch* or *prerender* another page
  (`<script type="speculationrules">`). Chrome sends those requests, and serves the
  navigation that later activates one, without an interception point: neither
  backend is shown the request, nor the click that follows (measured, Chrome 154:
  a prefetched cross-site link was followed with the guard seeing nothing, and the
  cross-site prefetch itself reached its server). It is a GET, so it is the same
  channel as `<img src="https://elsewhere/?data">`; what it adds is a navigation
  nobody judged.
- With `route`, a navigation that a *service worker* answers is never shown to the
  guard either. Playwright's `service_workers="block"` is an init script that a
  page defeats by calling the prototype's `register`, and a worker already in the
  profile is untouched by it (measured: an origin's pre-registered worker served
  that origin's page to a link click with no judgement). The `cdp` backend turns
  workers off for every page it guards.
- A single-page app does its damage over `fetch()`, which is not a navigation and
  is not judged. Deleting mail in a webmail client is an XHR, not a form post.
- An approved page choosing where to send its form. Judging a submission on its
  sender is what makes payments and SSO work, and it is also an exfiltration
  channel: the audit records it (under the key `cross_origin_send`, which is only a
  label on the audit row, not a capability), it does not stop it, unless the destination
  is on `LYRA_BROWSER_DENIED_ORIGINS`, which the guard refuses whoever sends there.
- A single-use scope is handed back about two seconds after the action that
  bought it, not instantly, because a click's navigation can leave just after
  the call returns. A page that submits inside that window rides an approval
  meant for the click. Two seconds rather than the ten minutes it used to be
  (`LYRA_BROWSER_RELEASE_GRACE`). A call cancelled while it is still asking (the client
  went away mid-prompt) hands back at once what it had already bought.
- The approval for a `file:` URL names that URL and covers only it, once — every
  `file:` URL is otherwise the same origin, which would make one yes a yes to the
  whole disk.
- The content of a download. It is gated, not inspected (see [Downloads](#downloads)):
  an approved download is bytes from that site, written as-is under a sanitised name.

Enforcement narrows what a compromised turn can reach; it does not make an
approved origin safe.

**One browser, one session.** Reading checks who is driving; only a mutating
tool becomes the driver, so a passive client cannot take the browser by asking
for a screenshot. Reading still counts as *using* it, so a holder part-way
through a read-only pass is not idle and does not lose the window. Grants are kept per session, but every session drives the
*same* window, and the route handler has no way back to a request
context — so whichever session called a tool last would decide how the next
request is judged, and one client's single-use approval would be spent by
another's traffic. Rather than offer an isolation it cannot deliver, the server
serves one session at a time and answers the rest with `session_conflict`.
Ownership lasts as long as the window: `close_browser` ends a turn, drops the
grants, and lets the next session claim it. A holder that goes quiet for
`LYRA_BROWSER_OWNER_IDLE_TIMEOUT` (default 900s) also hands it on — closing is
owner-only, so a client that drops with its window open would otherwise lock the
server for the life of the process. **The handoff closes the window**: passing on
a running browser would leave the previous holder's document loaded and still
able to start navigations, which the guard would then judge, and charge, against
whoever now holds the session.

**What "quiet" means.** Quiet is measured from the end of the session's last call, and
only while it has no call in flight and its window is not with the person:
- A call that outlasts the timeout is working, not gone. That covers a slow page, a long
  `wait_for`, or a consent dialog the person has not answered yet.
- A window handed to the person is theirs for as long as they take: a `request_takeover`
  not yet resumed, or an `ask_user_to_do` turn the agent has not taken back. Its session
  is never let go meanwhile. Its quiet time starts again when the call that takes the
  window back ends.
- This holds with spaces off (the holder) and on (each space).

`scripts/verify_idle_e2e.py` proves it with a 3 s timeout and two streamable-HTTP
clients, on both drivers. The long-call case runs headless and headful, and the takeover
and `ask_user_to_do` cases run headful under xvfb. While A is busy or handed over, B's
calls do not let A go, and nothing is audited as `owner_timed_out`. Once A is quiet past
the timeout, A is let go as before (2026-12-02, Chrome 157.0.8103.38). Before this, quiet
counted from the start of the last call, so a call in flight or a window with the person
could be closed mid-way.

That is the default. With `LYRA_BROWSER_SPACES=1` the server serves several sessions at
once instead, each in a space of its own; see
[Spaces](#spaces-several-sessions-one-browser-lyra_browser_spaces).

**Who is answering.** `auto` asks the user through MCP elicitation, where the
model cannot forge the answer. Only a client that cannot be asked at all — no
elicitation handler, no live request — falls back to honouring `confirm=true`,
and the audit records `consent_channel=legacy` with the reason. A decline, a
cancel and a timeout are *answers*: the model asserting `confirm=true` never
overrides one. A client that does not pass an elicitation handler takes that
fallback; wiring one is what turns the gate from a convention into a boundary, and
needs no change here. Hermes does pass one: its approval prompt answers, and its
value-less accept is read as the yes it is.

**Autonomous runs.** When nobody is there to answer, `LYRA_BROWSER_CONSENT_CHANNEL=autonomous`
(or `target.policy: autonomous` in a UAT run) approves what a task on the open web
needs: navigation to any site, and a declared `SUBMIT`, `UPLOAD` or `DOWNLOAD`. Each
approval is audited as `consent_channel=autonomous`, so a run's side effects can be
listed afterwards. It still refuses `PUBLISH`, `EVALUATE`, `INSPECT`, `file:`/`data:`/`javascript:` origins,
and any site in `LYRA_BROWSER_DENIED_ORIGINS` (same entry forms as the trusted list,
and it wins over every other yes). The default stays `auto`/`elicit`, so nothing
changes unless the operator chooses it.

**Trusted origins.** Every new site costs one prompt, and a prompt nobody
answers holds its tool call for `LYRA_BROWSER_CONSENT_TIMEOUT` (default 300s)
before it becomes a denial. For sites the operator always uses, that answer can
be given in advance: `LYRA_BROWSER_TRUSTED_ORIGINS` is a comma- or
whitespace-separated list of sites that are pre-approved for `NAVIGATE` — and the
`INTERACT` it implies — so they are not asked about again. The operator writes it;
nothing the model or a page says can add to it.

| Entry | Trusts |
|---|---|
| `https://www.kvraudio.com`, `http://localhost:3000` | exactly that scheme, host and port |
| `kvraudio.com` | `https` on the default port, that host only — not `www.kvraudio.com`, not `http://` |
| `*.example.com` | `https` on the default port, any subdomain at any depth — **not** `example.com` itself |

Hosts are compared as parsed `(scheme, host, port)` fields, never as text, so
`https://kvraudio.com.evil.io`, `https://kvraudio.com@evil.io` and
`https://kvraudio.com:8443` are not `kvraudio.com`. A site that redirects between
`example.com` and `www.example.com` needs both (`example.com` and
`*.example.com`). An entry that cannot be read is dropped and the rest still load:
empty and malformed entries, a lone `*`, single-label wildcards (`*.com`),
wildcards on an IP address, IPv6 literals, paths, userinfo, a port on a bare host
(write `http://localhost:3000`), and any scheme but http(s) — `file:`, `data:`,
`about:` and `blob:` name no site. The list does not know public suffixes:
`*.co.uk` is two labels and would be accepted, so do not write it.

What it covers is deliberately small. It never answers `SUBMIT`, `UPLOAD`,
`PUBLISH` or `DOWNLOAD`: those stay single-use and are still
asked on a listed site, every time. (To pre-approve sending from your own product for
end-to-end runs, `LYRA_BROWSER_TRUSTED_SEND_ORIGINS` is a separate list that answers
`SUBMIT` and `UPLOAD` and nothing else.) The list also holds where the browser *arrives* without
a `navigate` call -- a redirect hop or a followed link to a listed site -- because the guard
applies it to NAVIGATE too. It does not apply to an opaque origin, while
the user holds a takeover, or when approval is off (that stays
`consent_channel=off`). A listed site gets a real grant with the same lifetime
and initiator binding an approved one would, so enforcement judges it identically,
and the audit records `consent_channel=trusted` with the entry that matched.
`trusted` is a way a decision was reached, not a value of
`LYRA_BROWSER_CONSENT_CHANNEL`. It applies under `auto`, `elicit` and `legacy`.

**Takeover.** While the user holds the session, every mutating tool returns
`takeover_active` and the agent waits — including `highlight_element` and
`ask_user_to_do`, which write to the page. Reading tools keep working.

Enforcement steps aside too. Grants record what the *agent* was allowed to do;
holding a person to them would refuse them their own browser, and takeover exists
for the passwords, CAPTCHAs, 2FA and payments the agent must not do alone — every
one of which is a navigation. Those are recorded as `user_driven`, so the trail
distinguishes what a person did from what was approved for the agent. The one thing
that does not step aside is `LYRA_BROWSER_DENIED_ORIGINS`: a denied site is refused on
the user's turn too (navigations and downloads alike), because the guard cannot tell
their navigation from a script's on the page they were handed.

**A requested step.** `ask_user_to_do` hands the window over the same way without
freezing the agent, which keeps reading to see when the step is done. Until the agent's
next acting call (anything that stands down for a takeover, except `highlight_element`)
the user's sign-in, CAPTCHA or payment navigates as theirs (`user_driven`, `reason`
`ask_user_to_do`; a takeover's rows say `takeover`). That call takes the window back, and
so does closing the browser or handing it to another session. Without this, a user asked
to sign in clicked "Log in" and nothing happened: the guard measured their form POST
against the agent's grants, which held no `SUBMIT`.

## Spaces: several sessions, one browser (`LYRA_BROWSER_SPACES`)

By default one MCP session drives the browser at a time and the rest get
`session_conflict` (see Permissions). With `LYRA_BROWSER_SPACES=1`, one server serves
several sessions at once — several agents connected to the same `lyra-browser --http`,
say — and each gets a **space** of its own in the one logged-in browser, made on its
first call. Off by default: it is opt-in while real use measures it.

| | per space | shared |
|---|---|---|
| Tabs | its own tabs and their popups; headful, its own window | — |
| Grants | what its session was approved for | — |
| Navigation judging | by the space that owns the tab a request came from | — |
| Refusals (`blocked_by_policy`), captures (`screenshot(name=...)`) | its own | — |
| Console and network log (`console_messages`, `network_requests`, `network_request`, `export_har`) | its own tabs' entries, its own console switch | — |
| Native dialogs (`handle_dialog`, a reply's `dialogs`) | answered by its armed answer, reported to it | the one listener |
| Hand-off (`ask_user_to_do`, `request_takeover`, `resume_after_takeover`) | stands down that space's tools and waves through that space's tabs only | — |
| Downloads | paid for by, and reported only to, the owner of the tab they arrived on | the download dir |
| Cookies, local storage, the profile, the screen | — | one browser, one profile |

- **How requests are attributed.** Spaces always use the `cdp` guard (on every driver):
  the sidecar names the tab each document request came from, a popup takes its opener's
  space the moment it attaches (`rel="noopener"` too — Chrome still reports the opener)
  and an out-of-process iframe its page's. Playwright's route hands the guard no frame for
  a popup's first request, so `route` cannot do this. A request no space owns — a tab the
  user opened, one opened from outside the browser, a service worker — is judged against
  nobody's grants, and refused: no operator list, autonomous channel or user's turn
  stands in for an owner.
- **Tabs.** `tabs` lists only the caller's tabs, numbered as in the whole browser;
  another session's tab, or the user's, answers `not_your_tab`. Every tool acts on the
  caller's current tab.
- **Ending.** `close_browser` closes the caller's tabs and drops its grants; a space idle
  past `LYRA_BROWSER_OWNER_IDLE_TIMEOUT` is let go the same way on another session's
  next call. Idle means no call in flight and no window with the person, counted from
  the end of its last call (see What "quiet" means, under Permissions). The browser itself
  closes only when nobody else has a tab.
- **The console and network log.** Each entry belongs to the space whose tab it came
  from. A popup's first requests, recorded before the popup is adopted, are attributed
  when they are first read. A space reads its own entries only. Another space's request
  id answers `not_found`, and its traffic is left out of an `export_har`. An entry of a
  tab no space owns is shown to nobody. `console_messages(capture=true)` turns capture
  on for the caller's tabs only, so one session never sends `Runtime.enable` to
  another's pages. Request numbers are shared across spaces, so a gap in `seq` shows
  only that something else was recorded.
- **Native dialogs.** One listener still answers every dialog in the browser. That is
  the only place a popup's first-script dialog is seen. What it answers with is the
  space's own. A dialog raised on a space's tab gets that space's armed answer
  (`handle_dialog`) while that space's call acts, else the default, and only that
  space's next reply reports it. Another space's call in between neither spends the
  answer nor lets it lapse. A dialog on a tab no space owns gets the default and is
  reported to nobody.
- The audit trail tags each navigation verdict with `space` (a label such as `s-1a2b3c4d`,
  never the session id) and records `unattributed` for a request no space owns.

Measured 2026-12-02 by `scripts/verify_spaces_e2e.py` (two real streamable-HTTP MCP
clients on one server; Chrome 157.0.8103.38; `native` and Playwright 1.65.2 drivers):
32 checks headless and 40 headful (under xvfb), all passing on both drivers. The
console and network log per space added 15 checks, and dialogs per space 10 more. They
ran on 2026-12-02 on both drivers: 57 checks headless (`native` and Playwright 1.65.2) and
65 headful (`native`), all passing. Among them: A's console line, request, request id
and HAR entries are not B's to read, and B's console switch is its own. A armed a yes,
then B's confirm, raised in B's call in between, got the default. A's next call got A's
yes, and B was never told of A's dialog. Also among them:
A's approval for a site does not carry B there, and a link B clicks to it on B's own
page is refused by the guard while the same link clicked by A goes through; B's refusal
during A's in-flight navigation leaves A's `ok`; A's popup is A's and invisible to B; the
user's tab is `not_your_tab` to both; A's hand-off lets the user's navigation in A's
window through and nothing of B's; A's takeover stands down A's tools, not B's; the
spaces have separate windows headful; and with spaces off the second session still gets
`session_conflict`.

### Several stdio sessions: `lyra-browser --shared` (`LYRA_BROWSER_SHARED`)

A client that starts its server over stdio, as Claude Code does once per session, gets
a browser of its own, and the second gets a profile without the logins. With
`--shared` (or `LYRA_BROWSER_SHARED=1`; the Claude Code plugin's option "Share one
browser between sessions"), that process is only a stdio proxy. It connects to one
server per user and data dir, with spaces on, and starts it when none answers. Each
session is a space in the one browser (`src/lyra_browser/shared.py`).

- **Channel.** Unix sockets in `$XDG_RUNTIME_DIR/lyra-browser` (directory 0700,
  sockets 0600; a directory that is not this user's alone is refused). There is no
  TCP port, so no other local user's process can reach the logged-in browser.
  Without `XDG_RUNTIME_DIR` (macOS), the session says so on stderr and serves
  itself alone, as without `--shared`.
- **Consent.** Each session's dialogs go to that session. Toward the server, the
  proxy declares only what its own client declared (elicitation, sampling, roots).
  A client without dialogs is not handed one, and its calls do not fall back to the
  model's own `confirm`.
- **Bypass.** Claude Code's bypass field is carried per call: it lifts the dialog
  for the call that carries it, not for the session or for others.
- **Lifetime.** Each proxy holds a lifeline connection, which the kernel closes
  however the proxy ends. The server exits when none has been held for
  `LYRA_BROWSER_SHARED_IDLE` seconds (60), closing the browser. Starting and
  stopping share one lock, so two sessions never start two servers, and a stale
  socket from a killed server is cleared. If the server dies under a connected
  session, that session's next call waits for a new one in a new browser. Its old
  approvals and tabs are gone with the old browser.
- **Configuration.** The first session's flags and environment configure the server
  for everyone who joins it.

Measured 2026-12-02 by `scripts/verify_shared_e2e.py`: three real stdio clients
(`python -m lyra_browser --shared`) on a private socket dir and data dir, Chrome
157.0.8103.38, `native` and Playwright 1.65.2 drivers, headless. 29 checks, all
passing on both drivers:

- The first session started the server in 1.6 to 1.7 s.
- One server and one Chrome served all three, all on the shared profile.
- A's dialog approved A's navigation and B's declined B's. The client without
  elicitation was never shown one: the audit gives elicit/approved, elicit/declined,
  and "declares no elicitation", each in its own space.
- B could not list or switch to A's tab.
- The bypass field lifted A's dialog for that call only.
- A screenshot's image block came through the proxy.
- With every session gone, the server exited within 8 s, its sockets and Chrome with
  it.
- After `kill -9` a connected session's next call worked in a new server, and so did
  a new session starting on the stale socket.

The same, with the client it is for: `scripts/verify_shared_claude_e2e.py` ran two
concurrent `claude -p` sessions (Claude Code 2.1.334, model haiku) on 2026-12-02. The
result is in `docs/measurements/plugin/shared-claude.json`.

- Setup: the plugin was loaded with `--plugin-dir`, and its option set the way a person
  does it (`claude plugin configure ... --values-stdin`) in a private
  `CLAUDE_CONFIG_DIR`. Each session had its own approving Elicitation hook.
- Each session read the word on its own loopback page.
- One server and one Chrome served both, in two distinct spaces by the guard's
  attribution. Each session's two consent forms reached its own hook.
- The first run found an audit fault, fixed with it. A navigation verdict's top-level
  `space` named whichever session started the browser, because the guard runs in the
  context that session created. A verdict now keeps the space of the tab it judged.

## Guard backends

Enforcement has to see every document request before it leaves the browser. There
are two ways to stand there, chosen with `LYRA_BROWSER_GUARD` (`route` unless set);
both ask the *same* judgement (`NavigationGuard.decide`), so grants, single-use
scopes, takeover, observe mode and the audit trail behave identically. They differ in
what they can see and what they cost.

| | `route` (default) | `cdp` |
|---|---|---|
| How | Playwright's `context.route("**/*")` | A second DevTools connection: `Fetch.enable` for `Document` requests on every page and every out-of-process iframe |
| Redirect hops | Judged *after* they have left: a `context.on("request")` listener cancels the load (the request to the first refused hop still goes out; on loopback the page commits first and is blanked) | Every hop judged *before* it leaves: the destination of a refused hop sees nothing |
| HTTP cache | Off: Playwright sends `Network.setCacheDisabled(true)` with any route | On |
| etsy.com (DataDome), headful, fresh profile, N=5 | refused 5/5 | let in 5/5 |
| Service workers | `service_workers="block"` is an init script a page can step around; a navigation a worker answers is never seen | Bypassed on every guarded page (`Network.setBypassServiceWorker`) |
| Open port | none | a debugging port on `127.0.0.1`, see [below](#debugging-port) |
| Guard lost | cannot happen | the browser is killed and every call answers `guard_lost` |
| Launch | Playwright's defaults | adds `--remote-debugging-port=0`, drops `--enable-unsafe-swiftshader` |
| Dependencies | none | none: a stdlib WebSocket client (`cdp_socket.py`, ~250 lines), not the `websockets` package |

**How `cdp` guards.** Chrome is started with `--remote-debugging-port=0` next to the
pipe Playwright uses, and `cdp_guard.py` opens a second connection to it. It
auto-attaches to every page and out-of-process iframe at *browser* level with
`waitForDebuggerOnStart`, so a popup or a cross-site iframe is held until
`Fetch.enable` is in place on it (a session made through Playwright after the tab
exists cannot promise that: popups' first requests and cross-site iframe requests
escaped in the earlier probe). Each paused request becomes the two objects
`classify` reads, goes through `decide`, and is answered `Fetch.continueRequest` or
`Fetch.failRequest` with `Aborted` — never another error reason, which would show an
error page. Nothing is asked of the page while a request is
paused (its renderer does not answer then).

**Redirect hops.** Each hop is its own `Fetch.requestPaused`, judged as the
navigation it is: a 307/308 keeps method and body, a 301/302/303 turns a POST into a
body-less GET. A site you approved that answers `302` to an unapproved origin is
refused *before* the request leaves — the destination sees nothing — and the audit row
names `redirect_from`, and `navigate` answers `blocked_by_policy` with `redirected_to`. A hop that stays with the origin that issued it (the same
origin, or `http`→`https` of the same host on default ports) is not judged again: it is
the request carrying on, and asking again would strand every trailing-slash redirect on
a form.

**Uploads.** Chrome puts a navigation's whole body into the event (as text and as
base64: a 40 MB form is a 98 MB message). The transport reads such a message through
without keeping it and the guard judges the event without the body (it only asks
whether one exists). A 3, 12 and 40 MB multipart POST were refused when ungranted,
delivered when granted, and the guard stayed up.

**If the guard is lost.** Chrome releases every request it holds, and every target
waiting for the debugger, the moment the connection ends, so a lost connection is a
browser running unguarded. The session therefore kills the browser, records
`guard_lost` in the audit trail and answers every call `guard_lost` (also to readers,
and to `open_browser`) until `close_browser` acknowledges it; the next browser is a
fresh, guarded one. A socket that ends because the browser quit (a crash, the user
closing the last window) is told apart without waiting: the process is already gone, or it
is running with no open tab and leaves within 300 ms. With a tab open nothing explains the
socket, so it is killed at once. Measured (`scripts/verify_cdp_guard_e2e.py`): socket
aborted, process gone in 1–2 ms, and a hostile page posting a form every 4 ms got 0 of
them through to its server in 3 of 3 runs (waiting 300 ms first let 72 through). Requests
already in flight at that instant were released by Chrome and are not judged. A sidecar
that cannot start, or a target it cannot guard, is the same event: the window is closed
rather than left open.

**Debugging port.** `--remote-debugging-port` is an open, unauthenticated service, and
this is what `cdp` costs.

- *What it exposes.* Any process on the machine that finds the port can attach to the
  browser and do what the agent can and more: list tabs, read cookies (HttpOnly ones
  too), run script in any tab of the logged-in profile. Finding it needs no secret:
  `GET /json/version` hands out the WebSocket path. With `route` there is no port;
  Playwright drives Chrome over a pipe only it holds. Reading the profile directly would
  also give a same-user process the cookies, so the difference is mostly *other users* of
  the host and sandboxed code that has loopback but not the profile directory; on a
  one-user workstation it is small, on a shared host it is the whole profile.
- *What is done.* Random port, chosen by Chrome, bound to `127.0.0.1` only (`::1`
  refuses; measured). Chrome refuses a handshake that carries an `Origin` header (a web
  page cannot connect, 403) or a foreign `Host` (no DNS rebinding, 500). The profile
  directory is made `0700` before launch; `DevToolsActivePort` (written `0664`, and left
  behind when Chrome exits) is removed before launch and as soon as it is read. The port
  and the path are never put in an exception, a log line, an audit row or an envelope.
- *What remains.* The port exists as long as the browser does; Chrome has no way to close
  it or to require a token. A second consumer cannot use the pipe (Chrome serves one, and
  Playwright holds it); putting a proxy in front of a pipe-launched Chrome means
  launching Chrome ourselves, which this does not do. Chrome 136 and later ignore the
  flag on their *default* profile directory because the port is a cookie-theft vector
  [Chrome's own announcement, not measured here]; this server never uses that directory.
- Measured by the `exposure` section of `scripts/verify_cdp_guard_e2e.py`, which attaches
  from a separate process the way a scanner would.

**What neither backend sees.** `fetch()`/XHR (not navigations), WebSockets, GETs with the
data in the URL, speculation-rules prefetch/prerender and the navigation that activates
one (above), and `data:`/`about:`/`blob:`/`javascript:` URLs (not requests). Workers never
issue a document request and are not attached; a page's own `back_forward_cache` is off
under Playwright's switches, and history navigations are judged with the cache on.

**Choosing.** `cdp` for sites behind DataDome, where redirect chains matter, or where
a page's service worker must not answer navigations; `route` where an open loopback
port is unacceptable. Every `scripts/verify_*_e2e.py` gate runs on either:
`LYRA_BROWSER_GUARD=cdp python scripts/verify_tabs_e2e.py`.

## Installation

Developers working on this repo:

```bash
pip install -e ".[dev]"                 # dev includes playwright, for the parity gates
python -m playwright install chromium   # only needed if you have no system Chrome
lyra-browser                            # serve over stdio (the default, what an MCP client spawns)
# or: lyra-browser --http --port 8765   # serve over HTTP for dev
```

A plain `pip install lyra-browser` installs no Playwright at all: the default driver
drives the Chrome or Edge already on the machine. Add `[playwright]` only to pin one of
the Playwright drivers.

An end user needs no pip and no `playwright install` when Chrome or Edge is installed:
the server drives that browser. If neither is found, the tools answer
`browser_unavailable` so the client can prompt for an install.

**Claude Code:** the repository is a Claude Code plugin and its own marketplace.
One line installs it (Claude Code 2.1.275 or later):

```bash
claude plugin install lyra-browser --marketplace Intrect-io/lyra-browser
```

The plugin builds its own Python environment with `uv` (or `python3 -m venv`
without it) on the first session, drives your Chrome or Edge, and asks for every
site change and form send through Claude Code's own dialog. See
[docs/CLAUDE_CODE_PLUGIN.md](https://github.com/Intrect-io/lyra-browser/blob/master/docs/CLAUDE_CODE_PLUGIN.md).

**Any MCP client, through npx:** the server is Python, and a small Node launcher
(`npm/`) starts the matching PyPI release with `uv`, pinned to the dependency set in
`uv.lock`:

```bash
claude mcp add lyra -- npx -y @intrect/lyra-browser     # or "command": "npx", "args": ["-y", "@intrect/lyra-browser"]
npx -y @intrect/lyra-browser install-browser             # only if there is no Chrome or Edge
```

Needs Node 18+ and [uv](https://docs.astral.sh/uv/). Measured 2026-10-16 on Linux x86_64
(Node 24.20.0, npm 11.19.0, uv 0.11.8): the first start with empty caches answers
`initialize` in 3.6 to 8.7 s (8 runs), later starts in 1.4 to 3.4 s (29 runs); macOS and
Windows are not measured. `python scripts/verify_npx_e2e.py` reproduces it. See
[npm/README.md](https://github.com/Intrect-io/lyra-browser/blob/master/npm/README.md).

**Deploying it as a remote server (Cloudflare Containers):** see
[docs/CLOUDFLARE.md](https://github.com/Intrect-io/lyra-browser/blob/master/docs/CLOUDFLARE.md).

## Checking a setup: `lyra-browser doctor`

`lyra-browser doctor` says what a launch would use on this machine and what would stop
it, without launching a browser, importing a Playwright or writing anything (a probe
file in the data dir's nearest existing parent is created and removed). It reads the
same environment and flags as the server (`--client`, `--data-dir`, `--headless`). On
Linux over SSH (no display), 2026-11-01, asking for a window:

```text
$ lyra-browser doctor --no-headless
lyra 0.2.0 (Python 3.12.3), client generic
driver      native  (auto: native is the first in the order (native, patchright, playwright))
browser     chrome /opt/google/chrome/chrome
  chrome     /opt/google/chrome/chrome
  msedge     not found
  bundled    /home/me/.cache/ms-playwright/chromium-1208/chrome-linux64/chrome
window      headful (display no)
guard       cdp, consent auto
data dir    /home/me/.lyra-browser (writable)
profile     free
ERROR   a window is asked for (headless off) but there is no display
        fix: set LYRA_BROWSER_HEADLESS=1 (or --headless), or run under a desktop session or xvfb-run
NOT ok: a launch would fail
```

It reports the driver `auto` would pick and why (the same decision a launch makes,
`session.choose_driver`), the browser binary for each channel in the order a launch
tries them — narrowed to one when an imported profile pins its browser — the data dir
and whether it can be written, whether another lyra browser holds `profile.lock`, the
display, the guard backend, the consent channel and the imported profile. Each finding
is an `ERROR` (a launch would fail) or a `WARNING` (it works, but not as one might
expect: a held profile means an empty private one) with its fix. `--json` prints the
same as JSON with a boolean `ok`; the exit code is 0 exactly when `ok` is true. Through
npx it is `npx -y @intrect/lyra-browser doctor`; the Claude Code plugin's
`/lyra-browser:doctor` runs it too.

## Drivers

lyra drives the browser through one of three drivers, picked with `LYRA_BROWSER_DRIVER`
(the default is `auto`):

| Driver | Needs | Notes |
|---|---|---|
| `auto` (default) | Chrome, Edge or Chromium; `playwright` only if none | `native` when a browser is installed, else `patchright` when installed, else `playwright`. |
| `native` | Chrome, Edge or Chromium, nothing else | lyra's own driver (`lyra_browser.native`): the browser over raw DevTools on lyra's own WebSocket. No Playwright, no Node, no chromedriver. A plain `pip install lyra-browser` needs no browser download. |
| `patchright` / `playwright` | that package (`pip install "lyra-browser[playwright]"`) | Pins one. |

What `native` does differently, on purpose:

- **No `Runtime.enable`.** That is the one DevTools call Kasada refuses a browser on.
  Scripts run in an isolated world the page cannot see or tamper with. A script that
  reads the page's own globals (`window.CKEDITOR`) asks for the main world. The UAT
  recorder's console and page-error observers are the only thing that turns
  `Runtime.enable` on, and only for the pages they observe.
- **The sandbox stays on.** Playwright always passes `--no-sandbox`. This browser holds
  real logins, so `native` keeps Chrome's renderer sandbox unless `LYRA_BROWSER_SANDBOX`
  is off (a container without user namespaces).
- **The `cdp` guard, always.** `native` has no `context.route`. Asking for it selects
  `LYRA_BROWSER_GUARD=cdp`, which judges every redirect hop.
- **The same switches as Playwright otherwise.** The list was measured from Playwright
  1.64's launch. It keeps a shared profile's cookies readable across drivers and keeps
  the back/forward cache off, which the guard relies on.
- **The browser ends with the server.** `native` talks to Chrome over a port, but on
  Linux and macOS it also hands Chrome a `--remote-debugging-pipe` and keeps the other
  end. Nothing is sent on that pipe. When the server's process ends, however it ends, the
  pipe closes and Chrome shuts down as if closed, and its two `chrome_crashpad_handler`
  processes go with it. With the port alone, a server killed with a browser open left the
  whole browser running on the profile. That measured 15 Chrome processes and the
  crash handler, alive 5 s later. `scripts/verify_browser_e2e.py` checks both drivers after
  `close_browser` and after a server's SIGKILL: none of that browser's crash handlers are
  alive after 5 s, and none of its processes after 10 s (2026-12-02, Chrome
  157.0.8103.38, Linux; Playwright 1.65.2 already did this through its own pipe).

Status: default. Selectors are css (open shadow roots pierced), `text=`,
`role=…[name=…]` (from Chrome's accessibility tree), `xpath=`, `id=`, `data-testid=`,
`nth=`, `:visible`, `:has-text()` and `internal:control=enter-frame`; any other engine is
refused by name. `read_page(mode="tree")` matched Playwright's on 75 of 75 elements in the
same in-view order, and its refs reach into same-site and cross-site iframes
(`python scripts/verify_native_parity_e2e.py`).

**How fast a tree read is.** `native` builds the tree from Chrome's accessibility tree
(`Accessibility.getFullAXTree`). Each element's box and each link's href come from one
`DOMSnapshot.captureSnapshot` per frame, sent together with the accessibility tree. It used
to ask for them one element at a time, which meant thousands of DevTools round trips per
read on a long page.

`python scripts/measure_tree_latency.py` measures this on loopback pages of cards. Each card
has a heading, a link, a button and a field, under a bar of 50 links. It reads each page's
whole tree 7 times on each driver after a warm-up, with both browsers open and the drivers
taking turns, so host load hits both. Headless, Chrome 157.0.8103.38, 2026-12-02. Before is
`docs/measurements/tree-latency/before.json` (lyra ba2a2737d050); after is
`docs/measurements/tree-latency/after.json` (lyra 906256777d63). Median seconds:

| tree elements | before: native / Playwright | after: native / Playwright |
|---|---|---|
| 450 | 0.32 / 0.12 (2.60x) | 0.12 / 0.08 (1.53x) |
| 2,050 | 0.84 / 0.26 (3.26x) | 0.47 / 0.27 (1.77x) |
| 6,050 | 3.39 / 1.16 (2.94x) | 1.31 / 0.73 (1.80x) |

- **Compare the ratios, not the seconds across runs.** The two runs saw different host
  load: Playwright's own reads were up to twice as slow in the before run.
- **The tree a model reads did not change.** On every page, native's tree text hashes the
  same before and after: the same lines, refs and in-view order.
- **What is left is mostly Chrome's.** On the 6,050-element page the accessibility tree is a
  12 MB reply that took about 0.65 s to arrive in a profile of the same page, and the DOM snapshot about 0.1 s more.
- **Some boxes changed, towards Playwright's.** An inline element's box is now its border
  box, padding included, and a link that wraps over several lines gets its whole extent.
  Before, it got its text's quad, and for a wrapped link only the first line's. Measured on
  2026-12-02 against Playwright on the same live pages:
  - MDN's `<a>` page: all 48 changed boxes are nearer Playwright's, and 45 equal it.
  - github.com/python/cpython: all 17 equal it.
  - Wikipedia's Python article: 900 of 1,017 are nearer. Most of the rest are wrapped
    links, which Playwright measures differently again.

  No element lost or gained a ref. A box that has no layout object of its own, such as a
  `display: contents` table cell, is still measured one element at a time. So is a control
  inside a user-agent shadow root.
- **Real pages are faster too.** Wikipedia's Python article went from 1.09 s to 0.88 s and
  Hacker News from 0.46 s to 0.14 s. A loopback article of 3,000 paragraphs and few links
  took the same time (1.1 s): there, nearly all the work was always Chrome's accessibility
  tree.

The repo's own gates run on it with `LYRA_BROWSER_DRIVER=native python
scripts/verify_<gate>_e2e.py`, or with `--driver native` where a gate has that flag.
Measured 2026-10-23 on macOS with Chrome 155: 11 of 13 gates pass in full (1,855 checks),
including all 35 guard scenarios of `verify_cdp_guard_e2e.py`. `verify_tabs_e2e.py` stops
at the same headful-relaunch check the playwright driver stops at on that machine. The
rest of `verify_cdp_guard_e2e.py` reads `/proc` and runs on Linux only.

A page's own globals are not visible to `page.evaluate` on native by default, because it
evaluates in an isolated world as patchright does. Pass `world="main"` for them
(`tools/forms._main_world` picks the right keyword for each driver).

## Using your own Chrome logins

lyra's profile starts empty. Rather than logging in again inside it, a person can
bring the logins of one of their own browser profiles across, on the command line:

```bash
lyra-browser profile list                                  # profiles on this machine
lyra-browser profile import --profile "Work" --dry-run     # count what would move
lyra-browser profile import --profile "Work"               # import; run again to sync
lyra-browser profile import --profile "Work" --sites github.com,linear.app
lyra-browser profile status                                # what was last imported
```

It is a command, not a tool: the model cannot pull a profile in, because whoever
runs it decides that the agent may act as them on those sites. `--client` and
`--data-dir` pick whose lyra profile receives it, as for the server. `open_browser`
then reports `imported_from` and says, in its note, that on those sites the agent
acts as the user.
In Claude Code, `/lyra-browser:import-profile` walks through the same commands.

**The first open asks.** The first `open_browser` on an empty lyra profile (never
imported into, never asked about, no cookie file yet) lists the browser profiles on
this machine and asks the user, by MCP elicitation, whether to import one before the
window opens. The question goes to the client and the answer comes from it, so the
model neither sees the list nor answers it; the reply only carries `profile_import`
(`imported`, `skipped`, `failed` with a reason, or `unanswered`). Skip is the default,
and an accept without a choice (an approval-only client such as Hermes) is a skip.
It is not asked under the `autonomous`, `legacy` or `off` consent channels, in Claude
Code's bypass mode, from a client without elicitation, or with
`LYRA_BROWSER_FIRST_RUN_IMPORT=off`; UAT runs never ask. An answer either way is
kept in `<data_dir>/profile-first-run.json`, so it is asked once. A failed import (a
locked keyring, say) leaves the window on lyra's empty profile and is offered again
next time.

**Sync on open (opt-in).** With `LYRA_BROWSER_PROFILE_SYNC=1` (the plugin's "Sync the
imported profile" option), each `open_browser` that launches the browser compares the
imported profile's files with what the last import read (`source_stamp` in
`profile-import.json`: sizes and times of the cookie file and the storage trees) and,
when they changed, imports it again with the same browser, profile and sites. The
reply's `profile_sync` says `synced`, `unchanged`, `skipped` or `failed` (with a
reason); it never prompts, never unlocks a keyring, and a sync that cannot run leaves
the profile as it was. Like any re-import it replaces lyra's own cookies for the
sites in scope.

What moves, from `<profile>` into lyra's `profile/Default`, and nothing else:

| Component | How |
| --- | --- |
| `Cookies` | Row by row, decrypted and sealed again for lyra (below). Session cookies are left out: Chrome deletes them when it starts. |
| `Local Storage` | Whole. It is one database for every site, so a `--sites` list or `LYRA_BROWSER_DENIED_ORIGINS` leaves it out instead. |
| `IndexedDB`, `WebStorage` | Per origin / per storage bucket, filtered by site. |

Saved passwords (`Login Data`), extensions, history and `Preferences` (absolute
paths, account tokens) are never copied. `LYRA_BROWSER_DENIED_ORIGINS` is applied at
import too: a refused site's cookies stay behind, and so does a domain cookie that
would be sent to it.

**Sync means replace.** Re-running the import replaces lyra's cookies for the sites
in scope (every site without `--sites`) and the other components with the source's,
so whatever lyra's own sessions stored there is overwritten; cookies for other sites
stay. The import takes `<data_dir>/profile.lock` and refuses while a lyra browser
holds it (`close_browser` first). It stages everything beside the profile and swaps
each component in, so a failed import leaves the old profile as it was.

**The source is read-only and may be running.** SQLite files are read through the
backup API; LevelDB directories are copied file by file (without `LOCK`) and copied
again if they changed meanwhile, so a running browser's last few writes may be
missing.

**Cookie encryption (Linux).** Both drivers launch Chrome with
`--password-store=basic` (the `native` driver copies Playwright's switches), so lyra's
cookies are sealed `v10`, with Chrome's fixed key.
A Chrome that found a desktop keyring seals them `v11`, with a secret in that
keyring; copied as they are they would never open in lyra. The import fetches that
secret from the Secret Service (D-Bus), opens each cookie and seals it again as
`v10`. Whether it decrypted is checked, not assumed: since cookie schema 24 each
plaintext starts with the SHA-256 of its domain. A cookie that does not open is
counted and left out. When the cookies are `v11` and the login keyring is locked
(a session over SSH, say), the import refuses rather than bringing the storage
without the cookies; `--unlock-keyring` lets the keyring prompt for its own password
on the desktop (it gives up after 120 s when no prompt can be shown). lyra never asks
for or sees that password. macOS (Keychain) and
Windows (DPAPI, app-bound `v20`) cookies are not decrypted yet; they are reported as
undecryptable (the import reads `Network/Cookies` where those platforms keep the file).

**Which Chrome opens it.** Chrome migrates a profile forward only, so after an import
from Chrome (or Edge, or Chrome Beta) lyra launches that browser and no fallback; an
explicit `LYRA_BROWSER_CHANNEL` still wins. The import refuses when lyra's cookie
database has a different schema from the source's.

Measured 2026-10-28 on Linux (Chrome 154.0.8037.57, Playwright 1.63.0, cookie schema
24): `scripts/verify_profile_import_e2e.py` runs a real Chrome as the source, once
with `v10` and once with `v11` cookies (a throwaway gnome-keyring on a private D-Bus
session), imports, and checks that lyra's page is sent the cookie and reads
localStorage and IndexedDB back, that a re-import brings a new login and keeps cookies
outside `--sites`, and that the source's files did not change (26 checks, one run).
Re-run 2026-11-01 on both drivers (Chrome 154, `LYRA_BROWSER_DRIVER=native` and
`=playwright` with Playwright 1.63.0), now also checking that the named driver is the
one that ran: 66 checks each, all passed.
`scripts/measure_profile_import.py` imports a real profile into a throwaway data dir and
compares what lyra's Chrome holds (CDP `Storage.getCookies`, on `about:blank`) with what
was imported: on one `v10` profile, 25 cookies in the source, 4 session-only, 21
imported, 14 unexpired, and Chrome reported those 14 with the same names and values.
Three real `v11` profiles on the same machine (118 to 144 cookies) were not measured:
their keyring was locked over SSH, and the import refused them as described above. The
`v11` path is measured by the gate only, with cookies a real Chrome sealed through a
throwaway keyring.

## Configuration (env)

| Var | Default | Meaning |
|---|---|---|
| `LYRA_BROWSER_CLIENT` | detected | `generic`, `hermes`, `remote` or `claude-code` (also `--client`). Picks default paths, window mode and how captures reach the model — never permissions. `remote` is a server nobody sits at: headless, and `screenshot`/`read_image` attach the PNG as an MCP image. `claude-code` is the Claude Code plugin: a window where one can open, the same attached image, data beside `generic`'s. Detected from `HERMES_HOME` → hermes; otherwise `generic` (`claude-code` is never detected: the plugin passes the flag). |
| `LYRA_BROWSER_DATA_DIR` | — | Base data dir (profile + audit). Overrides everything. |
| `HERMES_HOME` | `~/.hermes` | hermes: data goes to `$HERMES_HOME/browser`. |
| `LYRA_BROWSER_HEADLESS` | auto | Run without a visible window (see Headless mode). Unset: headless for hermes and remote, and on Linux with no `DISPLAY`/`WAYLAND_DISPLAY` unless a persistent VNC display is up (see below); otherwise a window. |
| `LYRA_BROWSER_DISPLAY` | unset | X display the window opens on instead of the inherited one, e.g. `:98`. Unset: the persistent VNC display that `lyra-browser vnc install` keeps up, for `generic` and `claude-code` on a Linux host with no display of its own, while its X socket exists. |
| `LYRA_BROWSER_VNC_DIR` | `~/.config/lyra-browser/vnc` | Where `vnc install` keeps its sidecar (`vnc.json`) and password file. Host-wide, not per client. |
| `LYRA_BROWSER_VIEWPORT` | `1280x800` | `WIDTHxHEIGHT` of the page (`390x844` for a phone layout). Headless uses it as the emulated viewport; headful as the window size. Anything unreadable falls back to the default. |
| `LYRA_BROWSER_PROXY` | unset | Route the browser through a proxy, e.g. `socks5://100.x.y.z:1080`. For UAT runs that must not share the operator's egress IP, since per-IP rate limits, quotas and IP-based analytics exclusion all key on it. Unset means a direct connection. |
| `LYRA_BROWSER_REQUIRE_APPROVAL` | `true` | Ask before risky actions. `false` sets the consent channel to `off`. |
| `LYRA_BROWSER_CONSENT_CHANNEL` | `auto` | `auto` asks the user over MCP and falls back to `confirm=true` only on a client that cannot be asked; `elicit` pins asking and denies otherwise; `legacy` always takes the model's word; `off` does not ask; `autonomous` approves what an unattended run needs, except what `DENIED_ORIGINS` names (see Permissions). |
| `LYRA_BROWSER_ENFORCEMENT` | `enforce` | `observe` records what it would have blocked without blocking: navigations go through, and an undeclared download is saved (`observed: true`, audited `would_block`) instead of cancelled. |
| `LYRA_BROWSER_GRANT_TTL` | `600` | Seconds a grant stays usable. Single-use ones ignore this. |
| `LYRA_BROWSER_TRUSTED_ORIGINS` | — | Sites pre-approved for `NAVIGATE`/`INTERACT`, comma- or whitespace-separated: `https://host[:port]`, a bare `host` (https only), or `*.example.com` (https subdomains, not the apex). Never covers `SUBMIT`/`UPLOAD`/`PUBLISH`/`DOWNLOAD`. See Trusted origins. |
| `LYRA_BROWSER_TRUSTED_SEND_ORIGINS` | — | Sites where *sending* is also pre-approved — `SUBMIT` and `UPLOAD` — for acceptance runs against your own product. Same entry forms, **separate list**: a site in `TRUSTED_ORIGINS` is not send-trusted by being there. Never `PUBLISH` or `DOWNLOAD`; each approval stays single-use, and it steps aside during a takeover. Audited as `consent_channel=trusted_send`. |
| `LYRA_BROWSER_FOLLOW_BYPASS` | on | Claude Code client only: while Claude Code runs in bypassPermissions mode, consent requests are answered without a dialog (`consent_channel=bypass`). The mode arrives from the plugin's PreToolUse hook, never from the model; see docs/CLAUDE_CODE_PLUGIN.md (Bypass mode). |
| `LYRA_BROWSER_DENIED_ORIGINS` | — | Sites refused whatever else says yes: the trusted lists, a live grant, the `autonomous` channel and the user's turn all step aside. Same entry forms, matched on the host: `http://`, another port (unless the entry names one) and a trailing-dot spelling are refused too. The guard applies it to every navigation (a page's own, a form posting there, an iframe's document) and to downloads. |
| `LYRA_BROWSER_CHALLENGE_MAX_ATTEMPTS` | `3` | How many times the same bot check (vendor at a site) may stop `navigate` before it answers `challenge_abandoned`. |
| `LYRA_BROWSER_CAPTCHA_SOLVER` | — | `module:function` of a solver an interactive bot check is handed to when nobody is watching. None is shipped; see [Bot checks](#bot-checks-challenge). |
| `LYRA_BROWSER_CONSENT_TIMEOUT` | `300` | Seconds a prompt waits for an answer before it counts as a denial (`timed out waiting for the user`). The tool call is held that long, so for an unattended Hermes gateway set it lower — e.g. `60`. |
| `LYRA_BROWSER_RELEASE_GRACE` | `2` | Seconds before a finished action's unused single-use scope is reclaimed. |
| `LYRA_BROWSER_STEPS_REPLY` | `compact` | `full`: `run_steps` lists every step's whole reply instead of the brief form. See `run_steps`. |
| `LYRA_BROWSER_SHARED` | off | On (or `lyra-browser --shared`): a stdio server becomes a proxy to one per-user server (spaces on) that every session of the same data dir shares, started if absent. See Spaces, "Several stdio sessions". |
| `LYRA_BROWSER_SHARED_IDLE` | `60` | Seconds the shared server stays up after its last session has gone. |
| `LYRA_BROWSER_SPACES` | off | On: serve several MCP sessions at once, each in its own space (tabs, grants, hand-off, window) of the one browser; takes the `cdp` guard. See Spaces. |
| `LYRA_BROWSER_OWNER_IDLE_TIMEOUT` | `900` | Seconds a session may hold the browser quiet: no call in flight and no window with the person (a takeover or an `ask_user_to_do` turn), counted from the end of its last call. Handing it on closes the window. |
| `LYRA_BROWSER_CAPTURE_DIR` | — | Where `screenshot`/`read_image` write PNGs. Default: hermes `$HERMES_HOME/cache/browser` (where Hermes' vision may read), else `<data_dir>/captures`. |
| `LYRA_BROWSER_CAPTURE_KEEP` | `200` | Captures kept on disk; oldest are deleted first. `0` keeps all. |
| `LYRA_BROWSER_CAPTURE_MAX_EDGE` | `1568` | Captures longer than this on either edge are downscaled; `scale` in the reply says by how much. `0` keeps full size. |
| `LYRA_BROWSER_EVIDENCE` | on | Action replies carry `visual_change` (see Seeing the page). `off` skips the two thumbnails per action. |
| `LYRA_BROWSER_CAPTURE_SETTLE_MS` | `1000` | How long a `screenshot` first waits for the page to stop changing on screen. `0` captures at once. |
| `LYRA_BROWSER_CURSOR` | on | The virtual cursor (see Seeing the page): a pointer drawn with the DevTools overlay that travels to each click, hover, typed field and picked option, the real mouse moving along the same path. `off` removes both. |
| `LYRA_BROWSER_CURSOR_MS` | `300` | How long the cursor takes to travel to a target. |
| `LYRA_BROWSER_FIRST_RUN_IMPORT` | on | The first `open_browser` on an empty profile offers the user's own browser profiles to import, by elicitation (see Using your own Chrome logins). `off` never asks. |
| `LYRA_BROWSER_PROFILE_SYNC` | off | `1`: each launch re-imports the imported profile when its files changed since the last import. |
| `LYRA_BROWSER_DOWNLOAD_DIR` | — | Where declared downloads are saved. Default `<data_dir>/downloads`. |
| `LYRA_BROWSER_DOWNLOAD_KEEP` | `200` | Saved downloads kept; oldest are deleted first, and only files this server saved (tracked in a ledger in the dir). `0` keeps all. |
| `LYRA_BROWSER_DOWNLOAD_MAX_BYTES` | `209715200` | Largest file a download may be (200 MiB); a bigger one is cancelled and answered `download_failed` (`too_large`). |
| `LYRA_BROWSER_DOWNLOAD_TIMEOUT` | `120` | Seconds a declared download may take to arrive once it has started before it is cancelled (`download_failed`, `timeout`). |
| `LYRA_BROWSER_CHANNEL` | — | Force one channel (`chrome`/`msedge`). Unset = try chrome→msedge→bundled. |
| `LYRA_BROWSER_ALLOW_BUNDLED` | `true` | Allow bundled-Chromium fallback (only exists after `playwright install`). |
| `LYRA_BROWSER_AUDIT_STDERR` | `false` | Also write every audit record to stderr as one JSON line. For a host whose disk is ephemeral but whose stderr is collected (the Cloudflare image sets it). |
| `LYRA_BROWSER_DRIVER` | `auto` | Which driver launches the browser: `auto` takes `native` when Chrome/Edge/Chromium is installed, else `patchright`, else `playwright`; any name pins it. `native` drives an installed Chrome over raw DevTools with no Playwright at all, always with the `cdp` guard, the sandbox on and no `Runtime.enable`. Selectors cover css (open shadow roots pierced), `text=`, `role=…[name=…]`, `xpath=`, `nth=`, `:visible` and `:has-text()`; `read_page(mode="tree")` comes from Chrome's accessibility tree in Playwright's format, and its refs reach into same-site and cross-site iframes. `open_browser` reports the one in use as `driver`. |
| `LYRA_BROWSER_SANDBOX` | on | `native` driver only: Chrome's renderer sandbox. Playwright always launches with `--no-sandbox`; the native driver keeps the sandbox unless this is off (a container without user namespaces). |
| `LYRA_BROWSER_GUARD` | `route` | Where the navigation guard stands: `route` (Playwright's route) or `cdp` (a second DevTools connection: every redirect hop judged, cache on, DataDome lets the browser in, a loopback debugging port, `guard_lost` if the guard fails). See Guard backends. |
| `LYRA_UAT_CLAUDE_BIN` | `claude` on `PATH` | The Claude Code executable the `claude-code` UAT brain runs. See UAT mode. |
| `LYRA_UAT_CODEX_BIN` | `codex` on `PATH` | The Codex executable the `codex` UAT brain runs. See UAT mode. |

## UAT mode

`lyra-uat` plays a *persona* — who is visiting, from where, in what language, with what goal and how many steps — against a site, through the tools above, and writes `report.json`. The model that plays it is replaceable: Claude Code, Codex, the Anthropic API, OpenRouter, Ollama Cloud, or any OpenAI-compatible endpoint. What makes a run trustworthy is not: **the server, not the model, keeps the trace**. Whichever brain drives, every tool call is recorded as it happens, the step budget is enforced, a screenshot is taken after each action, a `type_text` value that looks like a payment-card number is refused, an upload outside the persona's directory is refused, and leaving the sites under test cannot be approved by the model's own `confirm=true`.

```bash
pip install -e ".[uat]"
lyra-uat demo-site --port 8787 &             # a small site with things to find
lyra-uat run examples/uat/demo/run.yaml      # one persona, Claude Code plays it
lyra-uat batch examples/uat/demo/batch.yaml  # two personas in parallel, one process each
```

A run leaves a directory: `report.json` (and `report.md`), `trace.jsonl`, `events.jsonl`, `captures/`, `network.jsonl`, `console.jsonl`, and the browser's own `audit.jsonl`. Persona, target, brain, hooks and limits are YAML or JSON; `lyra-uat schema run|batch|report|export` prints the JSON Schemas. Spec `asserts` judge the final page without the model; `lyra-uat export` writes a versioned record for a benchmark and `lyra-uat replay` re-runs a run's own calls to check the judgement holds. A run that should act without anyone to ask sets `target.policy: autonomous`; the default is `closed`, which keeps the run on its trusted sites. Details, the report format and each brain's requirements are in [docs/UAT.md](https://github.com/Intrect-io/lyra-browser/blob/master/docs/UAT.md).

## Headless mode

```bash
lyra-browser --headless      # or LYRA_BROWSER_HEADLESS=true; the flag wins
lyra-browser --no-headless   # force a window even if the env says otherwise
```

Unset, the mode follows the client and the host: `--client hermes` is headless
(Hermes reaches the user over chat and gives its servers no display), and so is
any Linux process with neither `DISPLAY` nor `WAYLAND_DISPLAY` — launching a
window there would crash, headless is a working session that says so — unless
the host keeps a persistent VNC display (next section).

### A persistent VNC display for a host with no screen

On a server you reach over SSH, lyra would otherwise always be headless. One
command keeps a display up that you watch from a VNC viewer:

```bash
lyra-browser vnc install                          # :98, 127.0.0.1:5902, 1920x1080x24
lyra-browser vnc install --listen 100.64.0.10     # e.g. a Tailscale or WireGuard address
lyra-browser vnc status                           # units, X socket, does RFB answer
lyra-browser vnc password                         # print the password again
lyra-browser vnc reset-password [--stdin]         # the only thing that changes it
lyra-browser vnc uninstall                        # stop, remove the units, keep the password
```

`install` writes two systemd user units — `lyra-xvfb.service` (`Xvfb :98
-nolisten tcp`) and `lyra-x11vnc.service`, bound to it, waiting for its X socket
before it starts, and restarted with it — enables and starts them, and records
display, port and listen address in `~/.config/lyra-browser/vnc/vnc.json`. The
password is generated once (8 characters, the most VNC authentication uses), shown
once, and kept at mode 0600 in `passwd` next to it; re-running `install` with other
flags keeps it. x11vnc reads it with `-passwdfile read:`, so it is never on a command
line and a reset applies to the next viewer without a restart. Without lingering
(`loginctl enable-linger $USER`) the units stop when you log out; `install` warns.

The server never starts or stops these units. A `generic` or `claude-code` server
with no display of its own opens its window there whenever the X socket exists —
headful, `attended=true` — and `open_browser` answers with `watch: {"vnc":
"<listen>:<port>", "display": ":98"}` and a note for the agent to give the user that
address. The password never reaches the model. Each launch judges the display again:
if the X server is gone, the session opens headless and `open_browser` adds
`display_lost`. Hermes and `remote` stay headless, and an inherited `DISPLAY` (a
desktop someone is looking at) always wins.

RFB is unencrypted and the password is short: the default listen address is
loopback (reach it with `ssh -L 5902:127.0.0.1:5902 host`), and a private-network
address is the alternative. Never listen on `0.0.0.0` on a network you do not trust.
Measured by `scripts/verify_vnc_e2e.py` (2026-11-03, Xvfb 21.1.12, x11vnc 0.9.16,
Google Chrome 154.0.8037.57; one full pass each with the `native` driver and with
Playwright 1.63.0, `--driver`): with `DISPLAY` and
`WAYLAND_DISPLAY` removed, `open_browser` reports `attended=true` and the address; a
real RFB client refuses a wrong password, and with the stored one sees the loaded page
on the framebuffer. With the X server killed (its socket left behind, so only Chrome's
"Missing X server" tells) and with it stopped cleanly, the next launch is headless with
`display_lost` rather than an error.

Headless does not merely hide the window — it means **nobody is watching**. The
collaboration tools have no human to reach, so they refuse with an `unattended`
envelope instead of reporting success for something no one will see:

| Tool | Headless behaviour |
|---|---|
| `highlight_element` | `unattended` — an outline nobody sees is not a signal |
| `ask_user_to_do` | `unattended` — there is no user at this window to ask |
| `request_takeover` | `unattended`, **and control is not handed over** — granting a takeover no human can release would block every later mutation |

Headless Chrome also announces itself: its UA says `HeadlessChrome`, and
Cloudflare's managed challenge refuses on that token alone (13 of 34 login
pages in the earlier survey). The session therefore sends the UA the same
binary would send with a window — the real version, the real platform, only
that token dropped — so `navigator.userAgentData` and the `Sec-CH-UA-*` headers
stay the browser's own. The version is read from the running Chrome on the
first headless launch and remembered in `<data_dir>/browser-ua.json`; that
first launch, and the one after each Chrome update, relaunch once (about 0.7s).

Navigation, interaction, and reading are unaffected. `open_browser` reports which
mode you are in via its `attended` field so the agent never assumes an audience.

## Looking like the user's Chrome

Sites that sort agents from people check the launch, not the behaviour. The
session is launched the way Playwright's own MCP server launches — with
`--disable-blink-features=AutomationControlled`, so `navigator.webdriver` is
`false` as in any Chrome a person opens, and without an emulated viewport in
headful mode, so the page sees the real screen instead of a window larger than
the screen it is on. Measured on 42 login pages behind Cloudflare, Akamai,
DataDome, PerimeterX and Kasada: of the 34 plain Chrome passes,
the Playwright defaults failed 6 headful and 19 headless; with these settings
the count is in the survey comment, per site.

What is deliberately *not* done: the `--enable-automation` infobar stays (it is
how a person at the shared window is told what is happening), and nothing is
forged — no WebGL or canvas noise, no patched CDP. Route interception and the
service-worker block contribute nothing to the Cloudflare and Akamai refusals; for
DataDome the route does matter, which is why the `cdp` guard backend exists.

Two vendors still refuse, and the cause of each is measured rather than guessed:

- **Kasada** (hyatt.com) notices one CDP call, `Runtime.enable`. Plain Chrome
  driven over raw CDP passes; the same Chrome with `Runtime.enable` on is
  refused; every other call Playwright makes on attach is fine. Playwright
  enables it on every page and has no switch not to. [patchright](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright-python)
  is a drop-in fork that does not send it and evaluates in an isolated world
  instead; with `pip install "lyra-browser[patchright]"` the session launches
  through it (`LYRA_BROWSER_DRIVER=auto`), and hyatt passes in both modes.
  What patchright changes for this server: `page.evaluate` runs outside the
  page's own JavaScript world (our evaluate calls only touch the DOM, which is
  shared) and console messages are not delivered (we read none).
- **DataDome** (etsy.com; tripadvisor.com does not discriminate in the
  measurements) refuses on either of two causes, each sufficient on its own
  (N=5–6 per cell, headful, one IP):
  `context.route` switches the HTTP cache off, so every document request carries
  `Cache-Control`/`Pragma: no-cache` (plain Chrome with only
  `Network.setCacheDisabled` is refused 0/6, while raw CDP `Fetch.enable` on
  documents or on all requests is fine), and on a GPU-less host
  `--enable-unsafe-swiftshader` gives the page a WebGL that plain Chrome lacks.
  The `cdp` guard backend removes both: no route, documents only over a second
  connection, and the switch dropped. Measured on that backend with the product itself
  (`scripts/measure_compat.py`, headful, fresh profile per visit, 12 s apart, N=5):
  **etsy.com let in 5/5 against 0/5 for the `route` launch; hyatt.com (patchright) 5/5
  against 4/5** (the one miss was a 429). Dropping the switch removes WebGL on a host with
  no GPU, as in plain Chrome there; on a host with a GPU it is inert [INFERENCE: no GPU
  host here]. Headless is undecidable on the measuring host.

## Development

```bash
ruff check .       # lint
pre-commit install # enable hooks
```

Real-browser gates live in `scripts/verify_*_e2e.py`, for
example `python scripts/verify_browser_e2e.py --headless-only`, or headful under
`xvfb-run -a`. `.github/workflows/browser-gates.yml` runs twenty-two of them nightly
(and on demand) for both drivers, on ubuntu with Xvfb; a red nightly run is the signal
that a driver change regressed something the fake-page unit suite cannot see. On the
native row it also runs `verify_native_parity_e2e.py` and keeps a tree-read timing record
(`scripts/measure_tree_latency.py`, `tree-latency.json` in the run's evidence; a hosted
runner's timing is a record, not a gate). `verify_shared_e2e.py` stays local: it needs
a per-user runtime directory a hosted runner does not promise.
`python scripts/verify_vnc_e2e.py` is the persistent-display gate: its own Xvfb and
x11vnc on a free display and loopback port, never the host's install.

- **CDP guard gate** — `python scripts/verify_cdp_guard_e2e.py` (both modes, `--driver`)
  re-runs the browser, script-redirect and tabs gates on the `cdp` backend, then checks
  what only it can do: redirect hops (301/302/303/307/308, with and without a body), popups
  at N=10, out-of-process iframes, service workers, large uploads, kill-the-socket
  fail-closed, a sidecar that cannot start, and what another local process can do with the
  debugging port. `scripts/measure_compat.py` is the etsy/hyatt measurement above.

- **What a turn carries** — `python scripts/measure_context.py [--json PATH]` measures
  lyra's tool list as each client receives it. It connects an in-memory MCP client, so
  middleware such as claude-code's `consent_override` is counted. It also measures the
  server instructions, and the same for lyra-uat's default tool set and its persona
  system prompt. It uses a temporary data dir and starts no browser.
  `docs/measurements/context/before.json` was taken on 2026-12-01 (UTC) at lyra
  3f88ec6497fb:

  | client | tool list (chars) | of which description text |
  |---|---|---|
  | generic, hermes, remote | 48,675 | 32,858 (68%) |
  | claude-code | 59,041 | 41,066 (70%) |
  | lyra-uat default set | 34,392 | 23,784 (69%) |

  The tool descriptions now state each tool's contract and nothing more. What a model
  must keep is pinned by `tests/test_tool_contracts.py`, together with the budget:
  description text at most 40% of the above, the whole list at most 60%. The long-form
  guidance moved to this README and the plugin's skill. The budget is for the tools
  `before.json` knew. A tool added since is held on its own: at most 1,100 characters as
  JSON and 400 of description text, on every client. The task tools (`drag`,
  `evaluate_readonly`, `read_download`, `save_deliverable`, `set_emulation`) add 3,341
  characters to the generic list (2026-12-02), 574 to 896 each.
  `docs/measurements/context/after.json` (2026-12-02):

  | client | tool list (chars) | of which description text |
  |---|---|---|
  | generic, hermes, remote | 28,080 (58%) | 12,263 (37%) |
  | claude-code | 32,518 (55%) | 14,543 (35%) |
  | lyra-uat default set | 18,988 (55%) | 8,380 (35%) |

  At ~4 characters a token that would be about 5.1k fewer tokens per turn for a client
  that sends every schema with each request as a generic client, and 6.6k as claude-code
  with tool search off. The estimate runs low for JSON schemas: a one-turn `claude -p`
  probe measured 22.8k -> 15.1k input tokens for the generic client, 7.7k fewer (see
  "Shorter tool descriptions, side by side").

  The lyra-uat persona system prompt is another 5,298 characters. A client that sends
  every schema with every request pays for the whole list on every turn: Hermes, a
  generic MCP client, Claude Code with tool search off, and lyra-uat's claude-code
  brain, whose `--tools ""` leaves Claude Code no tool search. What the cut did to a
  model's success and tokens is measured in `haiku-r5-docs-lean.json` (see "Shorter tool
  descriptions, side by side").

- **Real-sites gate** — `python scripts/verify_realsites.py` (needs the internet) visits ten
  live sites and a loopback control, reads each as a tree and as text, clicks its first
  internal link through the `aria-ref=` the tree printed, and compares judged and blocked
  navigations and page sizes with `scripts/realsites_baseline.json` (±10% plus a small
  slack; success must match exactly). A site that cannot be reached is `SKIP`, and the gate
  fails only when fewer than eight ran. It runs against live sites, so a site editing its
  header can turn it red with no code change: treat it as a report to read, not a merge
  gate (the loopback `verify_*_e2e.py` gates are the blocking ones). `--update-baseline` re-records it, `--sites a,b` and
  `--retries N` narrow and steady a run, `--driver patchright` and `--headful` pick the
  driver and the window.

## Status

The server, session manager, tools, permission layer, enforcement, bot-check
detection and audit are implemented, unit-tested (no browser needed) and exercised
end-to-end against real sites with a real Chrome — ten rounds over eleven sites, 187
judged navigations. Driven by a live MCP client that implements elicitation since
2026-10-15: as a Claude Code plugin (`docs/CLAUDE_CODE_PLUGIN.md`), a `claude -p`
session's `Elicitation` hook approved a navigation and a cancelled form denied one,
both audited as `consent_channel=elicit`/`denied` with no `confirm` fallback
(Claude Code 2.1.300, `scripts/verify_claude_plugin_e2e.py`).

## License

MIT

TDQS

B3.4/5.0

Scored across 29 tools

Disambiguation4/5

Most tools have clearly distinct purposes within a browser-automation domain. Some potential for confusion exists between read_page (text/tree reading) and read_form (form field listing), or between navigate/go_back/reload_page. However, the detailed descriptions strongly clarify when to use each, keeping overlap manageable.

Naming Consistency3/5

Mix of verb_noun (open_browser, close_browser, read_page, read_form, read_image) and verb-only (click, type_text, navigate, scroll, hover) patterns. The conventions are still readable and the verbs are clear, but there is no single predictable pattern across all 29 tools.

Tool Count2/5

29 tools is at the high end for a browser automation server, especially since many are fine-grained actions (click, type_text, press_key, hover, scroll) that could be combined into a more general 'interact' tool. The count feels heavy for the domain, though each tool does have a specific role.

Completeness4/5

Covers a wide range of browser automation needs: navigation, reading, interaction, downloads, forms, tabs, dialogs, and session control. A few gaps remain (e.g., no explicit tool for executing JavaScript or managing cookies/local storage, no direct window resizing), but these are minor for most agent workflows.

Maintenance

ActivityActive
ResponsivenessLimited data