如何处理Push Notifications服务工作人员中的PushSubScriptionChange事件?

发布于 2025-02-09 10:08:05 字数 983 浏览 0 评论 0原文

我们如何更新Chrome中的订阅?截至今天,Chrome不听PushNotificationChange事件。因此,下面的代码在Chrome的情况下不起作用。

从:

self.addEventListener('pushsubscriptionchange', function(event) {
  event.waitUntil(
    fetch('https://pushpad.xyz/pushsubscriptionchange', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        old_endpoint: event.oldSubscription ? event.oldSubscription.endpoint : null,
        new_endpoint: event.newSubscription ? event.newSubscription.endpoint : null,
        new_p256dh: event.newSubscription ? event.newSubscription.toJSON().keys.p256dh : null,
        new_auth: event.newSubscription ? event.newSubscription.toJSON().keys.auth : null
      })
    })
  );
});

” : https://bugs.chromium.chromium.orgs.org/p/chromium/sissues/sissues/sissues /细节?id = 753163

How can we update subscription in chrome? As of today chrome does not listen to pushnotificationchange event. So code below will not work in case of chrome.

code taken from: https://pushpad.xyz/service-worker.js

self.addEventListener('pushsubscriptionchange', function(event) {
  event.waitUntil(
    fetch('https://pushpad.xyz/pushsubscriptionchange', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        old_endpoint: event.oldSubscription ? event.oldSubscription.endpoint : null,
        new_endpoint: event.newSubscription ? event.newSubscription.endpoint : null,
        new_p256dh: event.newSubscription ? event.newSubscription.toJSON().keys.p256dh : null,
        new_auth: event.newSubscription ? event.newSubscription.toJSON().keys.auth : null
      })
    })
  );
});

Chrome issue link: https://bugs.chromium.org/p/chromium/issues/detail?id=753163

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文