Javascript 当选项卡处于焦点时单击Firebase web推送通知onclick

Javascript 当选项卡处于焦点时单击Firebase web推送通知onclick,javascript,firebase,push-notification,firebase-cloud-messaging,web-push,Javascript,Firebase,Push Notification,Firebase Cloud Messaging,Web Push,我正在寻找一种方法,当应用程序位于前台且选项卡处于焦点时,处理应用程序上的onclick事件 我有这个: self.addEventListener('notificationclick', function(event) {.... 在我的服务人员文件firebase messaging sw.js中,但这仅在应用程序位于后台或未处于焦点时才会触发。我想这就是它的工作原理 之前我是这样做的: const options = { body: notification

我正在寻找一种方法,当应用程序位于前台且选项卡处于焦点时,处理应用程序上的
onclick
事件

我有这个:

self.addEventListener('notificationclick', function(event) {....
在我的服务人员文件
firebase messaging sw.js
中,但这仅在应用程序位于后台或未处于焦点时才会触发。我想这就是它的工作原理

之前我是这样做的:

const options = {
              body: notification.body,
              click_action: notification.data.click_action,
              data: notification.data,
              tag: tag
            };

const notif = new Notification(notification.title, options);

notif.onclick = function() {
    alert('sdfsdf'); // working FINE
};
// v = ServiceWorkerRegistration

v.getNotifications({ tag: tag })
         .then(function(notificationsList) {
            if( notif = notificationsList[0] ) {
              console.log("notif: ", notif);

              notif.onclick = function() {
                  alert('new notif');
                };
            }
  });
然而,
新通知
在基于Android的浏览器(如chrome、brave、firefox等)中似乎根本不起作用

现在我用这个:

navigator.serviceWorker.getRegistrations().then(function() { ....
找到我的服务人员注册(
ServiceWorkerRegistration
interface)并在其上调用
showNotification
方法,该方法跨平台运行良好

但是如何绑定
showNotification
生成的
onclick
上的
Notification

我试着这样做:

const options = {
              body: notification.body,
              click_action: notification.data.click_action,
              data: notification.data,
              tag: tag
            };

const notif = new Notification(notification.title, options);

notif.onclick = function() {
    alert('sdfsdf'); // working FINE
};
// v = ServiceWorkerRegistration

v.getNotifications({ tag: tag })
         .then(function(notificationsList) {
            if( notif = notificationsList[0] ) {
              console.log("notif: ", notif);

              notif.onclick = function() {
                  alert('new notif');
                };
            }
  });
onclick
得到绑定,但仍然不起作用

我可能遗漏了什么