I am attempting to display a notification and trigger an action when it is clicked.
try {
navigator.serviceWorker.getRegistration()
.then(reg => {
reg.showNotification("Check out the video clip!", {
body: "Click here!",
icon: "images/she_is_fire.png",
vibrate: [100, 50, 100],
tag: 'sample',
actions: [{ action: 'explore', title: 'Watch', icon: 'images/she_is_fire.png' }],
});
self.addEventListener('notificationclick', function(event) {
event.notification.close();
window.open("https://youtu.be/PAvHeRGZ_lA");
}, false);
})
.catch(err => alert('Service Worker registration error: ' + err));
} catch (err) {
alert('Notification API error: ' + err);
}
I have added the event listener, but it does not seem to be triggering. What could I be doing wrong?