Network

Use network commands to intercept requests, mock responses, inspect traffic, and export HAR files during browser automation.

Request routing

Routes apply before matching requests are sent. Set them before navigation when you need the first page load to be affected.

agent-browser open
agent-browser network route "**/analytics/**" --abort
agent-browser network route "**/api/users" --body '{"users":[]}'
agent-browser navigate https://app.example.com
CommandDescription
network route <url>Intercept matching requests
network route <url> --abortBlock matching requests
network route <url> --body <json>Fulfill matching requests with a mock body
network route <url> --body <json> --allow-origin <origin>Let a page on that origin read the mock cross-origin
network route "*" --resource-type script --abortBlock only a specific resource type
network unroute [url]Remove one route or all routes

--resource-type accepts comma-separated resource types such as script, image, font, xhr, and fetch.

A mock for a URL on another origin than the page (a page on www.example.com calling api.example.com) fails with a network error unless you pass --allow-origin with the page's origin. The mock then answers CORS checks and preflights for that origin only. JSON bodies are sent as application/json.

Request log

agent-browser network requests
agent-browser network requests --filter api
agent-browser network requests --type xhr,fetch
agent-browser network requests --method POST
agent-browser network requests --status 2xx
agent-browser network request <requestId>
agent-browser network requests --clear
FilterDescription
--filter <pattern>Filter by URL substring or pattern
--type <csv>Filter by resource type
--method <method>Filter by HTTP method
--status <status>Filter by exact status, status family, or range
--clearClear the tracked request log

Use network request <requestId> to inspect one request and response in detail after finding its ID in network requests.

HAR export

agent-browser network har start

agent-browser open https://app.example.com
agent-browser click @e4

agent-browser network har stop ./trace.har

If HAR export fails, recording and captured requests remain available. Fix the destination and retry network har stop.

har stop fails with no_har_recording when no recording is active, for example after a daemon restart (close or idle shutdown).

Text response bodies (JSON, HTML, JavaScript, form data) are embedded in the HAR as content.text by default, captured while the browser still has them buffered so they survive navigation. The --content flag on har start controls this:

ModeBehavior
--content textDefault. Embed text-like bodies (JSON, XML, HTML, JS, form data), up to 2 MB per body.
--content allEmbed every body; binary content is base64-encoded with encoding: "base64".
--content noneSizes and MIME types only, no bodies.

HAR files include request headers, response headers, cookies, POST data, and response bodies. Treat them as sensitive when pages use cookies, bearer tokens, or API keys.

SSR and no-JavaScript debugging

agent-browser batch \
  "open" \
  "network route * --abort --resource-type script" \
  "navigate http://localhost:3000" \
  "snapshot -i"

Launching with open and no URL leaves the browser on about:blank, which gives routes time to register before the first real navigation.

Saved flows

Firefox does not support --capture flow.

Saved flows are experimental. Open a session with --capture flow, do a browser task once, and agent-browser keeps the requests behind it. Later runs send those requests again and return only the data the task needs. A run sends the requests directly and uses the page, then a replay of the recorded commands, only when that does not work.

agent-browser --capture flow open "https://shop.example.com/search?q=kettle"
agent-browser flow steps
agent-browser flow save search
agent-browser close

agent-browser flow run search --param q="toaster" --fields title,price --limit 3

Capturing

--capture flow is a launch setting, like --allowed-domains. It records every command with the requests it caused until close. Passing it to a session that is already running without it relaunches the browser, as any changed launch setting does, and capture starts from that page. Later commands that repeat it or omit it do not relaunch. flow is the only supported value; any other value fails and lists the supported ones.

Every recorded command returns recorded: {seq} in its JSON response. Failed commands stay in the recording with ok: false, because a failed click may still have sent requests. close reports unsaved: {steps: N} when steps after the last save exist.

har start and har stop are not available while capture owns the recorder. har stop fails with a message to use flow save.

Steps and saving

flow steps lists the recorded steps.

ColumnMeaning
seqStep number, the same one returned as recorded.seq
commandThe command and its main argument
urlThe page URL after the command
requestsRequests the command caused
okWhether the command succeeded

flow steps --json returns the same data.

agent-browser flow save <name> [--from <seq>] [--to <seq>] [--param k=v]... [--output <id>] [--description <text>] [--timeout <ms>]
OptionMeaning
--fromFirst step number. Defaults to the last navigation after the previous save
--toLast step. Defaults to the latest
--paramA value you typed during the task, so later runs can change it
--outputRequest id whose response the flow returns: an id from the saved flow (s1r1, numbered within the saved range) or the capture id s<step>r<n> using the step numbers of flow steps. An id that names a different request in each form is refused
--descriptionOne line saying what the flow does, shown in flow lists

Saving does not stop or reset the capture, so one session can save several flows. A flow can also start on a page that is already open, such as one where you are signed in.

flow save keeps:

  • first-party JSON responses
  • JSON that server-rendered pages embed in their HTML: <script type="application/json">, __NEXT_DATA__, JSON-LD and window.x = {...} state

It never saves cookies, authorization, or token and CSRF headers. Each run reads cookies from the live session.

Before it saves, flow save waits for first-party requests that the last step of the saved range started and that have no response yet, up to the command timeout (AGENT_BROWSER_DEFAULT_TIMEOUT, or --timeout). One an earlier step started that still has no response outlived the steps after it, as a long poll does, and is not waited on; a long poll the last step started waits until the timeout. A response whose body gets no bytes for 500 ms after its headers, such as a long poll, is not waited on (the same quiet window as wait --load networkidle). Requests left out are reported as still loading at save, also in the error when the save has nothing else to keep.

The save report lists the requests it kept, the params, and any step it could not turn into a request, with the reason. When the recording stops at a sign-in form, the report says so.

Flow files are version: 1. A file with an unknown field, or any other version, fails to load with the reason.

Params

Every value typed with fill, type, keyboard type or inserttext is either a param or redacted, and a step never stores it as a literal. A value typed into an ordinary field becomes a param named after the field, with source: typed; the step keeps a {{name}} placeholder and the file keeps no copy of the value, so a run must pass --param name=value. A --param you give at save time names the value and keeps it as the recorded example. Values shorter than three characters are still params but are not replaced inside request URLs and bodies, to avoid rewriting unrelated text; secret fields are redacted whatever their length. Pass flow save --param name=value to choose the name. flow save also finds params on its own:

  • a query value of the page URL that the requests also sent, such as ?q= (source: query)
  • a value the task picked from a list in an earlier response, such as an id from a list of stores (source: response)
  • a value copied from a single field of an earlier response, such as a session key, which is filled from that response on every run

Redaction

A value typed into a secret field is stored as <redacted> and listed in redactedSteps. Keys sent with press or keydown while a secret field has focus are gathered into one secret and redacted the same way, and the password auth login fills from the vault is treated as a secret too. Only a bare key or Shift plus a key adds to that secret; a paste chord (Control+v, Meta+v, Shift+Insert) or clipboard paste into a secret field redacts the step, and the field's value is read once the paste finishes and treated as a secret in full, so a later request that sends it is not saved. When the page exposes no readable value (a contenteditable field, a cross-origin frame), the requests tagged to the paste step are dropped instead. The text of clipboard write is redacted and treated as a secret. Headers sent with a command, such as navigate --headers, are classified like a request's: an authorization, cookie, token or CSRF value is redacted, the step is marked in redactedSteps, and the commands cannot be replayed. Commands that are not recorded, such as auth login, tag no requests to a step. Any request that carried the value, as is or form-encoded, percent-encoded or JSON-escaped, is dropped from the flow, the flow cannot be replayed through the UI, and the report names the request by method and path, without the query; when the secret is unknown or still appears in the path, it names only the method and host. When it was the only request, flow save fails with that name; fill a non-secret field or use a declared tool to make a reusable flow. agent-browser reads the field itself, or the focused element for keyboard type and inserttext, not only the command, so an unlabeled field is covered. A field is secret when:

Before a flow file is written, one pass checks everything it stores: commands, requests, writes, params and the start URL. A secret the recording saw, in any encoding, becomes <redacted> anywhere. Where the browser went (a command's URL, the start URL, the Referer and Origin headers, the writes) the value of a credential query parameter, such as token, access_token, csrf, auth, apikey, signature or password, becomes <redacted> too, in the query or in a #k=v fragment; pagination cursors like pageToken are kept, and so are values the run fills from an earlier response. A saved request's own URL is sent as recorded, so a publishable key such as Algolia's stays in it. A param named like a credential keeps no recorded value, so a run must pass it. A step whose command this pass touches is listed in redactedSteps, so the command replay never sends it, and a replay that would open a start URL without its credential is refused. The save report passes the same scrub.

SignalMatches
typepassword
autocompletecurrent-password, new-password, one-time-code, or any cc-* token
Name, id, label, placeholder, aria-label or selectorContains pass, secret, token, otp, pin, cvv or card
agent-browser flow list   # Params, recorded values, item fields and verified state

Running

agent-browser flow run <name> [--param k=v]... [--where field=value] [--fields a,b.c] [--limit n] [--timeout <ms>]

--where keeps items whose field contains the value, case-insensitively. --fields returns only those fields. Use them to keep large responses out of the agent's context. Unknown field names fail with the list of valid ones.

A run tries, in order:

  1. direct HTTP, with cookies from the live session
  2. the same request sent from the page, which adds the browser's own headers
  3. a replay of the recorded commands, which reads the request the page sends

Each request must stay on the flow's site, whatever --allowed-domains says. flow save records the base domain of the start URL, as defined by the public suffix list, so a.vercel.app does not allow b.vercel.app, and a run rejects any request or redirect to a host outside it. A flow whose origin directory does not match its start URL fails to load with a message to save it again. A replay sends only the interaction fields of each recorded command and runs under the current session's settings, plugins and action policy, whatever the flow file carries. The command replay runs only plain interactions (no evaluate or other script), checks every URL in a recorded command against the same hosts, reading each string as a browser does so that tabs, newlines and control characters cannot hide a host, resolves a value under a URL key against the flow's start URL so that //host/x is checked as the page would open it (a value that does not resolve is refused), and stops as soon as the tab leaves the site. After each command it waits for the first-party XHR, fetch and document requests that command started (not requests from earlier commands or third-party ones, and not streams once their MIME type is known; a long poll still waiting for its headers is waited on up to the command's clock), up to the request timeout for that command. The run has one clock, the run's timeout (AGENT_BROWSER_DEFAULT_TIMEOUT, 25 seconds by default; flow run carries it so the CLI waits as long): each HTTP request, in-page request and replayed command gets no more than the time left, and a wait command is given that as its timeout. A replay that runs out of time fails with "the run's time is up", which does not mark the flow unverified; a write that may have gone out ends as outcome_unknown. A * pattern in a URL value, such as a wait --url glob, is checked by its host part. It keeps response bodies for its own requests even when the session's HAR runs with --content none, and leaves the HAR as it was. It cannot install --allowed-domains for its own duration, because that filter is set up when the session opens, so it relies on these checks and on any --allowed-domains the session already has. The replay swaps each recorded value in one pass over the recorded command, encodes the new value for where it lands (a URL query gets query encoding), and starts a flow recorded on an already open page from its start URL with the run's values. The command replay runs at most once per run: every request that falls back to it reads its answer from that one replay, and it is not used when another tier already sent a write the replay would send again. A write the replay sent is read back from the replay's capture and never sent a second time; if the capture has no readable answer for it, or the replay may have sent a write and captured none, the run stops with outcome_unknown, also when a later command of the replay failed. A rejection with a 4xx status does not count as a write that was sent. The replay's requests are matched by method, host, path, recorded query and body; query parameters the replay added, such as cache-busters, are ignored, and a request that matches none or several replayed requests fails instead of taking a guess. The in-page tier runs only when the active tab is already on the flow's site, and a read it sends fails when the page it ended on, after redirects, is outside that site; otherwise it is skipped, with the reason in the run's fellBack list, and the run continues with the next tier.

A direct request is sent only to a public address, checked when its host resolves and again on every redirect, so a name that later resolves to a loopback, private or link-local address (for example 169.254.169.254) is refused with a clear error and nothing is sent. A flow recorded against localhost or *.localhost runs only against loopback addresses, and one recorded against a local IP address only against local addresses. So does one recorded against another name the browser reached directly, not through a proxy, only at local addresses that the name still resolves to when the flow is saved, such as lvh.me, a .test dev domain or an intranet host: flow save writes "reach": "loopback" when every address was loopback, else "reach": "local". A local flow never sends to a link-local or cloud metadata address (169.254.0.0/16, fe80::/10, fd00:ec2::254, 100.100.100.200). When the name resolves only to local addresses but the recording shows no direct connection to them (the browser went through a proxy, or the page came from cache), the flow is not marked local and the save report says why in reachNote. A flow recorded against a public address keeps refusing a name that later resolves to a local one; a file without reach gets that refusal with a hint to record the flow again. A proxy from HTTP_PROXY, HTTPS_PROXY or ALL_PROXY is used as configured, at any address; requests that go through it are resolved and checked by the proxy, not by agent-browser. A target that NO_PROXY excludes connects directly and is checked like any other. A proxy name that is an https:// hostname is trusted by the resolver, so a direct target with that same name skips the filter. The name of an http:// proxy is looked up only when a request goes through it; if that fails, the request fails with could not resolve proxy <host>, and targets that NO_PROXY excludes run without waiting on it.

The next run starts at the tier that worked. A transport error or a skipped tier does not move it, so a run that falls to the replay only because the page tier was skipped starts at the same tier next time; a tier that failed for a reason about the site (a changed shape, a rejected status) is passed over. Every tier checks the response against the shape that was recorded. If a tier saw the shape change and none got the recorded shape for that request, the run fails with drifted, the flow is marked unverified, and the agent continues in the page and saves the flow again. If a later tier gets the recorded shape after an earlier one saw it change, the run returns ok: true with the data, but the response has verified: false and a drift object naming the tier and step that changed, and the flow is marked unverified, so a successful run and a verified flow can differ. The message names the recorded key that is missing and, when a list appeared elsewhere, where. The path of the main list is saved with each request, so a list nested deeper than the shape is checked too. A recorded list that is missing from the response, or no longer a list, is drift, even when the answer looks empty, because a missed drift returns a silently wrong empty answer. A list that is present and empty is an empty result, and a response that only lacks the counts of an empty list leaves the verified state as it was.

A request goes on to the next tier after a response that says the site changed (a different shape, a page that is not JSON) and after a tier that was skipped, such as the page tier when the tab is not on the site or the request was answered with a redirect, which the page tier does not follow. A read also goes on after a network error such as a connection reset, and after a 5xx once an earlier tier of that request saw the site change. Any other failure of a read, such as a 4xx that rejects the params, ends the request. A write that may have been sent is never sent again: after a network error once it left the machine, or an answer with a 5xx or 408 status, the request ends with outcome_unknown and no other tier sends it. A write rejected with another 4xx was not applied, so the next tier may still send it. A write the site answered with a 2xx JSON body of a different shape was applied: the request ends with write_applied and no other tier sends it. A write answered with a redirect, or with a 2xx that is not JSON (a login page, say), may not have been applied: it ends with outcome_unknown and no other tier sends it.

Some responses end the run instead of falling to the next tier, because every tier would get the same answer. They do not mark the flow unverified unless a tier earlier in the run saw the shape change, and the run adds no throttle or retry of its own. A 401 or 403 on a request recorded with a credential or signature header is not one of them: the first tiers may only lack what the page adds, so the run goes on to the replay.

ResponseError codeMeaning
401 or 403auth_expiredThe session is signed out or lacks access. Sign in again in the browser, then rerun
401 or 403 on a request recorded with a credential headercredential_not_sendableThe recording sent authorization or a token or CSRF header, which a flow never saves. The run first tries the in-page request and the command replay, and reports this only when the replay cannot get an answer, because signing in again cannot supply what the file does not keep. A 401 or 403 from the replay itself is auth_expired. Use the page UI for this task. The request is marked strippedAuth in the file
401 or 403 on a request that carries a recorded signature or timestamp headerrequest_signedA header whose name has the word ts, timestamp, sig, signature, hmac or nonce was recorded with a value that looks computed per request: an epoch in seconds or milliseconds (a fraction is fine) or an ISO-8601 date and time for a timestamp name; for a signature name, 16 or more hex characters or 20 or more base64 characters with a digit, or a t=...,v1=... list with such a part. A value made of plain words (SignatureVersion2, RSASSA-PSS-SHA256), or recorded identically on two or more requests of the flow, is static. The HTTP and in-page tiers cannot produce a fresh value, so the run goes on to the replay, where the page's own scripts sign the request; a 401 or 403 from the replay is auth_expired. The run reports request_signed when the replay cannot get an answer. Use the page for this task. The message names the headers. A header with such a name and a static value does not count: the run reports auth_expired and names the header
A recorded key is missing or retypeddriftedA tier got a response with a different shape for the request and none got the recorded one. The flow is marked unverified; use the page for this task and save the flow again. A list that is present and empty is not drift
The host resolves to an address a run does not send toaddress_refusedThe direct request was refused before any connection, so nothing was sent and no other tier tries it. Continue in the UI
429rate_limitedThe site is rate limiting the session. data.retryAfter carries the Retry-After value when the site sent one
A write that may have been appliedoutcome_unknownThe write was sent but no response came back, or the site answered it with a 5xx, 408, a redirect, or a 2xx that is not JSON, including a bot challenge page. It is not sent again; check the site before rerunning
A write the site answered with a 2xx JSON body of a different shapewrite_appliedThe write was applied and is not sent again. The flow is marked unverified. Do not repeat the write; check the site for the result
A bot challenge page in answer to a readblockedThe site served a challenge instead of data. Continue in the UI or let the user clear it. A challenge in answer to a write that was sent is outcome_unknown

A bot challenge is recognized only in HTML responses, never in JSON. A write is sent once: if the request fails without an answer, the result is outcome_unknown, because the server may have applied it, and it is never retried. A write never follows a redirect, including a 307 or 308: the 3xx is its answer and the run stops with it. A read follows redirects only within the flow's site. The code is in the JSON response as code, with data.status, data.step and data.httpStatus.

Writes

flow save lists every write the recorded steps caused in the flow's writes, each with an id, a method, a URL and a kind. The report prints them.

KindWhat it is
explicitAny request other than GET, HEAD or OPTIONS, except GraphQL queries
suspectedA GET whose path has a whole segment of logout, signout, unsubscribe, delete or remove. /address does not match
agent-browser flow run <name> --allow-write <all|id,id,...>

--allow-write takes all or comma-separated write ids. A run only sends the writes among the requests its output needs, and a write --allow-write does not cover is never sent silently: the run stops with a confirmation request, and confirm approves one write at a time. Each write is a policy action named flow_write:<id>, so --action-policy can deny or require confirmation for it and --confirm-actions flow_write:<id> asks even when --allow-write covers it. These checks apply to the HTTP and in-page tiers. The command replay also sends writes no kept request covers; those need --allow-write or a confirmation too, and the policy file can deny them. A write the site accepted is never sent again by a lower tier.

A body is read as a form when its content type says so or when it has the shape k=v&k=v, whatever its content type. A value that could break the structure of a header, a plain text body or a multipart body, such as a line break or the multipart boundary, is refused before anything is sent. A value is encoded for where it lands: a URL query or path segment, a form body, or a JSON string. Placeholders are filled in one pass, so a value that contains placeholder text is inserted as data. A flow with no output sends every request, and every write among them is gated like any other. A param never fills the text of a GraphQL operation; it fills variables and the other fields. An operation with a placeholder in its text counts as a write, and a run refuses, before sending anything, a request that becomes a write once its values are filled in but is not in writes.

Discovery

After open, back, forward, reload or a tab switch, the response lists the saved flows for that site once per session, with their params, the recorded values and the item fields. A capturing session hides only the flows it saved itself. When the page also declares WebMCP tools, those come first and the hint suggests them when one covers the task.

Saved flows use the shape of a WebMCP tool: a name, a description and an inputSchema built from the params. flow list --json returns that shape, and webmcp list shows saved flows in it, after the tools the page declares. Run them with flow run; webmcp invoke only calls the page's own tools.

The MCP server exposes agent_browser_flow_list, agent_browser_flow_run, agent_browser_flow_steps and agent_browser_flow_save in the core profile. The common capture argument opens a session with --capture flow.

Storage

Flows live in ~/.agent-browser/flows/<origin>/<name>.json. Set AGENT_BROWSER_FLOWS_DIR to use another directory. <origin> is validated as a hostname when a flow is written, so it cannot contain a path.

On macOS and Linux the directories are created with mode 0700 and the files with 0600. On Windows flows are written under the user profile and inherit its per-user permissions; agent-browser does not set an explicit ACL, so a directory set with AGENT_BROWSER_FLOWS_DIR is only as private as its location.