9

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)
  );
})
dewraj singh
  • 128
  • 1
  • 10

3 Answers3

7

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.

Solrac
  • 924
  • 8
  • 23
  • 1
    I tried all short of option earlier, however it seems working now, not to sure if some chrome update resolved, but thank you for input Solrac. – dewraj singh Feb 13 '19 at 14:56
  • NOT working at ALL, something is really wrong. Every document says something, but there must be some critical thing missing. – CodingTT Sep 07 '22 at 22:13
1

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/"
      }
  }
Maheshvirus
  • 6,749
  • 2
  • 38
  • 40
-1

Turn off your adblocker! Spent 2 hours trying to debug this.After that try registering your service worker again.