admin管理员组文章数量:1392047
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
2 Answers
Reset to default 3Your 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 .... :)
本文标签: javascriptchrome notifications unsubscribe eventStack Overflow
版权声明:本文标题:javascript - chrome notifications unsubscribe event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744782795a2624814.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论