Skip to content

Support setting Application Badge from Service workers #53920

Closed as not planned
Closed as not planned

Description

@edvinv

Which @angular/* package(s) are relevant/related to the feature request?

service-worker

Description

Currently you can use Push notification for displaying notification messages. But it is not possible to change application badge from push notification when application is not started.
You can use setAppBadge from SwPush.messages, but this only works when application is already running.

Proposed solution

Support setting application badge natively in ngsw-worker.js. New push payload would look something like this:

{
  "notification": {
    "actions": NotificationAction[],
    ....
  },
  "appBadge": number | undefined
}

If appBadge property is not set nothing will happened, but if it is set, then inside "push" event, self.navigator.setAppBadge should be called with value of "appBadge". Setting "appBadge" to 0, will clear badge.

Alternatives considered

Now the only way to change application badge when application is offline is to use custom service worker to handle "push" event and then import ngsw-worker.js. But I'm not sure that even this will work on WebKit, because as stated in https://webkit.org/blog/14112/badging-for-home-screen-web-apps/ and if I understand correctly, both showNotification and setAppBadge must be 'promise' from same "push" event.

Activity

  1. KrishDevCrafting commented on Jan 15, 2024

    @KrishDevCrafting

    what the fuck is that

  2. added
    featureLabel used to distinguish feature request from other issues
    area: service-workerIssues related to the @angular/service-worker package
    on Jan 15, 2024
  3. added this to the Backlog milestone on Jan 15, 2024
  4. JeanMeche commented on Jan 15, 2024

    @JeanMeche
    Member

    On that topic, the setBadge function has only partial support ATM

  5. angular-robot commented on Jan 16, 2024

    @angular-robot
    Contributor

    This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

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

  6. JeanMeche commented on Aug 27, 2025

    @JeanMeche
    Member

    Per #63364, we won't be addressing this issue.

    The message is also visible here: https://angular.dev/ecosystem/service-workers

  7. angular-automatic-lock-bot commented on Sep 27, 2025

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

  8. locked and limited conversation to collaborators on Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: service-workerIssues related to the @angular/service-worker packagefeatureLabel 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