# Explore your app as an agent

> Drive a live browser step by step, act on element refs, and get the console errors, dead clicks and accessibility violations each step caused

A coding agent that changed a web page usually has a build that passes and a
test that passes, and no idea what the page does. `narro explore` gives it a
browser to use, one step at a time, and tells it what each step caused. It is
the same browser, recording and replay as [Recording a web app](/docs/record),
driven by commands instead of a person.

## The loop

An exploration is a loop of three commands: `narro explore start <url>` opens
the page, `narro explore snapshot` lists what is on it, and
`narro explore act <ref> <action>` does one thing to one element. Every act
prints what changed and what went wrong, then you read it and choose the next
step. `narro explore stop` ends the run and writes the outputs.

```bash
narro explore start http://localhost:5173/login
narro explore act e3 fill agent@example.com
narro explore act e4 fill --secret APP_PASSWORD
narro explore act e5 click
narro explore stop
```

`start` leaves a background process holding the browser, so each later command
is a short call to it rather than a new browser. Without `--session`, a command
addresses the session started last; `start` prints the session id when you run
several. The same loop is available to an AI assistant as the `explore_start`,
`explore_snapshot`, `explore_act`, `explore_ask` and `explore_stop` MCP tools (see
[AI integration](/docs/ai-integration)).

## Refs and snapshots

A snapshot is the page as an agent can act on it: each button, link, field and
heading with a short ref like `e12`, its role and its name. A ref belongs to the
snapshot that issued it. If the element is gone when you use the ref, the act
fails with `stale-ref` and prints a fresh snapshot. It never clicks a
different element that happens to sit where the old one was.

Take a new snapshot after anything that changes the page. Acting prints what
changed, so most steps do not need an extra `snapshot`. Use `goto`, `back` and
`scroll` for moving around: `scroll <ref>` brings an element into view, and
`scroll --direction up|down|top|bottom` moves the page.

On a big page, `narro explore snapshot --find <text>` prints only the lines that
contain the text (case-insensitive), each under the landmarks and elements that
hold it, with a count. It shows at most 30 matches and counts the rest. The next
act still diffs against the whole page.

## Dialogs, downloads and uploads

A snapshot shows the DOM, and some things a page does are not in it. Each step
lists them under `happened`, one line each. They are not findings, because they
are not defects.

- An `alert`, `confirm` or `prompt` is answered at once and reported, for example
  `confirm "Delete project?" → accepted`. Every dialog is accepted unless
  `start --dialogs dismiss` says otherwise. One act can override that with
  `--dialog accept|dismiss`, and `--dialog-text <text>` answers a `prompt`.
- A download is saved to `.narro/explore/<session id>/downloads/` under the
  name the server suggests, and the line gives the URL and the saved path.
- `narro explore act <ref> upload <file>` sets the files of a file input. If the
  ref is the button that opens a file chooser, it clicks the button and gives
  the files to the chooser. A file chooser that some other action opens is
  reported, with the ref to upload to.

A click whose only effect was one of these is not reported as a `dead-click`.

## Handing over to a person

Some steps are for a person, not an agent: a login the agent must not see, an
MFA code, a CAPTCHA. `narro explore ask "<message>"` shows the message in a
banner at the top of the page with a Done button. It waits until the person
clicks Done (default 5 minutes, `--timeout <seconds>` to change it), then
settles and prints what changed, like an act. The banner comes back if the page
navigates, and it never appears in a snapshot or a diff. `ask` works only when
someone can see the browser, so start with `--headed` or `--connect`. Without
one of them it fails at once.

## Logging in

A page behind a login is the common case, and a password must not reach the
agent, the terminal or a file on disk. There are three ways in, from safest to
most convenient.

Save the login once with `narro auth save <url>`. It opens a window, you sign in
yourself, and it writes the cookies and storage to `.narro/auth/<host>.json`.
Every later run starts logged in with `narro explore start <url> --auth <file>`.
The file is a credential: add it to `.gitignore` (the command tells you when it
is not).

Or sign in inside the run. `narro explore act <ref> fill --secret NAME` types
the value of the environment variable `NAME` from the shell that calls it. The
value is typed into the page and is scrubbed from every snapshot, finding, log
line and recording that leaves the session; a missing variable fails the step
before anything is typed.

Or attach to a browser you are already signed in to with `--connect`, which
takes a running Chrome's CDP endpoint.

When a saved login stops working, the step raises an `auth-expired` finding
rather than a confusing failure on the login page. Run `narro auth save` again.

## What the collectors report

Each step is checked while it runs, and a finding names the step that caused it
and carries the evidence: the message, the URL, the element. The rules below are
generated from the package, so this list is the set an agent can read back.

| Rule | Severity |
| --- | --- |
| `console-error` | error |
| `page-error` | error |
| `request-failed` | error |
| `slow-step` | warning |
| `dead-click` | warning |
| `layout-shift` | warning |
| `auth-expired` | error |
| `step-error` | error |

Accessibility violations are reported as `a11y:<axe rule id>`, for example
`a11y:label`, with axe's impact mapped to the severity. An accessibility finding
belongs to the page, so it is reported once per page and element for the whole
run; every other finding is an event and is kept per step. An error that Narro
sees while a step runs is a finding or an `error` on the step, and is not
swallowed.

## Outputs

`stop` writes three files to `.narro/explore/<session id>/` and prints the
briefing:

- `briefing.md` is what happened, as evidence to act on: a summary line, then
  each finding with the step that caused it and a replay link.
- `findings.json` is the same findings as data, sorted with errors first.
- `run.narrocast` is the whole run, one chapter per step, and plays in the
  [replay player](/docs/record) or on a slide like any other cast.

To watch a run, open the cast, or start with `--headed` to see the window while
it happens. Password fields and fields filled with `--secret` are
masked in the recording; other fields stay readable so the replay is useful.
Secret values never appear in any of the three files.

## Latency

A step waits for the page to settle before it reports: network quiet, no
mutations for a moment, and no more than a cap. A page that never settles
(polling, a websocket, a spinner) returns at the cap and the step is marked
`settled: false`; the next step works as usual. Slow work is reported rather than
hidden: a step that takes longer than the threshold raises `slow-step`.

The accessibility scan runs on navigation and on large changes, not after every
click, so most steps pay only for the action, the settle and a snapshot.