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:
parent
191144839a
commit
9bc4247b4d
1 changed files with 10 additions and 2 deletions
|
|
@ -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))
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue