1
0
Fork 0
mirror of https://github.com/imjasonh/webpush synced 2026-07-06 23:52:25 +00:00

log more, require interaction

Signed-off-by: Jason Hall <jason@chainguard.dev>
This commit is contained in:
Jason Hall 2025-11-24 18:47:50 -06:00
parent 191144839a
commit 9bc4247b4d

View file

@ -1,24 +1,32 @@
self.addEventListener('push', function(event) {
console.log('Push event received:', event);
let data = { title: 'Notification', body: '' };
if (event.data) {
try {
data = event.data.json();
console.log('Push data:', data);
} catch (e) {
data.body = event.data.text();
console.log('Push text:', data.body);
}
}
console.log('About to create notification options');
const options = {
body: data.body || '',
icon: data.icon || '',
badge: data.badge || '',
data: data.data || {},
requireInteraction: false
requireInteraction: true,
tag: 'push-notification-' + Date.now()
};
console.log('Showing notification with title:', data.title, 'options:', options);
event.waitUntil(
self.registration.showNotification(data.title || 'Notification', options)
.then(() => console.log('Notification shown successfully'))
.catch(err => console.error('Failed to show notification:', err))
);
});