Firebase 消息传递"the site has been updated in background"



我有问题。在我的服务辅助角色中收到通知时:

messaging.setBackgroundMessageHandler(function(payload) {
  console.log('[firebase-messaging-sw.js] Received background message ', payload);
  angularClient.postMessage(payload.data);
});

如何防止浏览器显示以下通知:

该网站已在后台更新

我所做的是向我的服务发送一条消息,其中将显示通知。目前,它显示两个通知。一个来自我的服务,很好,另一个说"该网站......".

当调用 onBackgroundMessage 时,您必须显示通知,并确保从 registration.showNotification('title', {body: 'message'}) 返回承诺

原因是 Web 推送不支持静默消息。

除了我自己创建的通知之外,我还收到了此通知。花了两天时间试图修复它。这是对我有用的代码:

self.addEventListener('push', async function(event) {
    event.waitUntil(
        self.registration.showNotification('title', {
          body: 'body'
        })
    );
});

最新更新