2021-08-22 21:22:47 +00:00
|
|
|
// This file should be served from the web root to avoid scope and cookie related issues with some browsers
|
|
|
|
self.addEventListener('install', function(e) {
|
|
|
|
console.log('install event');
|
|
|
|
});
|
|
|
|
|
|
|
|
self.addEventListener('fetch', function(e) {
|
|
|
|
// nothing here yet
|
2021-12-02 23:02:31 +00:00
|
|
|
|
2021-08-22 21:22:47 +00:00
|
|
|
});
|
2023-11-10 22:53:33 +00:00
|
|
|
|
|
|
|
self.addEventListener('push', function (event) {
|
|
|
|
if (!(self.Notification && self.Notification.permission === 'granted')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const sendNotification = body => {
|
|
|
|
// you could refresh a notification badge here with postMessage API
|
|
|
|
const title = "";
|
|
|
|
|
|
|
|
return self.registration.showNotification(title, {
|
|
|
|
body,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
if (event.data) {
|
|
|
|
const payload = event.data.json();
|
|
|
|
event.waitUntil(sendNotification(payload.message));
|
|
|
|
}
|
|
|
|
});
|