Use mm mock-network to stub browser network requests during an active session. Prefer this over raw CDP when you need deterministic API responses.
Mock rules are installed on the active Playwright browser context:
- Run
mm launchfirst. - Add rules before the UI action that triggers the request.
mm cleanupremoves all rules;mm mock-network clearremoves rules and request history without ending the session.- Unmatched requests on a mocked origin continue unchanged and are recorded as misses.
- Cannot intercept requests during extension startup before the session is fully active.
{
"id": "token-prices",
"method": "GET",
"url": "https://price.api.metamask.io/v1/**",
"response": {
"status": 200,
"json": { "ethereum": { "usd": 1234.56 } }
}
}| Field | Description |
|---|---|
id |
Stable identifier. Same id replaces the previous rule. |
method |
HTTP method; normalized to uppercase. |
url |
Absolute URL or glob. * matches within a segment; ** matches any path suffix. |
response.status |
Optional HTTP status; defaults to 200. |
response.json |
JSON response payload. |
response.body |
Text response payload. Use either json or body. |
response.headers |
Optional. JSON/text defaults include access-control-allow-origin: *. |
# Single rule
mm mock-network add '{"id":"token-prices","method":"GET","url":"https://price.api.metamask.io/v1/**","response":{"status":200,"json":{"ethereum":{"usd":1234.56}}}}'
# Multiple rules
mm mock-network add '{"routes":[
{"id":"feature-flags","method":"GET","url":"https://client-config.api.cx.metamask.io/**","response":{"json":{"flags":{}}}},
{"id":"empty-nfts","method":"POST","url":"https://nft.api.metamask.io/**","response":{"status":200,"json":{"nfts":[]}}}
]}'
# Inspect and manage
mm mock-network list
mm mock-network requests --limit 20
mm mock-network clear- Add the rule with
mm mock-network add ... - Trigger the UI flow that makes the request
- Run
mm mock-network requests --limit 20 - Confirm the expected request has
matched: trueand the expectedruleId
Use tool name mock_network with the same input shape:
mm run-steps '{"steps":[
{"tool":"mock_network","args":{"action":"add","rule":{"id":"prices","method":"GET","url":"https://price.api.metamask.io/v1/**","response":{"json":{"ok":true}}}}},
{"tool":"navigate","args":{"screen":"url","url":"https://test-dapp.io"}}
]}'