@mswjs/interceptors
0.45.12 · 11 Nov 2026MIT38M / weekRepositorynpmAtom feed
0.45.12 is the newest release of 0.42.x.
In short
5 breaking6 new13 fixed
- Breaking
Node.js v22 is the minimal supported version.
- Breaking
getRawRequestutility has been removed. Use theinitiatorreference on request listeners directly. - Breaking
/utils/nodeandgetClientRequestBodyStream()has been removed. Use theinitiatorreference directly. - Breaking
file://protocol requests are unsupported withfetchthe same way they aren't supported in Node.js 22 and 24 (improved compliance). - Breaking
HTTP-to-WebSocket upgrade requests throw with
fetchthe same way they do in Node.js. Other upgrade paths are unaffected and function correctly (http.request,WebSocket,undici).
Release note
Implements TCP/TLS wrap-based interception
Breaking changes
- Breaking
Node.js v22 is the minimal supported version.
- Breaking
getRawRequestutility has been removed. Use theinitiatorreference on request listeners directly. - Breaking
/utils/nodeandgetClientRequestBodyStream()has been removed. Use theinitiatorreference directly. - Breaking
file://protocol requests are unsupported withfetchthe same way they aren't supported in Node.js 22 and 24 (improved compliance). - Breaking
HTTP-to-WebSocket upgrade requests throw with
fetchthe same way they do in Node.js. Other upgrade paths are unaffected and function correctly (http.request,WebSocket,undici).
Features
Supports Node.js v26.
Supports Undici
fetchandrequesteven when they aren't global.Exposes the request
initiatoron the "request" event listener. Theinitiatorproperty points toClientRequest,XMLHttpRequest, orRequestinstance that initiated the intercepted request. If no instance can be reliably deduced, points to the rawnet.Socketbehind the connection.
Bug fixes
The library now executes more of the Node.js network that ever before. In fact, it executes the biggest possible amount of Node.js code. We are literally patching before the C++ bindings.
ClientRequest using sockets is now properly supported.
Now it doesn't matter how you import
http/https(e.g.import * as httpbroke previously since we cannot patch that).You can now end requests in the write callbacks. The documented limitation of Interceptors is gone.
Clients waiting for the
secureConnectbefore writing anything are now properly supported.TLS connections now correctly emit the
keylogevent on the socket.Fixes an issue where the automatic
Content-Typeheader added by Undici was not set on mocked responses.socket.address(), as well aslocalAddress,localPort,localFamily,remoteAddress,remotePort, and `remoteFamily, are correctly set for both mocked and bypassed connections.XMLHttpRequest: Fixes an issue where redirect responses weren't being followed.
XMLHttpRequest: Fixes an issue where the "progress" event for
request.uploadwasn't dispatched correctly.XMLHttpRequest:
totalresponse body length is now computed only from thecontent-lengthmocked response header, just like it's done natively.XMLHttpRequest: The
progressevent is now correctly emitted on the request for chunked responses.XMLHttpRequest (JSDOM): Correctly performs the
OPTIONSpreflight request based on the JSDOM implementation (previously, preflight triggered for requests that shouldn't trigger it).XMLHttpRequest: Implements mock response handling in accordance to the WHATWG XMLHttpRequest specification to improve browser compliance.
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.