26 lines
648 B
JavaScript
26 lines
648 B
JavaScript
self.addEventListener('push', function (event) {
|
|
if (event.data) {
|
|
const data = event.data.json()
|
|
const options = {
|
|
body: data.body,
|
|
icon: '/icon-192.png',
|
|
badge: '/badge.png',
|
|
data: {
|
|
url: data.url || '/'
|
|
},
|
|
actions: data.actions || []
|
|
}
|
|
|
|
event.waitUntil(
|
|
self.registration.showNotification(data.title, options)
|
|
)
|
|
}
|
|
})
|
|
|
|
self.addEventListener('notificationclick', function (event) {
|
|
event.notification.close()
|
|
event.waitUntil(
|
|
clients.openWindow(event.notification.data.url)
|
|
)
|
|
})
|