-
Notifications
You must be signed in to change notification settings - Fork 26.2k
feat(service-worker): Support ignoring specific URLs (e.g. for AJAX progress listener, video streaming, range requests, Firebase uploads) #21191
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
Comments
We have the same problem either. It would be best if this topic can be priorities somehow |
@doronsever
in the |
@MrCroft Thank you very much! |
Can this actually be put as a feature request from my end also? I think something having a key like |
The only problem I see is that the check should happen asynchronously. Based on #23025 (comment) it shouldn't be possible to decide whether to handle the request or not asycnhronously. But I am wondering if calling I.e. something like: onFetch(evt) {
evt.waitUntil(asynchronouslyDecideWhetherToHandle(evt).
then(handleIt => handleIt && evt.respondWith(...));
} |
I see the point. If thats the case it definitely seems like its a tradeoff on performance and feature. May be someone is is more aware than me on the implementation can point the way forward. |
This would also be useful as a workaround for Firebase uploads (#23244), video streaming (#25007) and range requests (e.g. seeking in videos) (#25865). |
I'm having the same issue when watching server sent events through an EventStream. Bypassing the 'notifications' request with aforementioned workaround fixed it for now though. |
This issue is blocking rendering PDF in Chrome from 71 version |
We are also having problems with PDF documents, they are correctly served by the Service worker, but they don't get rendered. Bypassing the sw with the console allows to see the PDF document. |
Did you try specifying |
what do you mean ? all files with extension are excluded with a glob; or am I missing something ? |
as @gkalpak says, the service worker doesnt work on safari when uploading files with @angular/fire to firebase storage |
Any roadmap on this issue? |
Plus one for this. We're hitting issues with the service worker adding "Cache-Control" headers to external API calls which don't allow that header. As we're not in control of the API we can't modify the accept headers on it. Therefore we need some way to have the browser do these API calls normally. |
@lyashu5040, it won't be able to address those cases (but it will address cases all other cases). |
BTW, for anyone desperate for a work-around, I've seen people successfully wrapping // Catch `fetch` events and prevent specific ones from propagating to the Angular SW.
self.addEventListener('fetch', evt => {
const req = evt.request;
if (/* `req` matches some criteria */) {
evt.stopImmediatePropagation();
}
});
// Import the Angular SW to do the heavy-lifting.
self.importScripts('./ngsw-worker.js'); If you do that, you might want to set updateViaCache: 'all', when registering the SW. I am not sure this will work (and it is definitely not an officially recommended approach 😇), but might be good enough as a work-around. |
issue angular#21191 added ngsw-bypass header and queryparameter for bypassing serviceworker on specific requests
issue angular#21191 added ngsw-bypass header and queryparameter for bypassing serviceworker on specific requests
issue angular#21191 added ngsw-bypass header and queryparameter for bypassing serviceworker on specific requests
… param Add support for bypassing the ServiceWorker for a request by using the ngsw-bypass header or query parameter. Fixes angular#21191
… param Add support for bypassing the ServiceWorker for a request by using the ngsw-bypass header or query parameter. Fixes angular#21191
I found a fairly simple workaround if you want your SW to completely "ignore" a specific path (for example we had a few paths that get redirected to another domain, which we did not want to be handled by our SW) : eg
|
@frankadrian, this is something different. In this case, the SW will still handle the request, but it will just choose to forward it to the server and forward the response back to the app. This is already possible without specifying a data-group (i.e. is the difault behavior). This thread is about having the SW not handle the request (and let the browser handle it instead). There is a subtle difference, but it can be important in certain cases (for reasons explained above). |
… param Add support for bypassing the ServiceWorker for a request by using the ngsw-bypass header or query parameter. Fixes angular#21191
… param Add support for bypassing the ServiceWorker for a request by using the ngsw-bypass header or query parameter. Fixes angular#21191
… param Add support for bypassing the ServiceWorker for a request by using the ngsw-bypass header or query parameter. Fixes angular#21191
… param Add support for bypassing the ServiceWorker for a request by using the ngsw-bypass header or query parameter. Fixes angular#21191
Please don't close this. As was stressed before the current implementation doesn't fix all usecases, eg. when using firebase SDK. |
@aSegatto Have you tried using an HttpInterceptor: https://angular.io/api/common/http/HttpInterceptor It could maybe capture the requests made by the firebase SDK? And in that case add the Guide for using HttpInterceptor can be found here: https://angular.io/guide/http#intercepting-requests-and-responses |
@petersalomonsen, I don't think the Firebase SDK goes through the @aSegatto, fair enough. I suggest we open a new issue specifically for situations where using an HTTP header or query param is not possible (since that is slightly different than the original issue). Can you do that (and reference this issue for context)? (Also, I think it is worth mentioning this work-around for visibility: #21191 (comment)) |
@aSegatto @gkalpak I've had a quick look at AngularFire and seems like it's not using
Then any library using We could of course add another feature to the serviceworker by using the message port to send lists of URLs to be bypassed (and the serviceworker could store this in a map), but I think I would try out the client side interception strategy first. |
@petersalomonsen Thanks for your suggestions. I don't know if modifying XMLHttpRequest would work , because i don't know how the requests are made from the firebase sdk (maybe they also use fetch API ? ), but this could be an approach... @gkalpak Thanks, I open another issue |
…e worker onFetch implementation and lets the browser handle the request, specific to angular. Background on root issue w3c/ServiceWorker#885 Issue leading to work around angular/angular#21191 Workaround that checks for the header petersalomonsen/angular@c7b357a
… param (angular#30010) Add support for bypassing the ServiceWorker for a request by using the ngsw-bypass header or query parameter. Fixes angular#21191 PR Close angular#30010
To expand upon @MrCroft 's workaround, in case anyone isn't using gulp/grunt or other build tool, you can modify the in
or for Ionic
Please note: the above code assumes you're using |
@briznad @MrCroft many thanks for the solution! It also works for me :) |
@BluebambooSRL: Sorry, I disn't understand your question 😕 Can you clarify? |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a...
Current behavior
ServiceWorker breaks AJAX uploads progress reporting.
Expected behavior
AJAX upload progress listener should work.
What is the motivation / use case for changing the behavior?
Progress is needed when handling uploads.
There is an open issue here and it is on this w3c roadmap
Until then, as far as I could read, it would be possible to make this work by checking the
event.request.url
at the very top of the SW script and simplyreturn
if it matches certain urls that would be specified inngsw-config.json
Environment
The text was updated successfully, but these errors were encountered: