Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome notifications unsubscribe event

Is it possible to catch unsubscribe event ?

This is the code im using to subscribe the user to the notifications

if ('serviceWorker' in navigator) {
    navigator.serviceWorker.ready.then(function(reg) {
      reg.pushManager.subscribe({
        userVisibleOnly: true
      }).then(function(sub) {
          add_endpoint_to_db( sub ); // im adding the user deatils to my db
      }).catch(function(e) {
        if (Notification.permission === 'denied') {

        } else {

        }
      });
  });

}

In case the user chooses to manually remove the notifications

Notification removal

I want to catch the action in order to remove his entry from the DB

So is it possible to catch the notifications change event ?

like image 850
lior r Avatar asked Feb 11 '18 08:02

lior r


2 Answers

Unsubscribe is browser setting that can be done by settings tab and offline mode so you cannot get that information

But Once the user has unsubscribed (i.e. deleted the service worker registration), then on sending the next message you should get a failure message from the FCM API.(if you are using firebase)

So think in this way .... :)

like image 107
Jameel Grand Avatar answered Sep 27 '22 16:09

Jameel Grand


Your looking for the pushsubscriptionchange event

self.addEventListener('pushsubscriptionchange', function() {
  // remove the entry from DB
});
like image 42
Anu Avatar answered Sep 27 '22 15:09

Anu