Option to call event.respondWith only if we have registered handler for this request
See original GitHub issueIs your feature request related to a problem? Please describe. A lot of requests are completed with warning
Warning: captured a request without a matching request handler
because MSW calls event.respondWith
almost for every request
Describe the solution you’d like
It would be really great, if we could configure worker.start()
with bypassUnhandledPath
/bypassUnknownPath
option
worker.start({ bypassUnknownPath: true })
Or with some bypass
function, where I could write own match test
const handlers = [] // MSW handlers
const match = (path, url) => { /* ... */ }
worker.start({
bypass: (req) => {
const foundHandler = handlers.find((handler) => match(handler.info.path, req.url));
return !foundHandler;
},
});
Describe alternatives you’ve considered
I’ve added this code to fetch
listener in mockServiceWorker.js
// Bypass static files (.js/css/woff2/etc).
if (new URL(request.url).pathname.match(/\.(.*)$/)) {
return;
}
So at least now I ignore static files. But this is not enough for me.
Additional context
I’m not afraid about warnings, I can disable them.
In fact I’m afraid of Chrome’s “network” tab, where I see a lot of XHR requests intercepted with MSW.
But truly these request are css/js/woff2/html/..etc
. And I would like to not intercept them with MSW at all.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:8 (4 by maintainers)
Top GitHub Comments
Just FYI, in Chrome Devtools, Network tab, you may add
-is:service-worker-initiated -is:service-worker-intercepted
to filter out service worker requests. Much cleaner after that.A great find regarding the difference in the
x-msw-bypass
header! I’ve opened an issue about it https://github.com/mswjs/msw/issues/1085. @crutch12, could you be interested in helping us fix it? I’ll assist you during the code review and make sure we cover this behavior difference. Thanks.