27 lines
678 B
JavaScript
27 lines
678 B
JavaScript
self.addEventListener('push', function (event) {
|
|
const data = event.data ? event.data.json() : {};
|
|
|
|
const title = data.title || 'Notificación';
|
|
const options = {
|
|
body: data.body || '',
|
|
icon: '/Imagenes/LogoSinFondochico.png',
|
|
badge: '/Imagenes/LogoSinFondochico.png',
|
|
data: {
|
|
url: data.url || '/'
|
|
}
|
|
};
|
|
|
|
event.waitUntil(
|
|
self.registration.showNotification(title, options)
|
|
);
|
|
});
|
|
|
|
self.addEventListener('notificationclick', function (event) {
|
|
event.notification.close();
|
|
|
|
const url = event.notification.data.url || '/';
|
|
|
|
event.waitUntil(
|
|
clients.openWindow(url)
|
|
);
|
|
}); |