4

Am following this project to add web push notifications using service-worker Push Notifications and ASP.NET Core and the complete project Demo.AspNetCore.PushNotifications. Everything works fine, my only problem here is that when I send 2 or more notifications only for the last notification received, On click fires (self.addEventListener('notificationclick', function (event) {...) in the service-worker. the rest they don't do nothing. how to make it work even for older notification (I think this happens only with chrome) ??

any help would be greatly appreciated

this is my service-worker.js :

const pushNotificationTitle = 'Demo.AspNetCore.PushNotifications';

self.addEventListener('push', function (event) {        
    event.waitUntil(self.registration.showNotification(pushNotificationTitle, {
        body: event.data.text(),
        icon: '/images/push-notification-icon.png'
    }));
});

self.addEventListener('notificationclick', function (event) {
    console.log('[Service Worker] Notification click Received.');

    event.notification.close();

    event.waitUntil(
        clients.openWindow('https://stackoverflow.com/')
    );
});

I send two or more notifications and put breakpoint in (self.addEventListener('notificationclick'). notificationclick event is only called when i click on the last notification received !!!!!!!!

Chmaykel
  • 41
  • 2

0 Answers0