I am using Google Web Starter kit and notification can be shown using service worker.
navigator.serviceWorker.getRegistration().then(function(reg) {
var options = {
body: body
};
reg.showNotification(title, options);
});
I would like to detect notificationclick event using the service worker.
notification behaviour article states that:
To achieve this we need to add a 'notificationclick' event listener to our service worker.
I tried the following:
navigator.serviceWorker.addEventListener('notificationclick', function() {
console.log('notificationclick event called');
});
But it doesn't seem to work. Where should the event listener be added?