Repository navigation
feat: support upstream network mock responses - #3420
Conversation
e9b420c to
085135b
Compare
## Summary Part 1 of 3 for ChromeDevTools#848: the core and local-file replacements. ```text mock_network 1 --body file.js -> create or update a page mock mock_network 1 [filters] -> inspect mocks remove_network_mock 1 -> remove matching mocks, or all ``` Network mocks are disabled by default in MCP and CLI. Enable them with `--categoryNetworkMocks`; changing the category requires a server restart. Adds the two-tool interface for local response files through MCP and CLI. Rules use absolute URLPatterns with optional resource types. An omitted query matches any query string; regex and named groups are rejected. Mocks survive reloads and reread files on each request. Updating a rule preserves unrelated rules; the most recently updated matching rule wins. Inspection reports hit counts, unmatched rules, and replacement errors. No-match navigation warnings follow main-frame document requests, so hash changes do not trigger them. Mocks disable the page cache and intercept all requests, so tool responses, performance traces, and Lighthouse reports carry a measurement warning. Changes are rejected during a trace; removing the last mock restores the cache and stops interception. Includes generated CLI definitions, documentation, metrics, and tests. Follow-ups: ChromeDevTools#3420 adds upstream responses; ChromeDevTools#3421 adds abort and allow-origin. Both are dependent drafts targeting `main` until their prerequisites land. ## Evidence - **Before:** replacing a page resource required manual DevTools setup. **After:** local-file replacement and rebuilds work through the new tools, with useful diagnostics when a file disappears. - Rebased on `main`; new source and test files are registered with GN. - `npm run sync`, `npm run gen`, `npm run format`, and the full `npm run test` suite passed: 1,863 passed, 3 skipped, 0 failed, including real Chrome integration tests. ## Merge Danger **Door:** two-way **Blast Radius:** page Active mocks alter request delivery and measurements for their page.
085135b to
5136c9c
Compare
5136c9c to
e55fa9b
Compare
OrKoN
left a comment
There was a problem hiding this comment.
Please check the initial AI-review feedback:
-
Remove
accept-encodingfrom the headers that#fulfillUpstreamforwards (drop it fromCROSS_ORIGIN_REDIRECT_HEADERSand strip it from the same-origin pass-through ingetRedirectHeaders). Chrome sendsAccept-Encoding: gzip, deflate, br, zstd, undici on Node 20 and 22 does not decodezstd, and the code then delivers a still-compressed body after it removed thecontent-encodingheader. -
Preserve multiple
Set-Cookieheaders in#fulfillUpstreamwithresponse.headers.getSetCookie()and pass the array torequest.respond(PuppeteerheadersArrayexpands arrays). Thefor (const [name, value] of response.headers)loop stores only the last value underset-cookie. -
Rename
kind: 'redirect',redirectUrl,RedirectNetworkOverrideInput,RedirectNetworkOverrideandStoredRedirectNetworkOverridetoupstream/upstreamUrl/Upstream*. The tool parameter and all user-facing text say "upstream", and the mechanism is a server-side fetch, not an HTTP redirect. -
Nit: let
fetchWithValidatedRedirectstake theUrlAccessPolicyand callvalidateNetworkUrlitself. Both callers pass the identical closureurl => validateNetworkUrl(url, policy).
🤖 I have created a release *beep* *boop* --- ## [1.13.0](ChromeDevTools/chrome-devtools-mcp@chrome-devtools-mcp-v1.12.0...chrome-devtools-mcp-v1.13.0) (2026-11-11) ### 🎉 Features * add logpoints built on the DevTools BreakpointManager ([ChromeDevTools#3211](ChromeDevTools#3211)) ([0877ee0](ChromeDevTools@0877ee0)) * add page-scoped network mocks ([ChromeDevTools#3384](ChromeDevTools#3384)) ([1d692d3](ChromeDevTools@1d692d3)) * support upstream network mock responses ([ChromeDevTools#3420](ChromeDevTools#3420)) ([c4bf342](ChromeDevTools@c4bf342)) ### 🛠️ Fixes * **config:** accept config files with a UTF-8 BOM ([ChromeDevTools#3365](ChromeDevTools#3365)) ([63170b1](ChromeDevTools@63170b1)) * **console:** stop resolving a cyclic Error.cause chain after 10 causes ([ChromeDevTools#3338](ChromeDevTools#3338)) ([172656a](ChromeDevTools@172656a)) * disable set_logpoints when --no-javascript-evaluation is set ([ChromeDevTools#3415](ChromeDevTools#3415)) ([11fcc59](ChromeDevTools@11fcc59)), closes [ChromeDevTools#3414](ChromeDevTools#3414) * **extensions:** say list_extensions only lists unpacked extensions ([ChromeDevTools#3433](ChromeDevTools#3433)) ([1383bb9](ChromeDevTools@1383bb9)) * ignore an invalid cached version in the update check ([ChromeDevTools#3392](ChromeDevTools#3392)) ([3a9f378](ChromeDevTools@3a9f378)) * **input:** validate press_key and submitKey parameters in Zod schema ([ChromeDevTools#3382](ChromeDevTools#3382)) ([375a269](ChromeDevTools@375a269)) * **network:** start an empty request list for navigations without a request ([ChromeDevTools#3357](ChromeDevTools#3357)) ([b701776](ChromeDevTools@b701776)) * normalize non-Error values thrown by tool handlers ([ChromeDevTools#3068](ChromeDevTools#3068)) ([535a3dc](ChromeDevTools@535a3dc)) * **performance:** error when performance_stop_trace is called on a non-recording page ([ChromeDevTools#2971](ChromeDevTools#2971)) ([ChromeDevTools#3117](ChromeDevTools#3117)) ([1ab630a](ChromeDevTools@1ab630a)) * **plugin:** launch the Claude Code MCP server with npx --prefix ([ChromeDevTools#3353](ChromeDevTools#3353)) ([a24334d](ChromeDevTools@a24334d)) * preserve task serialization on request cancellation ([ChromeDevTools#3079](ChromeDevTools#3079)) ([03fd4e8](ChromeDevTools@03fd4e8)) * report page loads that keep the URL ([ChromeDevTools#3395](ChromeDevTools#3395)) ([3cc38bb](ChromeDevTools@3cc38bb)) * save binary request bodies byte for byte ([ChromeDevTools#3404](ChromeDevTools#3404)) ([e3eb901](ChromeDevTools@e3eb901)) * suggest --headless when Chrome cannot find an X server ([ChromeDevTools#3428](ChromeDevTools#3428)) ([8b0856a](ChromeDevTools@8b0856a)) * **url:** unwrap view-source: before all scheme checks in validateUrl ([ChromeDevTools#3335](ChromeDevTools#3335)) ([7275268](ChromeDevTools@7275268)) * **wait:** explain whitespace-sensitive text matching ([ChromeDevTools#3350](ChromeDevTools#3350)) ([81a0379](ChromeDevTools@81a0379)) ### 📄 Documentation * add Pi client configuration ([ChromeDevTools#3364](ChromeDevTools#3364)) ([bc0d93e](ChromeDevTools@bc0d93e)) * clarify custom browser launch and connection options ([ChromeDevTools#3386](ChromeDevTools#3386)) ([7e10c08](ChromeDevTools@7e10c08)) * **input:** note that press_key cannot drive native <select> popups on macOS ([ChromeDevTools#3288](ChromeDevTools#3288)) ([8e79bd0](ChromeDevTools@8e79bd0)) ### ⚡ Performance * **memory:** drop async parents of request initiators in NetworkCollector ([ChromeDevTools#3345](ChromeDevTools#3345)) ([ca6f834](ChromeDevTools@ca6f834)), closes [ChromeDevTools#3344](ChromeDevTools#3344) ### 🏗️ Refactor * re-export only used Zod runtime members from third_party barrel ([ChromeDevTools#3439](ChromeDevTools#3439)) ([6b056c8](ChromeDevTools@6b056c8)) * reuse Zod schemas and validate integer viewport dimensions ([ChromeDevTools#3367](ChromeDevTools#3367)) ([3c609da](ChromeDevTools@3c609da)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: Alex Rudenko <[email protected]>
## Summary Adds `abort` and `allowOrigin` actions to page-scoped network mocks. The core (ChromeDevTools#3384) and upstream responses (ChromeDevTools#3420) are already on `main`. Closes ChromeDevTools#848. ```text abort=true -> fail matching requests abort=false -> resume the stored source or browser request allowOrigin + body/upstream -> set Access-Control-Allow-Origin allowOrigin without source -> configuration error ``` Omitted actions retain existing settings; `abort=true` takes precedence over the response source and origin header. `allowOrigin` requires a `body` or `upstream` source, supplied in the same call or already stored on the matching rule. It accepts `*`, `null`, or a serialized origin. This does not configure preflight or credential headers. Only upstream sources use server-side GET/HEAD fetches. With no source, `abort=false` sends the request to the network and still takes precedence over older matching mocks. Includes validation, generated CLI/docs, and tests for abort toggling, preserving sources, origin headers, and rejected aborts without retries or false replacement errors. Network mocks are disabled by default in MCP and CLI. Enable them with `--categoryNetworkMocks`; changing the category requires a server restart. ## Evidence - **Before:** rules needed a local body or upstream source. **After:** agents can abort requests or set an origin header on a replacement response, then update actions without replacing its source. - A real Chrome test verifies that a cross-origin fetch fails without `allowOrigin`, succeeds with it, and fails again with `abort: true`. - Regression tests reproduce source-less origins, invalid origin values, and duplicate aborts on the previous revision (12 failures). - `npm run gen` (including build and format) and the full `npm run test -- --test-concurrency=2` suite passed: 1,955 passed, 3 skipped, 0 failed. - Updated with `main` (`cf587b48`) and tested with Chrome for Testing 157. ## Merge Danger **Door:** two-way **Blast Radius:** page These actions are opt-in and retain the existing measurement warning.
Summary
Part 2 of 3 for #848. Builds on the network mock core merged in #3384.
This PR contains only upstream response support.
Adds
upstreamas an alternative tobodyfor GET/HEAD requests.Allowlists and blocklists apply before contacting the initial target and
every redirect destination, including same-origin replacements.
Cross-origin hops drop credentials and other non-allowlisted headers.
Fetch negotiates compression independently of Chrome. Decoded responses
omit stale compression and length headers, and separate Set-Cookie headers
are preserved.
The redirect loop and URL policy checks are shared with
McpContextresource loading. Resource loading still returns text and rejects HTTP
errors; mocks preserve response status and binary bodies. Shared errors
redact URL credentials and query strings, report missing Location headers,
and release redirect bodies on error paths.
Includes mutually exclusive parameter validation, generated CLI/docs,
redirect-policy tests, and browser coverage. #3421 adds
abortandallowOriginafter this PR.Network mocks are disabled by default in MCP and CLI. Enable them with
--categoryNetworkMocks; changing the category requires a server restart.Evidence
Before: mocks could only serve local files.
After: upstream responses work across reloads, and redirects to blocked
destinations fail before the destination is contacted.
Rebased after feat: add page-scoped network mocks #3384 merged; source and test files are registered with GN.
npm run formatand the fullnpm run test -- --test-concurrency=2suite passed on this revision:1,890 passed, 3 skipped, 0 failed, including real Chrome integration tests.
Three regression cases fail on the previous revision and pass with these
fixes: same-origin and cross-origin Accept-Encoding, and multiple Set-Cookie.
Merge Danger
Door: two-way
Blast Radius: network
Opt-in upstream responses use server-side fetches and retain the core
measurement warning.