23 lines
668 B
JavaScript
23 lines
668 B
JavaScript
self.addEventListener("push", (event) => {
|
|
let data = { title: "Echoboard", body: "New activity on your watched content" };
|
|
try {
|
|
data = event.data.json();
|
|
} catch {}
|
|
|
|
event.waitUntil(
|
|
self.registration.showNotification(data.title, {
|
|
body: data.body,
|
|
icon: data.icon || "/favicon.ico",
|
|
data: { url: data.url },
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener("notificationclick", (event) => {
|
|
event.notification.close();
|
|
const raw = event.notification.data?.url || "/";
|
|
const safe = new URL(raw, self.location.origin);
|
|
const url = safe.origin === self.location.origin ? safe.href : "/";
|
|
event.waitUntil(clients.openWindow(url));
|
|
});
|