Network Commands
Intercept, block, mock, and inspect network requests using the CDP Fetch domain.
Overview
zchrome network <subcommand> [options]| Subcommand | Description |
|---|---|
route | Intercept requests matching a URL pattern |
unroute | Remove all active routes |
requests | View tracked network requests |
network route
Intercept requests matching a URL pattern. Uses wildcard matching (*).
zchrome network route <pattern> [options]Options
| Option | Description |
|---|---|
--abort | Block matching requests (responds with BlockedByClient) |
--body <json> | Mock response with the given JSON body (HTTP 200, application/json) |
--file <path> | Mock response from a file (reads file contents as response body) |
--redirect <url> | Redirect matching requests to a different host |
Log Intercepted Requests
zchrome connect
zchrome navigate https://example.com
# Intercept and log all API calls (continue them normally)
zchrome network route "*api/*"Output:
Route added: *api/* (continue/log)
Waiting for requests... (Ctrl+C to stop)
INTERCEPTED: https://example.com/api/users
INTERCEPTED: https://example.com/api/configBlock Requests
Block matching requests entirely — useful for disabling analytics, ads, or heavy resources.
# Block all PNG images
zchrome network route "*.png" --abort
# Block analytics
zchrome network route "*google-analytics*" --abort
# Block ads
zchrome network route "*doubleclick.net*" --abortOutput:
Route added: *.png (abort)
Waiting for requests... (Ctrl+C to stop)
BLOCKED: https://example.com/images/hero.png
BLOCKED: https://example.com/images/logo.pngMock Responses
Return custom JSON instead of making real network requests — useful for testing, prototyping, or offline development.
# Mock a user API endpoint
zchrome network route "*api/user*" --body '{"name":"Test User","id":42}'
# Mock a config endpoint
zchrome network route "*api/config*" --body '{"feature_flag":true}'
# Mock from a file (reads file contents as response body)
zchrome network route "*api/config*" --file mock.jsonOutput:
Route added: *api/user* (mock response)
Waiting for requests... (Ctrl+C to stop)
MOCKED: https://example.com/api/user/profileMock responses are returned with HTTP 200 and Content-Type: application/json.
Redirect Requests
Redirect matching requests to a different host — useful for pointing production API calls to a local dev server or staging environment.
# Redirect all API calls to local dev server
zchrome network route "*api/*" --redirect "http://localhost:3000"
# Redirect to staging with a base path
zchrome network route "*api/v1/*" --redirect "http://staging.internal:8080/v2"Output:
Route added: *api/* (redirect → http://localhost:3000)
Waiting for requests... (Ctrl+C to stop)
REDIRECT: https://prod.example.com/api/users → http://localhost:3000/api/usersThe original URL's path and query string are preserved; only the origin (and optional base path) is replaced.
network unroute
Remove all active intercept routes by disabling the Fetch domain.
zchrome network unrouteOutput:
All routes removedThis stops all request interception and returns the browser to normal operation.
network requests
View tracked network requests using the Performance Resource Timing API.
zchrome network requests [options]Options
| Option | Description |
|---|---|
--filter <pattern> | Only show requests whose URL contains the pattern |
--clear | Clear the request log |
List All Requests
zchrome network requestsOutput:
METHOD URL STATUS
--------------------------------------------------------------------------------
fetch https://api.example.com/v1/users 45ms 1234B
script https://cdn.example.com/app.js 120ms 45678B
css https://cdn.example.com/styles.css 30ms 8901B
Total: 3 request(s)Filter by URL Pattern
# Show only API requests
zchrome network requests --filter "api"
# Show only image requests
zchrome network requests --filter ".png"Clear Request Log
zchrome network requests --clearURL Pattern Syntax
URL patterns use wildcard matching:
| Pattern | Matches |
|---|---|
*api* | Any URL containing "api" |
*.png | URLs ending in ".png" |
*example.com/api/* | API paths on example.com |
*google-analytics* | Google Analytics requests |
*/v1/users* | Specific API endpoint path |
Interactive REPL
All network commands work in the interactive REPL (also available as net):
zchrome> network route "*api*"
Route added: *api* (continue/log)
Waiting for requests... (Ctrl+C to stop)
INTERCEPTED: https://example.com/api/data
zchrome> network unroute
All routes removed
zchrome> network requests --filter "cdn"
METHOD URL STATUS
--------------------------------------------------------------------------------
script https://cdn.example.com/app.js 85ms 12345B
Total: 1 request(s)Use Cases
Block Heavy Resources for Faster Scraping
# Block images to speed up page loads
zchrome network route "*.png" --abort
zchrome network route "*.jpg" --abort
zchrome network route "*.gif" --abort
# Navigate and scrape (much faster without images)
zchrome navigate https://example.com
zchrome get text "#content"
# Remove routes when done
zchrome network unrouteTest API Error Handling
# Mock an error response
zchrome network route "*api/checkout*" --body '{"error":"payment_failed"}'
# Navigate and observe the UI error handling
zchrome navigate https://shop.example.com/checkout
zchrome snapshot -iDebug API Calls
# Watch what API calls a page makes
zchrome network route "*api*"
# Output shows each intercepted URL in real-time
# Or check what already loaded
zchrome network requests --filter "api"Offline Testing
# Block all external requests
zchrome network route "*" --abort
# Only local/cached content will load
zchrome navigate https://example.comA/B Test Feature Flags
# Mock feature flag endpoint
zchrome network route "*api/features*" --body '{"new_checkout":true,"dark_mode":false}'
# Navigate to see the app with different flags
zchrome navigate https://app.example.comLocal Development Redirect
# Redirect production API to local dev server
zchrome network route "*api/*" --redirect "http://localhost:3000"
# Navigate to production site, but API calls go to local server
zchrome navigate https://app.example.comTips
- Route is blocking — the
routecommand enters a live loop. PressCtrl+Cto stop. - One route at a time — each
routecommand sets up a new Fetch pattern. Useunroutebetween different routes. - Requests shows completed resources — it uses
performance.getEntriesByType('resource'), so it only shows requests that already finished loading. - Mock body is raw JSON — no base64 encoding needed. The body is sent directly as the response.
- Use in scripts — combine with
navigate,wait, andgetcommands for automated testing workflows.
See Also
- Network Interception - Zig API examples for programmatic network interception
- Cookies - Cookie management
- Storage - localStorage/sessionStorage management