不会为远程通知触发 notificationclick

notificationclick is not fired for remote notifications

我在我的 Service Worker 中使用 self.addEventListener('notificationclick', function(event) {}) 来监听点击通知

The notificationclick event is fired to indicate that a system notification spawned by ServiceWorkerRegistration.showNotification() has been clicked.

当我使用 ServiceWorkerRegistration.showNotification 并单击通知时它触发了侦听器,但是当我有一个远程通知时它没有被触发,我必须从服务器设置 actions 如果用户单击操作按钮它触发,但如果点击通知本身,则不会触发

有什么解决方法吗?

firebase-messaging.js 有以下代码。

self.addEventListener("notificationclick", function(event) {
  event.stopImmediatePropagation();
  event.notification.close();

在加载库之前定义我的通知点击函数。

self.addEventListener("notificationclick", function(event) {
  console.log('notification open');
  // log send to server
});

importScripts('https://www.gstatic.com/firebasejs/8.6.2/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/8.6.2/firebase-messaging.js');

firebase.initializeApp({
  'messagingSenderId': 'xxxxx'
});
const messaging = firebase.messaging();