2017-08-30 86 views
0

我在尝试发送推送通知时遇到Opera Desktop Browser 47的问题。Opera推送通知 - 无法触发notificationclick事件

虽然通知正确传递,但我无法触发'notificationclick'事件。控制台中也没有任何东西。

服务人员:(SW片段已采样测试数据)

self.addEventListener('push', function(event) { 

event.waitUntil(self.registration.pushManager.getSubscription().then(function(o) { 
     if (event.data) { 
      console.log(event.data); 
      var json=event.data.json(); 
      var notifs = []; 
      const title = 'Sample Opera Title'; 
      const options = { 
       body: 'Body of push notification', 
      }; 
      payload_notifs.push(self.registration.showNotification(title, options)); 

      return Promise.all(notifs); 
     } 
    })); 
}); 

self.onnotificationclick = function(event) { 
    console.log('On notification click: ', event.notification.tag); 
    event.notification.close(); 
}; 

现在的事情是,当我把一个断点刚刚发出的通知后(不要让事件完成),通知正在交付,“通知点击”事件也在起作用。

这实际上很奇怪,因为在具有相同服务代码的其他浏览器上工作正常。

有没有人有想法?

回答

0

试试这个:

self.addEventListener('push', function(event) { 

event.waitUntil(self.registration.pushManager.getSubscription().then(function(o) { 
     if (event.data) { 
      console.log(event.data); 
      var json=event.data.json(); 
      var notifs = []; 
      const title = 'Sample Opera Title'; 
      const options = { 
       body: 'Body of push notification', 
      }; 
      payload_notifs.push(self.registration.showNotification(title, options)); 

      Promise.all(notifs); 
     } 
    })); 
}); 

self.onnotificationclick = function(event) { 
    console.log('On notification click: ', event.notification.tag); 
    event.notification.close(); 
}; 

删除return,歌剧是古怪做一些事情。