Implement proof of concept push notifications

This commit is contained in:
Hornwitser 2025-02-28 15:32:03 +01:00
parent e3210afe3a
commit 6007f4caeb
13 changed files with 407 additions and 1 deletions

25
public/sw.js Normal file
View file

@ -0,0 +1,25 @@
self.addEventListener("push", function (event) {
console.log(event);
if (!event.data)
return;
const payload = event.data.json();
const { body, icon, image, badge, url, title } = payload;
const notificationTitle = title ?? "No title";
const notificationOptions = {
body,
icon,
image,
data: {
url,
},
badge,
};
event.waitUntil(
self.registration.showNotification(notificationTitle, notificationOptions)
.then(() => {
console.log("Web push delivered");
})
);
});