website/web/static/js/service-worker.js
Noah Petherbridge a314aab7ec Web Push Notifications
* Add support for Web Push Notifications when users receive a new Message or
  Friend Request on the main website.
* Users opt in or out of this on their Notification Settings. They can also
  individually opt out of Message and Friend Request push notifications.
2024-07-20 19:44:22 -07:00

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);
}
});