-
Notifications
You must be signed in to change notification settings - Fork 801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a new, non-navigate request when fetchOptions is set #1796
Comments
If you're making a navigation request, the
So I would expect that you'd get the behavior you want by not setting
being executed with Or perhaps I'm missing something here related to older versions of Chrome that necessitates using |
The sample code i provided is only meant for reproduction of the issue. In real, i am appending additional header to each request to identify requests coming from service worker. Setting fetchOptions to undefined or {} when request.mode == 'navigate' works but defeats the purpose of setting additional header on each request. The issue can be reproduced in older builds of Chrome, I've checked randomly in Chrome builds v60 to v65. you may check with following code...
One possibility to overcome this issue i can think of is using makeRequest, and create custom request object. And the following solution works.
So as per my opinion, in order to support fetchOptions properly for request.mode=='navigate' for all workbox strategies, workbox-core needs a immediate fix. |
Implementing your own handler that creates a non-
Are you asking for a change that would detect when That could be done, but I'm not sure I'd describe that as a bug that necessitates an immediate fix as much as it's a feature request to save some effort of manually implementing the logic. |
Yes, It'd be great to have this feature. It look me long time to think of possible solution to overcome this issue. I am sure many others have faced this issue while using workbox or native service-worker js code. I'll not say it a bug, this is a fetch API limitation. In workbox, there should not be any limitation. I think, while you make this feature request in next workbox release, current documentation of workbox strategies should be updated with this limitation. (because novice like me rely on documentation and when any limitation is not documented, it takes much time to actually dig root cause of the issue). |
@jeffposnick
This seems to be not inline with the fetch spec (ref). Please note this is from my tests yesterday, as I had the same issue and tried to work around it the same way you seem to address it in d5c8277, I haven't tested the beta release yet. The solution for me was: const req = event.request.clone();
const bodyPromise = 'body' in req ?
Promise.resolve(req.body) :
req.blob();
const body = await bodyPromise;
const request = new Request(req.url, {
body: body,
credentials: req.credentials,
headers: req.headers,
integrity: req.integrity,
method: req.method,
mode: 'same-origin',
redirect: 'manual',
referrer: req.referrer,
referrerPolicy: req.referrerPolicy,
}); |
Thanks for testing this out and letting me know. (Unfortunately, Edge is currently a big gap in our automated testing strategy.) I can manually confirm that https://glitch.com/edit/#!/lace-staircase?path=sw.js:1:0 has problems in Edge. We'll experiment with your approach and get something resolved for the final v4.0.0 release. |
FYI, rather than continue to experiment to find the most efficient approach, I'm going to put in a stop-gap fix described in #1862 targeting the v4.0.0 release, and we can iterate on that in a future release. |
I'm going to remove the v4 milestone from this issue since I don't think we need to solve this before that major release. |
@jeffposnick , @philipwalton, The function I've created is working well in all browsers, tested in Edge too.
For some personal reasons, I can't post the url of my sw.js file publicly. To see it in action, provide me a way to send you a private message. I'll be happy to show you my implementation and even full code. |
Thanks @divyeshsachan—I think we can point folks to that as a workaround if they really need this functionality for navigation requests in v4.0.0. As it stands, it's a lot of code and I would rather not include it directly in The most important thing in my mind is to ensure that we avoid failed navigations, and we do have that fix in for v4.0.0. |
Since this was requested for WB v4, we are at v6 and have not seen movement in a while, I'll close the issue. |
Library Affected:
workbox-sw 3.6.1
Browser & Platform:
E.g. Chrome < v68 for Android & windows (not checked on other platforms but seems true for them as well).
Issue or Feature Request Description:
on event.request.mode == 'navigate', using fetchOptions for networkOnly, networkFirst strategy fails and throws offline fallback page with TypeError as follows. (not checked with other strategies like staleWhileRevalidate, etc.)
The problem is discussed in (https://stackoverflow.com/questions/46982502/cannot-construct-a-request-with-a-request-whose-mode-is-navigate-and-a-non-emp) and the selected answer points to remove fetchOptions completely when event.request.mode == 'navigate'. After removing RequestInit object i.e. fetchOptions from strategies works but defeats the purpose of fetchOptions completely.
So, it seems the limitation with fetch(), can you suggest a fix or possible workaround or overcome this issue on old chrome builds?
Most of my users using old chrome build on android as well as on windows platform are trapped into this issue and always see offline fallback page.
Your help is appreciated. Steps to reproduce issue follows
trace
This is modified sample code for your reference for easy reproduction of issue at your side. Activate the service worker with 'sw-offline' fallback page and navigate to other url. You will see a error log and returns offline fallback
The text was updated successfully, but these errors were encountered: