Skip to content

Exclude push event from ngsw-worker.js #26413

Closed

Description

@shabbir-dhangot

EDIT(@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

Activity

  1. gkalpak commented on Oct 12, 2018

    @gkalpak
    Member

    There is not such option currently. Generally, @angular/service-worker assumes it is the only SW running.
    As a workaround, maybe you could try to call event.stopImmediatePropagation() or something.

  2. gkalpak commented on Oct 12, 2018

    @gkalpak
    Member

    Closing, because there are no plans to provide such configuration options for the time being (although we might revisit in the future).

  3. shabbir-dhangot commented on Oct 12, 2018

    @shabbir-dhangot
    Author

    @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.

  4. gkalpak commented on Oct 12, 2018

    @gkalpak
    Member

    OK, it sounds reasonable, I guess (especially if you don't control the other SW).
    Maybe we could have a method on SwPush to disable handling of push events.

    (Not a high priority, though. Contributions welcome 😉)

  5. added
    featureLabel used to distinguish feature request from other issues
    area: service-workerIssues related to the @angular/service-worker package
    on Oct 12, 2018
  6. added this to the Backlog milestone on Oct 12, 2018
  7. shabbir-dhangot commented on Jan 22, 2019

    @shabbir-dhangot
    Author

    @gkalpak I able to comment line using sed below command post ng build --prod

    
    ng build --prod && pushline=\"this.scope.addEventListener('p\" && replaceline=\"\/\/this.scope.addEventListener('p\" && sed -i \"s/$pushline/$replaceline/g\" dist/ngsw-worker.js
    
    
  8. johanchouquet commented on Apr 23, 2020

    @johanchouquet
    Contributor

    Hello there,

    Do you plan on working on that feature anytime soon ?

    I think that a lot of people want to build PWAs using FCM for push notifications, and they also want to use angular service worker.

    It seems that a Workbox + FCM solution is possible, but there are no examples out there of how to do that (especially given that Angular provides its own implementation of the Service Worker). So, it's a big blocker to the adoption of Angular Service Worker.

    What you think ?

  9. webmaxru commented on Apr 23, 2020

    @webmaxru
    Member

    Hello! Just FYI: this part of my PWA workshop explains how to add Push support to Workbox-driven service worker. And the demo app is based on Angular (link to the repo is included in this doc): https://docs.google.com/document/d/10IOJ53cJR3opRYfpSKlRBYUnoeAHZOnLCBfW0mjA790/edit#heading=h.z6oes5esmix1

  10. johanchouquet commented on Apr 23, 2020

    @johanchouquet
    Contributor

    Hi @webmaxru! Thanks for the link. I'll look at that for sure !

  11. 1 remaining item

  12. WaseemRakab commented on Sep 7, 2020

    @WaseemRakab

    im looking forward to this issue also...
    any update on this??

  13. ciekawy commented on Oct 12, 2020

    @ciekawy

    I just got here looking for a solution and I'm so surprised there is no real one for so long and there are articles on the web and SO answers suggesting to comment out lines in ngsw-worker.js - I think this shows how important this issue is...

  14. angular-robot commented on Jun 4, 2021

    @angular-robot
    Contributor

    Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

    Find more details about Angular's feature request process in our documentation.

  15. angular-robot commented on Jun 25, 2021

    @angular-robot
    Contributor

    Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

    We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

    You can find more details about the feature request process in our documentation.

  16. markgoho commented on Jun 25, 2021

    @markgoho
    Contributor

    @jessicajaniuk is there a chance the automated process got this one wrong? The issue is from 2018 and has 6 thumbs up and 3 hearts on the original comment. Does the algorithm count other reactions besides 👍🏻 and does it scan for unique reactions across the whole thread of comments or just the initial comment?

    It's possible that if this were a brand new issue, it might have gotten the required 20 👍🏻 but this one is so old that nobody thought to go back and provide the additional 👍🏻 to get it to "count".

    I'm not asking for this to be reconsidered, only for it to be used as way of asking "is the process working the way we intended it to?"

  17. jessicajaniuk commented on Jun 25, 2021

    @jessicajaniuk
    Contributor

    Hi @markgoho! Thanks for the question. I can understand your confusion here. The voting process looks solely at the issue description and does not look at all the comments within the issue. So in that case, this feature request only got 6 👍🏻 votes. Since we just started this new voting process, it's safe to say a lot of feature requests that have been around a while are getting closed with this situation. You are welcome to submit a new feature request to see if we get more votes going forward, since there will be less noise in the feature request queue.

  18. markgoho commented on Jun 25, 2021

    @markgoho
    Contributor

    thanks for this clarification regarding what exactly the bot is counting @jessicajaniuk

    regarding your suggestion to submit a new feature request, it seems like this might create a lot of duplicate issues simply to gather votes, e.g. this particular issue didn't get enough votes, so I'm creating a new issue with the same feature request?

    do you think there might be a better way to approach this scenario? perhaps a "reset button" of sorts where a feature request is put back on the queue with a fresh 20-day timer? maybe it has to have been 3 months or something before a reset can happen (just thinking out loud here)

  19. jessicajaniuk commented on Jun 25, 2021

    @jessicajaniuk
    Contributor

    I hear you on the noise issue, but I still think that creating a new request makes the most sense. There's no real way for us to have a reset option. So creating a new request and going through the voting process again is really the best choice. We'll have the strongest signal there. We don't expect most of these requests to receive new open issues. If you feel strongly about this feature, please do create a new feature request issue.

  20. gkalpak commented on Jun 25, 2022

    @gkalpak
    Member

    By design, the Angular Service worker does not support tweaking/disabling specific features - it was designed to be a drop-in SW and is necessarily limited in its functionality/configurability as a result.

    We have #21197 to consider adding custom extension points, but for now other service worker implementations (e.g. Workbox) are a better option for user-defined behavior in the SW.

    For really simple cases, such as disabling a specific event, you could also define your own service worker script that imports ngsw-worker.js at the end and add an event listener for the event you want to disable that prevents propagation of the events to over listeners (such as those defined in ngsw-worker.js.

    I.e. something like:

    // my-sw.js
    self.addEventListener('push', evt => evt.stopImmediatePropagation());
    importScripts('./ngsw-worker.js')

    I am going to close this issue, since we do not intend to provide the option of disabling/modifying specific events in the near future. In the meantime, let's use #21197 to track adding custom extensions points in general.

  21. angular-automatic-lock-bot commented on Jul 26, 2022

    @angular-automatic-lock-bot

    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.

  22. locked and limited conversation to collaborators on Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: service-workerIssues related to the @angular/service-worker packageeffort2: daysfeatureLabel used to distinguish feature request from other issues

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions