Skip to content

feat: add abort and allow-origin network mocks - #3421

Merged
OrKoN merged 4 commits into
ChromeDevTools:mainfrom
marco-prontera:stack/network-mocks-actions
Nov 11, 2026
Merged

OrKoN merged 4 commits into
ChromeDevTools:mainfrom
marco-prontera:stack/network-mocks-actions

Conversation

@marco-prontera

@marco-prontera marco-prontera commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds abort and allowOrigin actions to page-scoped network mocks.
The core (#3384) and upstream responses (#3420) are already on main.
Closes #848.

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.

@marco-prontera
marco-prontera force-pushed the stack/network-mocks-actions branch 2 times, most recently from e51d6cd to ea7f33d Compare November 10, 2026 16:12
marco-prontera added a commit to marco-prontera/chrome-devtools-mcp that referenced this pull request Nov 10, 2026
## 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.
@marco-prontera
marco-prontera force-pushed the stack/network-mocks-actions branch from ea7f33d to 82f919c Compare November 10, 2026 16:48
@marco-prontera
marco-prontera marked this pull request as ready for review November 10, 2026 16:48
@marco-prontera
marco-prontera force-pushed the stack/network-mocks-actions branch from 82f919c to 84ab2e4 Compare November 10, 2026 17:10
@marco-prontera
marco-prontera force-pushed the stack/network-mocks-actions branch from 84ab2e4 to 9372dc2 Compare November 10, 2026 20:30
marco-prontera added a commit to marco-prontera/chrome-devtools-mcp that referenced this pull request Nov 11, 2026
## Summary

Part 2 of 3 for ChromeDevTools#848. Builds on the network mock core merged in ChromeDevTools#3384.
This PR contains only upstream response support.

```text
mock_network 1 --upstream URL
  -> validate URL -> fetch -> validate each redirect -> fulfill response
```

Adds `upstream` as an alternative to `body` for 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 `McpContext`
resource 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. ChromeDevTools#3421 adds `abort` and
`allowOrigin` after 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 ChromeDevTools#3384 merged; source and test files are registered with
GN.
- `npm run format` and the full
  `npm run test -- --test-concurrency=2` suite 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.
@marco-prontera
marco-prontera force-pushed the stack/network-mocks-actions branch from 9372dc2 to 310f552 Compare November 11, 2026 11:08
@marco-prontera

Copy link
Copy Markdown
Contributor Author

Hi @OrKoN I think this is the last one to complete our work here to close the issue #848 one detail I’d like to confirm: when allowOrigin is used without body or upstream, it reuses the server-side fetch logic. This supports GET/HEAD only so matching POST or OPTIONS requests fail. The tool description documents this limitation.

Does that scope work for this PR, or did you have in mind modifying the response from the browser’s original request?

@OrKoN
OrKoN self-requested a review November 11, 2026 11:34
@OrKoN

OrKoN commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the PR. Puppeteer does not offer response interception (tracking puppeteer/puppeteer#1191) so I think we should not fall back to server side fetches. Let's just document that allowOrigin currently requires either body or upstream. Please also check this list of changes:

  1. In src/NetworkOverrideManager.ts, do not send allowOrigin-only (passthrough) rules through #fulfillUpstream; keep abort and allowOrigin for body and upstream rules, and reject allowOrigin when the rule has no source. The Node fetch replaces the browser request: it uses the server host and network stack, buffers the full body with no timeout, hides redirects, and aborts each matched request that is not GET or HEAD (all of them when route is omitted).

  2. In tests/network_overrides.test.ts, add one real-browser test: a cross-origin fetch() fails without allowOrigin and succeeds with it, and a rule with abort: true fails the request. Mocks cannot observe the CORS check in Chrome, and this PR adds only mock tests for both actions.

  3. In src/tools/network.ts, restrict allowOrigin in the Zod schema to *, null, or a serialized origin (new URL(value).origin === value). The schema accepts values such as https://example.com/path, which Chrome rejects for each request with no error at configuration time.

  4. In #handleRequest, call this.#abortRequest(request) for override.abort instead of request.abort('failed'). A rejected request.abort goes to the catch block, which records "Failed to load " as a replacement error and aborts again.

@marco-prontera

Copy link
Copy Markdown
Contributor Author

Thanks for the PR. Puppeteer does not offer response interception (tracking puppeteer/puppeteer#1191) so I think we should not fall back to server side fetches. Let's just document that allowOrigin currently requires either body or upstream. Please also check this list of changes:

  1. In src/NetworkOverrideManager.ts, do not send allowOrigin-only (passthrough) rules through #fulfillUpstream; keep abort and allowOrigin for body and upstream rules, and reject allowOrigin when the rule has no source. The Node fetch replaces the browser request: it uses the server host and network stack, buffers the full body with no timeout, hides redirects, and aborts each matched request that is not GET or HEAD (all of them when route is omitted).
  2. In tests/network_overrides.test.ts, add one real-browser test: a cross-origin fetch() fails without allowOrigin and succeeds with it, and a rule with abort: true fails the request. Mocks cannot observe the CORS check in Chrome, and this PR adds only mock tests for both actions.
  3. In src/tools/network.ts, restrict allowOrigin in the Zod schema to *, null, or a serialized origin (new URL(value).origin === value). The schema accepts values such as https://example.com/path, which Chrome rejects for each request with no error at configuration time.
  4. In #handleRequest, call this.#abortRequest(request) for override.abort instead of request.abort('failed'). A rejected request.abort goes to the catch block, which records "Failed to load " as a replacement error and aborts again.

Thank for you review. I applied the changes

@OrKoN OrKoN left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the following:

  1. Rebase on main and resolve the merge conflicts. GitHub reports the branch as CONFLICTING, and only check-changes and the CLA check ran on this commit, so no CI test result exists.

  2. In src/NetworkOverrideManager.ts (#handleRequest), move the override.abort and override.kind === 'passthrough' branches above the try block. #abortRequest and #continueRequest catch their own errors, so the request.url() branch for source in the catch block cannot run.

  3. In src/tools/network.ts, state in the abort description that a mock with no body or upstream sends the request to the network when abort is false, and that this mock still wins over older matching mocks. The description only mentions "preserving the replacement source", and mock_network with only abort: false creates such a mock.

  4. In tests/NetworkOverrideManager.test.ts, remove the allowOrigin=* case from rejects unsupported upstream methods before fetching. allowOrigin no longer changes the method check, so the second case repeats the first.

  5. In tests/NetworkOverrideManager.test.ts, keep the main version of updates one rule without replacing unrelated rules or restarting interception and test the abort update in a new test. The rewritten test no longer replaces the source of an existing rule, so no test asserts that this update keeps the rule id.

@marco-prontera
marco-prontera force-pushed the stack/network-mocks-actions branch from 2fadaf7 to c48e154 Compare November 11, 2026 12:31
@marco-prontera
marco-prontera requested a review from OrKoN November 11, 2026 12:33

@OrKoN OrKoN left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@OrKoN
OrKoN enabled auto-merge November 11, 2026 16:51
@OrKoN
OrKoN added this pull request to the merge queue Nov 11, 2026
Merged via the queue into ChromeDevTools:main with commit eb4b53d Nov 11, 2026
15 checks passed
mijanurecon452-tech pushed a commit to mijanurecon452-tech/chrome-devtools-mcp that referenced this pull request Nov 24, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.14.0](ChromeDevTools/chrome-devtools-mcp@chrome-devtools-mcp-v1.13.0...chrome-devtools-mcp-v1.14.0)
(2026-11-24)


### 🎉 Features

* add --backgroundNewPages to keep new_page tabs in the background
([ChromeDevTools#3539](ChromeDevTools#3539))
([7a39d6d](ChromeDevTools@7a39d6d))
* add abort and allow-origin network mocks
([ChromeDevTools#3421](ChromeDevTools#3421))
([eb4b53d](ChromeDevTools@eb4b53d))
* add inspect-in-devtools skill and claude plugin command
([ChromeDevTools#2696](ChromeDevTools#2696))
([aa977a6](ChromeDevTools@aa977a6))
* add network requests from service workers
([ChromeDevTools#3554](ChromeDevTools#3554))
([11162da](ChromeDevTools@11162da))
* add service workers to get_console_message
([ChromeDevTools#3537](ChromeDevTools#3537))
([2e247a4](ChromeDevTools@2e247a4))
* include computed styles in get_css_styles
([ChromeDevTools#3538](ChromeDevTools#3538))
([cf98d8b](ChromeDevTools@cf98d8b))
* list errors a page raises while a tool runs
([ChromeDevTools#3431](ChromeDevTools#3431))
([d5d30bd](ChromeDevTools@d5d30bd))
* resolve CSS custom variable values inline in `get_css_styles`
([ChromeDevTools#3481](ChromeDevTools#3481))
([8ba2ac9](ChromeDevTools@8ba2ac9))
* support transparent screenshots
([ChromeDevTools#3457](ChromeDevTools#3457))
([045fb8c](ChromeDevTools@045fb8c))
* **telemetry:** send startup events directly from the server process
([ChromeDevTools#3511](ChromeDevTools#3511))
([b14eb81](ChromeDevTools@b14eb81))


### 🛠️ Fixes

* accept POSIX root URIs from WSL2 clients on a Windows server
([ChromeDevTools#3380](ChromeDevTools#3380))
([4b9acc9](ChromeDevTools@4b9acc9))
* align root plugin.json name with marketplace entry
([ChromeDevTools#3474](ChromeDevTools#3474))
([1424980](ChromeDevTools@1424980))
* **cli:** enable off by default categories in CLI except PWA
([ChromeDevTools#3595](ChromeDevTools#3595))
([0ff265d](ChromeDevTools@0ff265d))
* **cli:** handle array of strings correctly
([ChromeDevTools#3593](ChromeDevTools#3593))
([d197b28](ChromeDevTools@d197b28))
* **cli:** match yargs-parser when detecting negative numbers
([ChromeDevTools#3548](ChromeDevTools#3548))
([eb9b030](ChromeDevTools@eb9b030))
* **cli:** pass option values starting with `-` through to tools
([ChromeDevTools#3501](ChromeDevTools#3501))
([ec0abfc](ChromeDevTools@ec0abfc))
* **cli:** preserve daemon PID when SIGKILL fails
([ChromeDevTools#3485](ChromeDevTools#3485))
([0788697](ChromeDevTools@0788697))
* **cli:** reuse live daemons after EPERM
([ChromeDevTools#3452](ChromeDevTools#3452))
([1417f93](ChromeDevTools@1417f93))
* **cli:** strip terminal escape sequences from tool output and errors
([ChromeDevTools#3536](ChromeDevTools#3536))
([ec2fb15](ChromeDevTools@ec2fb15))
* **config:** reject --browserUrl values without an http(s) scheme
([ChromeDevTools#3437](ChromeDevTools#3437))
([e40cef6](ChromeDevTools@e40cef6))
* **config:** reject --viewport values with more than two parts
([ChromeDevTools#3577](ChromeDevTools#3577))
([ab911a6](ChromeDevTools@ab911a6))
* **console:** keep stack traces of messages from earlier navigations
([ChromeDevTools#3397](ChromeDevTools#3397))
([e8798d6](ChromeDevTools@e8798d6))
* **console:** resolve Error arguments on the session of their handle
([ChromeDevTools#3408](ChromeDevTools#3408))
([4c6c767](ChromeDevTools@4c6c767))
* dedicated worker can now build a stack trace
([ChromeDevTools#3572](ChromeDevTools#3572))
([9762165](ChromeDevTools@9762165)),
closes
[ChromeDevTools#2962](ChromeDevTools#2962)
* do not queue unknown page ids
([ChromeDevTools#3599](ChromeDevTools#3599))
([4dc8cbc](ChromeDevTools@4dc8cbc))
* **emulation:** reject non-string extraHttpHeaders values
([ChromeDevTools#3484](ChromeDevTools#3484))
([64d4726](ChromeDevTools@64d4726))
* explain DevToolsActivePort permission errors during autoConnect
([ChromeDevTools#3487](ChromeDevTools#3487))
([0e49c59](ChromeDevTools@0e49c59))
* **extensions:** preserve list_extensions fields in JSON output
([ChromeDevTools#3592](ChromeDevTools#3592))
([02b146b](ChromeDevTools@02b146b))
* **input:** allow multi-file upload_file through chooser-opening
elements
([ChromeDevTools#3436](ChromeDevTools#3436))
([ef680a3](ChromeDevTools@ef680a3))
* **input:** return when click_at, type_text, drag or press_key opens a
dialog
([ChromeDevTools#3576](ChromeDevTools#3576))
([7bcb86d](ChromeDevTools@7bcb86d))
* keep temp files under the temp dir
([ChromeDevTools#3372](ChromeDevTools#3372))
([d666acf](ChromeDevTools@d666acf))
* remove commands from claude plugin
([ChromeDevTools#3469](ChromeDevTools#3469))
([e2f08b4](ChromeDevTools@e2f08b4))
* respect tool timeouts in CLI daemon responses
([ChromeDevTools#3443](ChromeDevTools#3443))
([86a1c23](ChromeDevTools@86a1c23))
* **snapshot:** keep extra element UIDs reusable
([ChromeDevTools#3493](ChromeDevTools#3493))
([4559cd5](ChromeDevTools@4559cd5))
* treat local host name and interface addresses as local browser
endpoints
([ChromeDevTools#3463](ChromeDevTools#3463))
([cf587b4](ChromeDevTools@cf587b4))
* use exception events instead of Runtime.exceptionThrown
([ChromeDevTools#3553](ChromeDevTools#3553))
([437f394](ChromeDevTools@437f394))
* validate heap snapshot className regex
([ChromeDevTools#3030](ChromeDevTools#3030))
([343e6b1](ChromeDevTools@343e6b1))
* validate install_pwa and launch_pwa URLs against navigation policy
([ChromeDevTools#3464](ChromeDevTools#3464))
([057a6aa](ChromeDevTools@057a6aa))
* wait for parsed scripts before reporting an unknown logpoint URL
([ChromeDevTools#3461](ChromeDevTools#3461))
([404f331](ChromeDevTools@404f331))


### 📄 Documentation

* clarify that Chrome may clamp resize_page dimensions
([ChromeDevTools#3583](ChromeDevTools#3583))
([b5a41e0](ChromeDevTools@b5a41e0)),
closes
[ChromeDevTools#2998](ChromeDevTools#2998)
* explain the light and browser third-party bundles in AGENTS.md
([ChromeDevTools#3529](ChromeDevTools#3529))
([835c09a](ChromeDevTools@835c09a))
* fix typos in comments, tests and skill docs
([ChromeDevTools#3489](ChromeDevTools#3489))
([f312b72](ChromeDevTools@f312b72))


### ⚡ Performance

* **telemetry:** start the watchdog process on the first event that
needs it
([ChromeDevTools#3513](ChromeDevTools#3513))
([a4c550d](ChromeDevTools@a4c550d))


### 🏗️ Refactor

* **build:** split Puppeteer and DevTools into a separate bundle
([ChromeDevTools#3510](ChromeDevTools#3510))
([1067857](ChromeDevTools@1067857))
* **config:** import ConfigWatcher without the browser bundle
([ChromeDevTools#3520](ChromeDevTools#3520))
([24dba69](ChromeDevTools@24dba69))
* create BrowserManager without the browser bundle
([ChromeDevTools#3563](ChromeDevTools#3563))
([e8763f9](ChromeDevTools@e8763f9))
* **formatters:** rename MAX_NAME_LENGTH to
HEAP_SNAPSHOT_MAX_NAME_LENGTH
([ChromeDevTools#3591](ChromeDevTools#3591))
([92250bc](ChromeDevTools@92250bc))
* load DevTools in HeapSnapshotManager on first use
([ChromeDevTools#3564](ChromeDevTools#3564))
([d8035c6](ChromeDevTools@d8035c6))
* load McpResponse when ToolHandler builds a response
([ChromeDevTools#3565](ChromeDevTools#3565))
([e4669b3](ChromeDevTools@e4669b3))
* **telemetry:** extract sending to Clearcut into sendToClearcut()
([ChromeDevTools#3509](ChromeDevTools#3509))
([7354c59](ChromeDevTools@7354c59))
* **telemetry:** generate the session id in ClearcutLogger
([ChromeDevTools#3516](ChromeDevTools#3516))
([ea19ce7](ChromeDevTools@ea19ce7))
* **telemetry:** import flagUtils without the browser bundle
([ChromeDevTools#3518](ChromeDevTools#3518))
([ab046de](ChromeDevTools@ab046de))
* **third_party:** re-export Mutex from the light bundle
([ChromeDevTools#3566](ChromeDevTools#3566))
([48466c4](ChromeDevTools@48466c4))
* **tools:** import emulation without the browser bundle
([ChromeDevTools#3521](ChromeDevTools#3521))
([c5d5d7f](ChromeDevTools@c5d5d7f))
* **tools:** import input without the browser bundle
([ChromeDevTools#3522](ChromeDevTools#3522))
([bdecb63](ChromeDevTools@bdecb63))
* **tools:** import logpoints without the browser bundle
([ChromeDevTools#3525](ChromeDevTools#3525))
([71098b0](ChromeDevTools@71098b0))
* **tools:** import memory without the browser bundle
([ChromeDevTools#3526](ChromeDevTools#3526))
([ebb27f9](ChromeDevTools@ebb27f9))
* **tools:** import performance without the browser bundle
([ChromeDevTools#3524](ChromeDevTools#3524))
([ba76587](ChromeDevTools@ba76587))
* **tools:** import snapshot without the browser bundle
([ChromeDevTools#3523](ChromeDevTools#3523))
([110d7f3](ChromeDevTools@110d7f3))
* **utils:** import text utilities without the browser bundle
([ChromeDevTools#3519](ChromeDevTools#3519))
([8029df8](ChromeDevTools@8029df8))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Network Request Interception and URL Replacement

2 participants