This commit is contained in:
Dobromir Popov
2024-04-08 13:32:41 +03:00
parent 5c9fd9d0f5
commit 02661d6c8c
2 changed files with 8 additions and 1 deletions

View File

@ -1,6 +1,12 @@
'use strict'
console.log('Service Worker Loaded...')
self.addEventListener('push', function (event) {
console.log('Push message', event)
if (!(self.Notification && self.Notification.permission === 'granted')) {
return
}
const data = JSON.parse(event.data.text())
event.waitUntil(
registration.showNotification(data.title, {
@ -11,6 +17,7 @@ self.addEventListener('push', function (event) {
})
self.addEventListener('notificationclick', function (event) {
console.log('Notification click: tag', event.notification.tag)
event.notification.close()
event.waitUntil(
clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function (clientList) {