# Browser automation

> What the browser tools let the agent do, the difference between zelk's own browser and yours, how tabs earn trust, how browser calls are decided, and what the log keeps.

An agent that can drive a browser can check a web app it just built, read a
page that has no API, or fill in a form for you. zelk gives it two browsers.
One is a Chrome that zelk starts for itself, with an empty profile, and
throws away. The other is yours, signed in as you, and zelk reaches only the
tabs you let it. The second is where the care goes: a signed-in browser holds
your accounts, and a page can try to talk the model into spending them.

The scenes below play it. zelk's own browser is on the left and yours on the
right. The bar above them is the call the model makes and how permission
decided it. In your browser, the tabs in the Ion outline are the only ones
the agent can touch.

Each scene shows zelk’s own browser and your browser side by side. The calls the model makes, how each is decided, and what zelk records:

- **Its own browser**. zelk’s own browser is a Chrome of its own. It starts on the first call with an empty profile, so no login of yours is in it. Its calls are decided like any tool’s: a read runs, and a rule can let a site’s calls run.
   Setup: Started with -browser. zelk’s own browser isn’t running yet, and nothing of yours is in reach: your browser is there, and zelk can’t see it. (a person attends · allow browser_*(domain:localhost))
   1. `browser_open localhost:3000/signup` runs (step 5): The allow rule browser_*(domain:localhost) matches, so it runs.
   2. `browser_snapshot` runs (step 5): It only reads, and read-only calls run without asking.
   3. `browser_click @e2` runs (step 5): The allow rule browser_*(domain:localhost) matches, so it runs.
   The session’s log:
   - `effect_started` run_tool browser_open localhost:3000/signup
   - `effect_finished` browser_open localhost:3000/signup → ok: a tab on localhost
   - `effect_started` run_tool browser_snapshot
   - `effect_finished` browser_snapshot → ok: the page as an outline, fenced as untrusted data
   - `effect_started` run_tool browser_click @e2
   - `effect_finished` browser_click @e2 → ok
- **A tab you trusted**. A tab you trusted is worked in without asking. Sharing a tab was your decision, so while you attend, a call in it doesn’t ask again. The trust follows the tab: it holds after the tab leaves the shop for another site.
   Setup: You shared the shop tab with zelk, so it is in the zelk tab group. Your mail and bank tabs are not. (a person attends · no allow rules)
   1. `user_browser_snapshot` runs (step 5): It only reads, and read-only calls run without asking.
   2. `user_browser_click @e3` runs (step 5): It acts in a tab you trusted, and you are attending, so it runs without asking.
   3. `user_browser_click @e5` runs (step 5): It acts in a tab you trusted, and you are attending, so it runs without asking.
   The session’s log:
   - `effect_started` run_tool user_browser_snapshot
   - `effect_finished` user_browser_snapshot → ok: the page as an outline, fenced as untrusted data
   - `effect_started` run_tool user_browser_click @e3
   - `effect_finished` user_browser_click @e3 → ok
   - `effect_started` run_tool user_browser_click @e5
   - `effect_finished` user_browser_click @e5 → ok
- **Tabs outside the group**. Only the group is visible. Tabs outside it aren’t attached or listed, so the agent can’t name them. The one thing that asks is opening a new tab, and your yes is what puts it in the group.
   Setup: Your mail and bank tabs are open too. They aren’t in the zelk group. (a person attends · no allow rules)
   1. `user_browser_tabs list` runs (step 5): It only reads, and read-only calls run without asking.
   2. `user_browser_open new_tab tracker.example.com/issues` asks you, and you allow (step 6): No rule allows it, and a call that opens a tab isn’t in a trusted one yet, so it asks you.
   The session’s log:
   - `effect_started` run_tool user_browser_tabs list
   - `effect_finished` user_browser_tabs list → ok: 1 tab: shop.example.com
   - `effect_started` await_input: approve user_browser_open
   - `command_accepted` answer: allow
   - `effect_started` run_tool user_browser_open new_tab tracker.example.com/issues
   - `effect_finished` user_browser_open new_tab tracker.example.com/issues → ok: a tab in the zelk group on tracker.example.com
- **No one attending**. With no one attending, a call that acts needs a rule or a hook. A trusted tab counts only while a person is there to have trusted it. A run no one watches acts only where a rule or a hook allows it; reading a tab still works.
   Setup: A scheduled run, with no one at the keyboard. You wrote one rule: user_browser_* may act on shop.example.com. Both tabs are in the group. (no one attends · allow user_browser_*(domain:shop.example.com))
   1. `user_browser_click @e3` runs (step 5): The allow rule user_browser_*(domain:shop.example.com) matches, so it runs.
   2. `user_browser_click @e7` is refused (step 6): No rule allows it. A trusted tab counts only while a person attends, and no one can be asked, so it is refused.
   The session’s log:
   - `effect_started` run_tool user_browser_click @e3
   - `effect_finished` user_browser_click @e3 → ok
   - `permission_decided` deny: no rule allows it, and no human can be asked
- **A page gives orders**. Page text is data, and some doors don’t open for it. Suppose the model obeys the page. A new tab asks you, and typing a password is refused in code. A click in the trusted tab would not have asked: that is what trusting a tab means.
   Setup: The shop page has been written to steer an agent. It carries a line that talks to the model, and a password field. (a person attends · no allow rules)
   1. `user_browser_snapshot` runs (step 5): It only reads, and read-only calls run without asking.
   2. `user_browser_open new_tab bank.example.com/accounts` asks you, and you deny (step 6): No rule allows it, and a call that opens a tab isn’t in a trusted one yet, so it asks you.
   3. `user_browser_fill @e9` runs (step 5): It acts in a tab you trusted, and you are attending, so it runs without asking. The driver then refuses it.
   The session’s log:
   - `effect_started` run_tool user_browser_snapshot
   - `effect_finished` user_browser_snapshot → ok: the page as an outline, fenced as untrusted data
   - `effect_started` await_input: approve user_browser_open
   - `command_accepted` answer: deny
   - `permission_decided` deny: the person denied it
   - `effect_started` run_tool user_browser_fill @e9
   - `effect_finished` user_browser_fill @e9 → error: it is a password field. Hand the tab to the user to type it

## What the tools let the model do

The tools are named `browser_*` for zelk's own browser and `user_browser_*`
for yours, about thirty of each. The model works in a loop: **snapshot**, act,
snapshot again. A snapshot is the page as an outline built from Chrome's
accessibility tree, one line per element, with a short **ref** on each one
that can be acted on:

```text
@e12 button "Save" disabled
```

A ref names that element until the page navigates. `browser_click`,
`browser_fill`, `browser_press` and the rest take a ref, and the input they
send is real input at the element's centre, not a script poking the page.

Eleven tools are always offered: open, snapshot, click, fill, press, wait,
screenshot, console, network, tabs and evaluate. The rest are found through
`ToolSearch` when needed: device emulation, accessibility audits,
recordings, request mocking, traces and more. The agent can open the app it
is building, click through it, read the console and the network log, and
check its own change, without you pasting any of it in.

Tools that only read, such as snapshot, screenshot, console and network,
are marked read-only and run without asking in every mode that grants reads.
Tools that act go through permission.

## Two browsers

| | zelk's own browser | Your browser |
| --- | --- | --- |
| Tools | `browser_*` | `user_browser_*` |
| Process | zelk starts it and ends it | yours; zelk never starts or closes it |
| Profile | empty, new each session, deleted after | yours, with every login |
| Reached by | pipes to a Chrome zelk runs | zelk's extension in your Chrome, Brave or Edge |
| Tabs | all of its own | only the tabs in zelk's tab group |
| Sandbox and network | the session's, as a command's | none: it is you, on your network |
| Who else acts | nobody | you, at the same time |

A rule for one never applies to the other: `browser_*(domain:localhost)`
can't spend a real account, because it doesn't name `user_browser_*`.

zelk's own browser is set up once with `zelk browser setup`, which installs a
pinned Chrome for Testing only if its checksum matches. Under a sandbox it
runs inside it, on the session's network, so with the network off on Linux or
macOS it reaches your dev server only through a port you name with
`-browser-local` (under `mxc` on Windows, host loopback stays closed).
Your browser needs zelk's extension and a one-time pairing
([the browser guide](/cli/browser/)).

## Tabs and trust

In your browser, zelk works in one tab group, titled `zelk`. The group is
all it sees. A tab outside it isn't attached and isn't listed, not even by
title.

A tab is in the group because you put it there: you **shared** it with the
extension's button, or you approved the call that opened it, or it is a
popup a trusted tab opened, such as a sign-in window. That is what
**trusted** means. Taking a tab out of the group, or closing it, ends the
trust, and so does the extension's Stop button. Trust follows the tab, not
the site: a trusted tab stays trusted through a sign-in's redirects and
links to other sites.

Three limits hold in code whatever the model says. It never types into a
password, one-time-code or card field: it hands the step to you with
`user_browser_handoff`, which waits until you press Done in the extension,
where no page can reach. And it opens only `http`, `https` and `about:blank` pages.

## How browser calls are decided

[Permission](/concepts/permissions/) decides every call before it runs.
Step 5 is where a call is allowed because of what it is.

**In zelk's own browser,** a read-only call is allowed. An acting call is
allowed by an allow rule, such as `browser_*(domain:localhost)`, and
otherwise asks you like any tool; in auto mode the reviewer decides it. Each
acting tool declares an `origin`, the page it acts on, which the model copies
from the last result. Rules match it, and just before acting the tool checks
the tab's real origin and refuses if it differs, so a page that navigated
while an approval waited is never acted on under the old approval.

**In your browser,** a call in a tab you trusted is allowed at step 5 while a
person attends. That is the decision you made when you trusted the tab. The
one call that still asks is opening a new tab, `user_browser_open` with
`new_tab`, unless a rule names the site, you approved a tab on it earlier in
the session, or a message of yours names it. Your approval puts the tab in
the group, and the prompt can offer to trust the site for the session or for
good.

Auto mode's reviewer is never enough for these tools: a call no rule allows
goes to a person, because a wrong allow spends your real account. In plan
mode nothing that acts runs.

**With no one attending,** such as `zelk exec` without `-input prompt` or a
scheduled run, a trusted tab doesn't count: that trust shouldn't spend an
account in a run nobody watches. A call that acts goes ahead only if
something you set up allows it: an allow rule that matches it, whether it
names the site or only the tool, or one of your hooks, a `PreToolUse` hook
that allows it or a `PermissionRequest` hook that approves it. Everything
else is refused, in `bypass` mode too. Reading still works: a read-only
call, such as a snapshot of a tab already attached, passes the read-only
grant as it does in any mode.

## Why browsing is dangerous

- **It holds credentials.** A signed-in tab can do anything you can on that
  site. A session cookie is the account itself, past the password and
  two-factor sign-in, so cookie values never reach the model. Exporting one
  site's cookies to a file takes your click in the extension, every time.
- **A click can't be undone.** Paying, sending and deleting look like any
  click to the code, and in a trusted tab a click doesn't ask. What holds
  the model back is its skill, which says to do such a thing only when you
  asked for exactly that, and otherwise to stop and ask you in the
  conversation. That is advice, not a gate.
- **A page can give orders.** Whoever controls a page controls text the
  model will read: a review, a comment, a hidden line. This is prompt
  injection.

zelk can't make the model immune, so it limits what an obeyed page can do.
Everything a page produces, such as its text, console output, titles and
URLs, reaches the model fenced as untrusted data, labelled "never
instructions". A page can't open a tab, because that asks you, and can't type
a password, because the driver refuses. It can't answer an approval or end a
handoff, which are decided outside it. The extension forwards only a short
list of methods and strips cookies and authorization headers.

What none of this does: a trusted tab runs what the model decides. If a page
talks the model into clicking a button in a tab you trusted, the click runs.
Trust only tabs you would let the agent work in. What it reads of them goes
to the model's provider.

## What the log records

A browser call is recorded like any tool call. `effect_started` records the
intent before the call runs and `effect_finished` the result as the model
read it, page text inside its fence. A call waiting for you is an
`await_input`, and a refusal is a `permission_decided` with the step and the
reason. A trace, recording, heap snapshot or long response body goes to a
file in the session's scratch directory, and the result carries a summary
and the path.

Replay folds the log with effects suppressed, so it never opens a browser: it
reads what each call returned. The log doesn't hold the browser's own state,
such as a page and its refs, so a call cut off by a crash is handled
carefully. A call that is read-only and idempotent, such as a snapshot, may
be run again. A click may have landed, so it is recorded as
`unknown`, never sent again, and the model is told to check the page before
repeating it ([Durability and recovery](/concepts/durability/)).

## Processes and lifetime

zelk's own browser starts on the first browser call, not with the session.
There is one for each root session, shared with its subagents, each with
tabs of its own. It runs in its own process group and dies with zelk. It
closes with the session's background work and after 30 minutes with no
browser call, and the next call starts a fresh one and says page state was
lost. Its profile is deleted on close, so a login on a site the agent tests
lasts one session.

Your browser isn't zelk's to start or stop. zelk listens on a loopback port
and your extension dials it. One root session holds it at a time, with its
subagents. When the session ends, idles for 30 minutes or is deleted, zelk
detaches, your tabs stay open, and the group is renamed with `(done)`.
Chrome shows its own bar, "zelk started debugging this browser", whenever
zelk is attached. Cancel on that bar, or Stop in the extension, ends every
action at once, and each later call fails until you press Resume.

## Limits

- zelk's own headless Chrome runs on Linux, macOS and Windows. The link
  to your browser supports Chromium browsers such as Chrome, Brave and
  Edge from Linux, macOS, native Windows and WSL2. Native Windows uses
  a per-user native messaging registration.
- In your browser, tools that would read or change your session are left
  out: storage, request mocking, heap snapshots and uploads.
- Bot challenges are handed to you, never solved. What a site's terms permit
  is your call.
- Under seatbelt on macOS and MXC on Windows, Chrome runs without its own
  sandbox, which can't nest inside those sandboxes.

## Where to go deeper

- [The browser guide](/cli/browser/): setup, pairing, the flags and the
  settings
- [Permissions](/concepts/permissions/): the steps every call goes through,
  and [Sandboxing](/concepts/sandboxing/), which confines zelk's own browser
- [The browser contract](/internals/browser/), [your
  browser](/internals/user-browser/), [automating it](/internals/browser-automation/)
  and [several zelk processes](/internals/browser-processes/): trust, hard
  limits, watches and pace
- [Cron and Watch](/cli/cron-watch/): waking the agent when a page changes
