Back to Explore

mswjs/interceptors

GitHub
10 updates · last 90 days2 watchersOpen source

Last release:

@mswjs/interceptors is a low-level network interception library for Node.js, supporting interception and normalization of HTTP, XMLHttpRequest, fetch, and WebSocket traffic. It runs arbitrary logic on dispatched requests, converting intercepted requests to Fetch API Request instances and letting you construct Fetch API Response objects for intercepted HTTP requests. It’s useful as a lower-level component for higher-level mocking tools such as Mock Service Worker.

Project status

  • Actively maintained: The repo shows very recent activity (last upstream push on 2026-09-16), and version updates have continued into mid-September 2026 (v0.42.x through v0.43.0).
  • Update cadence: Multiple updates landed within roughly a 2-week window (v0.42.4 on 2026-09-08, v0.42.5 on 2026-09-10, v0.42.6 on 2026-09-13, v0.43.0 on 2026-09-16), suggesting an active release cadence rather than maintenance-only.

AI summary generated

AI-generated from public sources. May be inaccurate. Report

Recent updates

  • v0.43.2

    v0.43.2 addresses request header deletion behavior in the Node.js environment. The code now synchronizes headers deleted via `request.headers.delete()` onto the underlying outgoing Node HTTP message, with tests updated to cover Node vs browser behavior for XMLHttpRequest.

  • v0.43.1

    v0.43.1 contains a targeted fix for XMLHttpRequest behavior around forbidden request headers. The change ensures that unsafe headers rejected by the Fetch headers guard are not forwarded to the underlying XHR request.

  • v0.43.0

    v0.43.0 makes changes to how WebSocket-related types are exposed by the package. The main behavioral change is an API surface adjustment around exported WebSocket event types and connection-related interfaces.

    Breaking
  • v0.42.6

    v0.42.6 is presented as a bug fix that reverts connection listener invocation behavior. In the actual code changes, the socket interceptor reworks how the "connection" event is emitted and how the socket controller decides passthrough versus claim, with additional timing changes in the HTTP request interception path.

  • v0.42.5

    v0.42.5 focuses on several network and fetch robustness fixes. It addresses cancellation/hanging issues around streamed responses, ensures HTTP request parsers are properly freed during upgrade boundaries, and fixes passthrough socket listener leaks and half-open write behavior.

  • v0.42.4

    v0.42.4 contains a set of bug fixes across the HTTP and WebSocket interceptors, mainly around parser error handling, keep-alive socket edge cases, and avoiding passthrough connection interception loops. The code diff also introduces a new shared internal AsyncLocalStorage context used to mark certain “internal” connections so they bypass socket consumer interception.

  • v0.42.3

    v0.42.3 contains a bug fix aimed at correct handling of initial bytes when switching socket types during interception. The code changes add a more precise reset scheduling mechanism tied to HTTP message boundaries, plus regression tests for keep-alive passthrough scenarios and CONNECT.

  • v0.42.2

    v0.42.2 introduces socket interception behavior changes around how connection listeners decide whether traffic is handled or passed through, and adds more realistic handling of mocked HTTP CONNECT tunnel refusals. While the release notes only call out two socket fixes, the diff also changes HTTP tunnel retargeting and verdict accounting for non-HTTP traffic, which can affect how data is routed and when pass-through occurs.

  • v0.42.1

    v0.42.1 primarily updates the browser build pipeline to ensure the CommonJS-only `debug` package is bundled for browser compatibility. In addition, it bumps the package version and removes some internal documentation markdown files from the repository.

  • v0.42.0

    v0.42.0 introduces wrap-based TCP/TLS interception and expands protocol coverage (notably CONNECT and improved Node networking execution). It also modernizes the interception internals by moving to new request/event abstractions and updating the public event payloads to include the request initiator.

    BreakingFeatures
  • v0.41.9

    v0.41.9 primarily fixes a potential memory leak related to fetch abort handling and updates several interceptor internals to use global symbols via Symbol.for. The release notes describe both areas at a high level, but the code diff also contains an additional API-level change in one interceptor class and subtle behavior changes around symbol identity.

  • v0.41.8

    v0.41.8 updates the patching behavior in `PatchesRegistry` to handle properties that are non-configurable but writable. The release notes describe the intent (patching non-configurable writable properties), and the code implements it with descriptor-aware logic and adds targeted tests.

  • v0.41.7

    v0.41.7 includes fixes aimed at Node.js 24 compatibility and correctness of mocked FetchResponse cloning. It preserves custom response status and URL across Response.clone, and sanitizes recorded header tuples to avoid extra internal arguments introduced by newer Node versions.

  • v0.41.6

    v0.41.6 focuses on making fetch response cloning safer inside the interceptors. Instead of calling Response.clone() directly, the code now uses a dedicated FetchResponse.clone() helper to avoid failures when cloning is restricted by the runtime.

  • v0.41.5

    v0.41.5 fixes an issue where the library could not detect configurable global values that are defined on a prototype instead of directly on globalThis. The code change introduces a new global patching mechanism (globalsRegistry) and updates fetch, XMLHttpRequest, and WebSocket interceptors to use it.

  • v0.41.4

    v0.41.4 adds a new `FetchRequest` utility and switches several internal interceptors to construct `FetchRequest` instances instead of using the native `Request` constructor directly. The new `FetchRequest` class adds Node/Undici-compatible handling for non-configurable HTTP methods and request modes, and related prototype adjustments are made to keep raw header recording working.

    Features
  • v0.41.3

    v0.41.3 makes a small change to the WebSocket interceptor override to improve typing. The release notes describe annotating the `readyState` property to use the standard `WebSocket['readyState']` type.

  • v0.41.2

    v0.41.2 adds a new public export, resolveWebSocketUrl, and centralizes its implementation in a dedicated utility module. Internally, the WebSocket override interceptor now imports this shared helper instead of defining its own local copy.

  • v0.41.1

    v0.41.1 is a small WebSocket-focused release. The documented change is a bug fix for resolving relative WebSocket connection URLs. The code diff, however, shows broader WebSocket URL normalization behavior changes (scheme rewriting, relative URL resolution, and stricter validation) that can impact how developers compare or store `WebSocket.url` and related event fields.

    Breaking
  • v0.41.0

    v0.41.0 introduces a bundling pipeline change to use tsdown. It also includes ClientRequest-related fixes around HTTP parser cleanup and passthrough socket listener removal, plus a documented CJS export behavior change for the /presets/node entry.

    BreakingFeatures