javascript - chrome notifications unsubscribe event - Stack Overflow

Is it possible to catch unsubscribe event ?This is the code im using to subscribe the user to the notif

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

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 ?

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

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 ?

Share Improve this question edited Apr 27, 2018 at 18:59 Tarun Lalwani 147k11 gold badges213 silver badges276 bronze badges asked Feb 11, 2018 at 8:02 lior rlior r 2,3007 gold badges44 silver badges82 bronze badges 4
  • Hi, I'm also looking to this because to many entries in DB, after manualy subscribing back new entry is created. – SergkeiM Commented Apr 27, 2018 at 11:24
  • When I go to chrome://settings/content/notifications and remove your site’s permission to show notifications from there, I don’t even need to currently have your site itself loaded in my browser at that point ... so I don’t see anyone who could catch that event even if it existed in that situation ... – C3roe Commented Apr 27, 2018 at 12:11
  • @CBroe Hi thank you for reply, but in this case how can I delete the endpoint attached to the user in my DB? because next time user will allow notifications I'm generating a new Endpoint, this makes 2 endpoint for the user (because they are always different). – SergkeiM Commented Apr 27, 2018 at 13:48
  • 1 May be this can help How to listen for web notification permission change – anshulk Commented May 1, 2018 at 16:02
Add a ment  | 

2 Answers 2

Reset to default 3

Your looking for the pushsubscriptionchange event

self.addEventListener('pushsubscriptionchange', function() {
  // remove the entry from DB
});

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 .... :)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744782796a4593441.html

相关推荐

  • javascript - chrome notifications unsubscribe event - Stack Overflow

    Is it possible to catch unsubscribe event ?This is the code im using to subscribe the user to the notif

    2天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信