groupe-meditation/frontend/public/push-sw.js

24 lines
664 B
JavaScript

self.addEventListener('push', (event) => {
let data = {};
if (event.data) {
try {
data = event.data.json();
} catch {
data = { title: 'App', body: event.data.text() };
}
}
const title = data.title || 'App';
const options = {
body: data.body || 'Nouvelle notification',
icon: '/icon-192.png',
badge: '/icon-192.png',
data: { url: data.url || '/' },
};
event.waitUntil(self.registration.showNotification(title, options));
});
self.addEventListener('notificationclick', (event) => {
event.notification.close();
const url = event.notification.data?.url || '/';
event.waitUntil(clients.openWindow(url));
});