I have to hide a push notification after 1 minute. What should I do in my service worker to achieve this?
You can use the Notification.close() method. You can get the Notification object with ServiceWorkerRegistration.getNotifications.
For example:
self.addEventListener('push', event => {
event.waitUntil(
self.registration.showNotification('Title', {
body: 'Body.',
})
.then(() => self.registration.getNotifications())
.then(notifications => {
setTimeout(() => notifications.forEach(notification => notification.close()), 60000);
})
);
});
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