Solvedangular feat(service-worker): provide more options for notification click actions
✔️Accepted Answer
Not sure if you are still looking for a solution to this, but you could make your own service worker and import the cli built one into yours.
In ./src, create a sw.js
importScripts('./ngsw-worker.js');
self.addEventListener('notificationclick', (event) => {
//do something here
})
Then when you register your service worker in your app, use
ServiceWorkerModule.register('/sw.js', { enabled: environment.production })
and be sure to add it to the assets in angular.json
Other Answers:
Any progress on this? Is it now possible to click on a notification and open an URL?
Just to keep track of the current support of Notification#actions: https://web-confluence.appspot.com/#!/catalog?q=%22Notification%23actions%22
This workaround does not work anymore, self is undefined at this point and we can't get a reference to the service worker itself. Any news on this feature request? It is really needed.
Currently, clicking on a push notification emits a value on
SwPush#notificationClicks
. This is fine, but limited (e.g. when there is no app instance currently open).We need a way to provide more advanced configuration options wrt handling notification clicks.
Possible options off the top of my head:
If there are no open clients:
ServiceWorkerRegistration#scope
.Notification#data.url
(or some other property we agree on).Notification#data.urlPerAction
. Then we could look up the URL to open based on the action's name.If there are clients open:
Notification#data.url
orNotification#data.urlPerAction
).Alternatively, we could specify some operations per action according to some predefined convention. E.g.:
Originally posted by @gkalpak in #25860