Files
buzz-sheet/public/commission-push-sw.js
gunshiz 5812d99715
CI / Verify (push) Successful in 2m30s
CI / Build immutable images and deploy (push) Successful in 3m9s
feat : comment feature
2026-10-08 01:40:08 +07:00

23 lines
819 B
JavaScript

self.addEventListener("push", (event) => {
if (!event.data) return;
const message = event.data.json();
event.waitUntil(self.registration.showNotification(message.title, {
body: message.body,
icon: message.icon || "/icon.png",
tag: message.id,
data: { url: message.url },
}));
});
self.addEventListener("notificationclick", (event) => {
event.notification.close();
const url = new URL(event.notification.data.url, self.location.origin);
if (url.origin !== self.location.origin) return;
event.waitUntil((async () => {
const windows = await self.clients.matchAll({ type: "window", includeUncontrolled: true });
const existing = windows.find((client) => client.url === url.href);
if (existing) return existing.focus();
return self.clients.openWindow(url.href);
})());
});