20 lines
517 B
JavaScript
20 lines
517 B
JavaScript
|
/* nonshy service worker, for web push notifications */
|
||
|
|
||
|
self.addEventListener('install', (event) => {
|
||
|
self.skipWaiting();
|
||
|
});
|
||
|
|
||
|
self.addEventListener('push', (event) => {
|
||
|
const payload = JSON.parse(event.data.text());
|
||
|
try {
|
||
|
event.waitUntil(
|
||
|
self.registration.showNotification(payload.title, {
|
||
|
body: payload.body,
|
||
|
icon: "/static/img/favicon-192.png",
|
||
|
})
|
||
|
);
|
||
|
} catch(e) {
|
||
|
console.error("sw.showNotification:", e);
|
||
|
}
|
||
|
});
|