You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(service-worker): Support ignoring specific URLs (e.g. for AJAX progress listener, video streaming, range requests, Firebase uploads) #21191
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 simply return if it matches certain urls that would be specified in ngsw-config.json
Environment
Angular version: 5.1.2
Reacted by Byron Dover, netTrekSL, Mateus Lopes, Sylvain Dumont, Till, Daniel Schuba, 1001 Days of Code, Stefan Fodor, Sean Steinke, McKenzie Long and 10 more
@doronsever
In case this is critical for you, I've just tested with editing the resulted ngsw-worker.js file and it works:
I've installed gulp and gulp-replace 😬 and created a gulp task that replaces onFetch(event) { with:
onFetch(event) {
if (event.request.url.indexOf('/upload') !== -1) { return; }
in the dist/ngsw-worker.js file and then my build script became ng build [whatever options I have] && gulp swAjaxUploadFix (or I could have used the default task and simply run gulp, but I like to name my tasks).
Of course, in my case we have the convention that all upload urls contain /upload.
And also I log a big, multiple line message in the console on build so I don't forget about removing this workaround as soon as this feature gets implemented by the Angular team.
But, meanwhile, reporting the progress on uploads works! 😁
So, I just wanted to let you know it works. Because when I posted the issue, I had only read that this would fix progress reporting, and took what I read for granted, haven't tested myself. Now I have!
Reacted by Krishnamurthy G B, Till, 1001 Days of Code, McKenzie Long, David Ed, Nicolas Beaussart, RebendaJiri, Huzirun, Paweł Hertman, unspike and 8 more
Reacted by Maxime Layat, Huzirun, Bacila Nicolae, jraadt and ColaColin
Reacted by Ignat Beresnev and jraadt
Reacted by David Ed, Huzirun, Bacila Nicolae, jraadt and Akhoy
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 event.waitUntil() allows us to defer the decision of whether to call event.respondWith() or not and still be able to choose not to handle the request.
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.
changed the title [-][ServiceWorker] Possibility to have urls that bypass the ServiceWorker (otherwise, Ajax progress listener doesn't work)[/-][+]feat(service-worker): Support ignoring specific URLs (e.g. for AJAX progress listener, video streaming, range requests)[/+]on Sep 17, 2018
This would also be useful as a workaround for Firebase uploads (#23244), video streaming (#25007) and range requests (e.g. seeking in videos) (#25865).
A possible solution could come through #20756 (comment).
Reacted by Marian Stoica, Maxime Layat, Michael Sanford, Alexandre Vilao and Jek Bao CHOO
changed the title [-]feat(service-worker): Support ignoring specific URLs (e.g. for AJAX progress listener, video streaming, range requests)[/-][+]feat(service-worker): Support ignoring specific URLs (e.g. for AJAX progress listener, video streaming, range requests, Firebase uploads)[/+]on Sep 17, 2018
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.
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.
@petersalomonsen, I don't think the Firebase SDK goes through the HttpClient (for all requests), but I might be wrong.
@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 HttpClient. But even when this is the case we can still intercept XMLHttpRequest for example like this:
Then any library using XMLHttpRequest in your client will set the ngsw-bypass header. You can extend this to check for specific URLs / methods.
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...
Message port IMHO is more clean as it doesn't couple to the sdk implementation.
To expand upon @MrCroft 's workaround, in case anyone isn't using gulp/grunt or other build tool, you can modify the ngsw-worker.js file using sed and easily integrate the workaround into your package.json scripts. Here's the code I'm using on MacOS 10.14.5:
@briznad@MrCroft many thanks for the solution! It also works for me :)
There is any way to write the code at the @angular/pwa library in order to avoid tho search for this bug? @gkalpak@AngularFirebase@fireship-io Thanks in advance!! Federico
Activity
doronsever commentedon Jan 21, 2018
We have the same problem either.
For now, we added an ugly spinner instead of a progress bar but our clients aren't happy with it.
It would be best if this topic can be priorities somehow
NgxDev commentedon Jan 24, 2018
@doronsever
In case this is critical for you, I've just tested with editing the resulted
ngsw-worker.jsfile and it works:I've installed
gulpandgulp-replace😬 and created a gulp task that replacesonFetch(event) {with:in the
dist/ngsw-worker.jsfile and then my build script becameng build [whatever options I have] && gulp swAjaxUploadFix(or I could have used the default task and simply rungulp, but I like to name my tasks).Of course, in my case we have the convention that all upload urls contain
/upload.And also I log a big, multiple line message in the console on build so I don't forget about removing this workaround as soon as this feature gets implemented by the Angular team.
But, meanwhile, reporting the progress on uploads works! 😁
So, I just wanted to let you know it works. Because when I posted the issue, I had only read that this would fix progress reporting, and took what I read for granted, haven't tested myself. Now I have!
doronsever commentedon Jan 24, 2018
@MrCroft Thank you very much!
At least it's working now :)
ganeshkbhat commentedon May 5, 2018
Can this actually be put as a feature request from my end also? I think something having a key like
"exclude"with interface likeinterface Exclude { name: string; urls: string[]; version?: number; }. There is one more open question like this in 'so. https://stackoverflow.com/questions/47693093/angular-5-and-service-worker-how-to-exclude-a-particular-path-from-ngsw-configgkalpak commentedon May 5, 2018
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
event.waitUntil()allows us to defer the decision of whether to callevent.respondWith()or not and still be able to choose not to handle the request.I.e. something like:
ganeshkbhat commentedon May 18, 2018
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.
[-][ServiceWorker] Possibility to have urls that bypass the ServiceWorker (otherwise, Ajax progress listener doesn't work)[/-][+]feat(service-worker): Support ignoring specific URLs (e.g. for AJAX progress listener, video streaming, range requests)[/+]gkalpak commentedon Sep 17, 2018
This would also be useful as a workaround for Firebase uploads (#23244), video streaming (#25007) and range requests (e.g. seeking in videos) (#25865).
A possible solution could come through #20756 (comment).
[-]feat(service-worker): Support ignoring specific URLs (e.g. for AJAX progress listener, video streaming, range requests)[/-][+]feat(service-worker): Support ignoring specific URLs (e.g. for AJAX progress listener, video streaming, range requests, Firebase uploads)[/+]GXGOW commentedon Dec 19, 2018
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.
delagen commentedon Dec 20, 2018
This issue is blocking rendering PDF in Chrome from 71 version
aSegatto commentedon Dec 21, 2018
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.
34 remaining items
feat(service-worker): support bypassing SW with specific header/query…
aSegatto commentedon Apr 26, 2019
Please don't close this. As was stressed before the current implementation doesn't fix all usecases, eg. when using firebase SDK.
petersalomonsen commentedon Apr 26, 2019
@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
ngsw-bypassheader.Guide for using HttpInterceptor can be found here: https://angular.io/guide/http#intercepting-requests-and-responses
gkalpak commentedon Apr 27, 2019
@petersalomonsen, I don't think the Firebase SDK goes through the
HttpClient(for all requests), but I might be wrong.@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))
petersalomonsen commentedon Apr 28, 2019
@aSegatto @gkalpak I've had a quick look at AngularFire and seems like it's not using
HttpClient. But even when this is the case we can still interceptXMLHttpRequestfor example like this:Then any library using
XMLHttpRequestin your client will set thengsw-bypassheader. You can extend this to check for specific URLs / methods.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.
aSegatto commentedon Apr 29, 2019
@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...
Message port IMHO is more clean as it doesn't couple to the sdk implementation.
@gkalpak Thanks, I open another issue
Added http header to BrowserFetchStreamTransport that bypasses servic…
feat(service-worker): support bypassing SW with specific header/query…
briznad commentedon Jun 7, 2019
To expand upon @MrCroft 's workaround, in case anyone isn't using gulp/grunt or other build tool, you can modify the
ngsw-worker.jsfile usingsedand easily integrate the workaround into yourpackage.jsonscripts. Here's the code I'm using on MacOS 10.14.5:in
package.jsonor for Ionic
Please note: the above code assumes you're using
wwwas your build output directory (vsdist, etc).BluebambooSRL commentedon Jul 22, 2019
@briznad @MrCroft many thanks for the solution! It also works for me :)
There is any way to write the code at the @angular/pwa library in order to avoid tho search for this bug? @gkalpak @AngularFirebase @fireship-io Thanks in advance!! Federico
gkalpak commentedon Jul 22, 2019
@BluebambooSRL: Sorry, I disn't understand your question 😕 Can you clarify?
angular-automatic-lock-bot commentedon Sep 15, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.