Skip to content

Support setting Application Badge from Service workers #53920

@edvinv

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: service-workerIssues related to the @angular/service-worker packagefeatureIssue that requests a new featurefeature: votes requiredFeature request which is currently still in the voting phase

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions