I'm enabling web notification to my web site and added below event listener to service worker .js file, This works fine in edge and click event gets trigger and opens a new window, however chrome nothing happens and event it self does not trigger -
self.addEventListener('notificationclick', function (event) {
event.notification.close();
console.log('Notification notificationclick triggered');
event.waitUntil(
clients.openWindow(event.notification.data)
);
})
Just tested it on Chrome and its working as intended:
self.addEventListener('notificationclick', function (event) {
clients.openWindow("/");
});
Unregister your Service Worker using the Chrome devs window then find the Application tab. You would be able to update or unregister that particular service.
Looks like you need to do that in order to see the changes you made to the file from time to time. Maybe browser cache or so.
You can use data object in place of notification.
eg.
{
"to": "pass token here",
"data":{
"title": "Hello",
"body": "Good Evening",
"click_action":"https://stackoverflow.com/"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With