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

HAR files can include request headers, response headers, 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.