Push notification 浏览器通知:未显示

Push notification 浏览器通知:未显示,push-notification,notifications,progressive-web-apps,Push Notification,Notifications,Progressive Web Apps,我似乎按照Google实验室的建议创建了serviceWorker,并编写了推送通知的代码,但它似乎没有出现。似乎来自服务器的推送事件确实到达了浏览器,但是忽略了showNotification功能 // in sw.js self.addEventListener('push', function(event) { console.log('Push Received'); // this shows up event.waitUntil(self.registration.showNot

我似乎按照Google实验室的建议创建了
serviceWorker
,并编写了
推送通知的代码,但它似乎没有出现。似乎来自服务器的推送事件确实到达了浏览器,但是忽略了
showNotification
功能

// in sw.js
self.addEventListener('push', function(event) {
 console.log('Push Received'); // this shows up
 event.waitUntil(self.registration.showNotification('Hello World'));
 // tried  self.registration.showNotification('Hello World') but still does not show up
});
为了进一步检查
showNotification
是否有效,我在
main.js
中添加了以下内容

//in main.js
console.log(Notification.permission) // shows granted
if (Notification.permission == 'granted') {
 console.log('will show notification') // this gets logged
 navigator.serviceWorker.getRegistration().then(function(reg) {
   Console.log('reached here'); // this too gets logged
   reg.showNotification('Hello world!');
 });
最后,我发现了这个网站,一些人用它进行测试

以及

在允许从这个站点发送通知后,我发现使用screen或给定的curl命令不会显示任何通知

我在Chrome和Firefox上都试过了,结果是一样的。我在MacOS10.13.6上使用Chrome68.x和Firefox61.x


我发现我正在使用的站点在Chrome设置(高级部分)中启用了通知。即使单击地址栏的
安全部分
也会显示通知已设置为
允许
。是否有其他我缺少的设置?谢谢,这真是个愚蠢的错误。Mac OS X的通知设置(我认为是默认设置)设置为“请勿打扰”。禁用显示推送通知的。想其他人,像我一样,可能没有意识到这一点应该知道

给Windows 10桌面用户的一些额外建议:

  • Not a-浏览器-通知-由
    self.registration.showNotification
    引起的通知将不会像您预期的那样显示在浏览器中。这些通知显示在Windows操作中心中

  • 焦点辅助-Windows中有一个“焦点辅助”设置(类似于上面提到的Apple设置),用于确定发送给Action Center的通知是静默的还是导致敬酒。它没有提到行动中心

  • 不止一种类型的“通知”只是为了让事情变得混乱,Windows的“通知”区域是一个不同但相关的功能。操作中心在任务栏通知区域中有一个图标。你可以

  • 双监视器-如果有多个监视器,则只能在主监视器的任务栏上看到“操作中心”图标。此外,您将只在主监视器上看到Action Center toast

  • 现有通知禁止toast-如果您站点的域已在操作中心中列出,您将不会看到新消息的其他toast。但是,您仍然可以在“操作中心”中看到站点创建的项目。清除该项,您的下一次通知将导致敬酒


我在这上面浪费了一个小时。如果没有这个答案,情况会更糟。非常感谢。