Exclude push event from ngsw-worker.js
See original GitHub issueEDIT(@gkalpak): Related to issue #24387.
I’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[x ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:
Current behavior
I have my own service worker that listening push event. While building ngsw-worker.js auto generated and having push event available. Due to this website is showing notification two times. One from my service worker and another from ngsw-worker.js file.
Currently I have to comment that code each time I am building dist folder. Is there any option available that will automatically not include this push event listener?
this.scope.addEventListener('push', (event) => this.onPush(event));
Expected behavior
There should be option to not include this event.
Minimal reproduction of the problem with instructions
Problem required no plunkr. Its happening with PWA service worker js file.
Environment
Angular version: latest
Browser:
- [x] Chrome (desktop) version all
- [x] Chrome (Android) version all
- [x] Chrome (iOS) version all
- [x] Firefox version all
- [x] Safari (desktop) version all
- [x] Safari (iOS) version all
- [x] IE version all
- [x] Edge version all
Issue Analytics
- State:
- Created 5 years ago
- Reactions:15
- Comments:20 (13 by maintainers)
Top Results From Across the Web
How to exclude specific api request from service worker
I'm using service worker with angular cli and I have some api ... Try to using request parameter in fetch event, then get...
Read more >Angular Service Worker - Step-By-Step Guide
SwPush for doing server Web Push notifications. More than that, this module registers the Angular Service Worker in the browser (if Service ...
Read more >Service worker configuration - Angular
The ngsw-config.json configuration file specifies which files and data URLs the Angular service worker should cache and how it should update the cached ......
Read more >Top 5 @angular/service-worker Code Examples - Snyk
join(path.dirname(workerPath), 'safety-worker.js'); const configPath = path.resolve(appRoot, 'ngsw- ...
Read more >Service Workers & Angular - Martin Džejky Jakubik
The module also refers to a file called ngsw-worker.js . This file is built by the CLI in production mode. Angular uses the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is still a pretty serious issue, partly because the implementation of push handling in ngsw is extremely limited. Because push events are broadcast to the SwPush instance in the browser, if the app is active, you can’t handle a push differently for active vs inactive apps. (For example, to trigger an action or show the notification in-app when the app is active, vs showing the desktop notification when it isn’t.)
A DIY service worker can have that logic present in it to say “this was dispatched to the application, don’t call showNotification(…)”.
There’s different ways this could be handled, but it seems all of the similar bug reports are from people trying to solve that underlying problem – if you use SwPush, you can’t prevent the native push, and if you use your own service worker, you get doubled up native notifications.
Given the scenarios people have are pretty varied, being able to simply turn off push support in ngsw seems like the better option, but at a minimum it seems like the ngsw implementation needs a way to tell it “if I have any clients, so this broadcast is going to hit an instance of my application, don’t show this notification”. Basically, if the broadcast() call in handlePush() actually posts any messages, don’t execute the code following it.
We’ve been trying to use Angular PWA, but this limitation is turning into a hard block for us, because the user experience for anything but the most trivial uses of push is just bad.
Something is fundamentally broken with the architecture if common use patterns are requiring people to hand edit the build output.
@gkalpak Can it be open? This is much needed feature who has already developed website. I am using firebase service-worker from months and that is having active notification listener.
Due to dual notification listener user is receiving notification twice. I appreciate if you introduce this option soon.
Currently managing with commenting line every-time.