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 "*" --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.

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

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.