Disabling "navigate" bypass causes TypeError: "Uncaught (in promise) TypeError: Failed to construct 'Request': Cannot construct a Request with a RequestInit whose mode member is set as 'navigate'." #2229
When the handler runs it throws this uncaught error:
parseWorkerRequest.ts:11 Uncaught (in promise) TypeError: Failed to construct 'Request': Cannot construct a Request with a RequestInit whose mode member is set as 'navigate'.
at parseWorkerRequest (parseWorkerRequest.ts:11:10)
at createRequestListener.ts:31:21
at ServiceWorkerContainer.<anonymous> (setupWorker.ts:84:15)
at parseWorkerRequest.ts:
/**
* Converts a given request received from the Service Worker
* into a Fetch `Request` instance.
*/
export function parseWorkerRequest(
incomingRequest: ServiceWorkerIncomingRequest,
): Request {
return new Request(incomingRequest.url, {
...incomingRequest,
body: pruneGetRequestBody(incomingRequest),
})
}
On Safari
Navigates to http://localhost:5173/api/auth/login and responds 200 OK with index.html body. Seems like worker doesn't run at all because it should print when intercepting request, maybe navigate GET requests aren't intercepted by service workers on Safari and Firefox?
mockServiceWorker.js
Prerequisites
Environment check
msw
versionBrowsers
Chromium (Chrome, Brave, etc.), Firefox, Safari
Reproduction repository
https://github.com/iulspop/msw-navigate-error
Reproduction steps
npm install
npm run dev
localhost:5173
/api/auth/login
Current behavior
On Chrome
When the handler runs it throws this uncaught error:
at
parseWorkerRequest.ts
:On Safari
Navigates to
http://localhost:5173/api/auth/login
and responds200 OK
withindex.html
body. Seems like worker doesn't run at all because it should print when intercepting request, maybenavigate
GET requests aren't intercepted by service workers on Safari and Firefox?mockServiceWorker.js
On Firefox
Same as Safari
Expected behavior
For the request handler defined for
api/auth/login
to respond with302
and redirect/
and set the cookie.