forked from ziracms/zira
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
26 lines (22 loc) · 743 Bytes
/
sw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
self.addEventListener('push', function (event) {
if (!(self.Notification && self.Notification.permission === 'granted')) return;
const sendNotification = msg => {
const title = msg.title;
const options = {
body: msg.body,
icon: msg.icon,
data: {
url: msg.url
}
};
return self.registration.showNotification(title, options);
};
if (event.data) {
const message = event.data.json();
event.waitUntil(sendNotification(message));
}
});
self.addEventListener('notificationclick', function(event) {
event.notification.close();
event.waitUntil(clients.openWindow(event.notification.data.url));
});