即使在 serviceworker.js 的 addEventListener 中注册,notificationclick 也不会在 chrome 中触发

dew*_*ngh 6 javascript web-notifications service-worker

我正在为我的网站启用 Web 通知,并将下面的事件侦听器添加到 service worker .js 文件中,这在边缘运行良好,单击事件被触发并打开一个新窗口,但是 chrome 没有任何反应并且事件本身不会触发 -

self.addEventListener('notificationclick', function (event) {
  event.notification.close();
  console.log('Notification notificationclick triggered');
  event.waitUntil(
    clients.openWindow(event.notification.data)
  );
})
Run Code Online (Sandbox Code Playgroud)

Sol*_*rac 7

刚刚在 Chrome 上测试了它,它按预期工作:

self.addEventListener('notificationclick', function (event) {
  clients.openWindow("/");
});
Run Code Online (Sandbox Code Playgroud)

使用 Chrome 开发者窗口取消注册 Service Worker,然后找到“应用程序”选项卡。您将能够更新或取消注册该特定服务。

看起来您需要这样做才能不时查看对文件所做的更改。也许是浏览器缓存之类的。