31 lines
877 B
JavaScript
Raw Normal View History

2025-02-01 21:22:40 +00:00
self.addEventListener("install", (event) => {
console.log("Service worker installed");
});
self.addEventListener("push", (event) => {
if (!(self.Notification && self.Notification.permission === "granted")) {
return;
}
console.log("Received a push message", event);
const data = event.data?.json() ?? {};
const title = data.title || "Something Has Happened";
const message =
data.message || "Here's something you might want to check out.";
const icon = "images/new-notification.png";
event.waitUntil(self.registration.showNotification(title, {
body: message,
tag: "simple-push-demo-notification",
icon,
}));
});
self.addEventListener("notificationclick", (event) => {
console.log("Notification click Received.", event);
event.notification.close();
event.waitUntil(clients.openWindow(
"https://molodetz.nl",));
});