chrome.notification.create不在OS X上显示通知

时间:2017-06-15 04:43:36

标签: google-chrome-extension notifications

我开发了一个扩展程序,并使用Chrome API,该API每20秒从后台脚本发送一次通知

的manifest.json

{
  "name": "Test",
  "description": "Test",
  "manifest_version": 2,
  "version": "0.1",
  "chrome_url_overrides" : {
    "newtab": "register.html"
  },
  "background": {
    "scripts": ["background.js"]
  },
  "permissions": ["idle", "tabs", "gcm", "storage", "notifications"],
  "icons": { "128": "gcm_128.png" }
}

background.js //发送通知

  function messageReceived(message) {
    var messageString = '';
    if(message) messageString = message;
    var nid = getNotificationId();
    messageString = messageString + nid;

    // Pop up a notification to show the GCM message.
    chrome.notifications.create(nid, {
      title: 'Kukdu Kuuu',
      iconUrl: 'gcm_128.png',
      type: 'basic',
      message: messageString
    }, function() {});
  }

  // Returns a new notification ID used in the notification.
  function getNotificationId() {
    var id = Math.floor(Math.random() * 9007199254740992) + 1;
    return id.toString();
  }

  setInterval(function() {
    console.log('running - ');
    messageReceived('test notification ');
  }, 20000);

当我不在Chrome浏览器上时显示通知,即当我没有焦点时。但是当我处理chrome时,我没有收到通知。

当我运行API chrome.notifications.getAll()时,我获得了整个ID队列。

但是,通知不会立即显示在我的系统上。可能是什么问题呢?但是,它在Windows机器上运行良好。

1 个答案:

答案 0 :(得分:1)

这是chrome中的一个未解决的问题。

这是链接,

https://bugs.chromium.org/p/chromium/issues/detail?id=583746#

重要评论&总之,

  

这绝对是故意的,但这也是一个值得怀疑的决定。

     

Pro:*不会用电影中断电影等沉浸式内容   通知。

     

Con:*人们使用全屏来浏览,   ESP。在Mac上使用新的全屏模式。

     

(dewittj@chromium.org评论)

当前推送行为,

  

在全屏模式下排队收到通知。

     

当用户退出全屏模式或切换到其他应用或窗口时,它会显示所有通知。

     

如果用户退出浏览器,则会在下次浏览器重启时显示通知。