Chrome通知未从Chrome扩展程序后台页面显示

foot脚

使用新的chrome.notificationsAPI,我无法从扩展程序中收到通知以显示。即使最基本的通知也无法为我显示,但我没有收到任何错误,并且回调函数已正确执行。

manifest.json

{
  "name": "notify",
  "version": "0.0.0",
  "manifest_version": 2,
  "permissions": [
    "notifications"
  ],
  "background": {
    "scripts": ["main.js"]
  }
}

main.js

window.addEventListener('load', function() {
  var opt = {
    type: 'list',
    title: 'Primary Title',
    message: 'Primary message to display',
    priority: 1,
    items: [{ title: 'Item1', message: 'This is item 1.'},
            { title: 'Item2', message: 'This is item 2.'},
            { title: 'Item3', message: 'This is item 3.'}]
  };
  chrome.notifications.create('notify1', opt, function() { console.log('created!'); });
});

检查背景页面时,可以看到“已创建!” 在控制台中,但我从未在桌面上收到通知。我尝试了一堆不同的优先级值无济于事。我究竟做错了什么?

贾斯汀

不幸的是,由于我尚未诊断出一个错误,因此从控制台抑制了有关chrome.notifications的详细错误消息。未显示您的通知的原因是,该通知未提供必需的“ iconUrl”参数。当我在扩展程序的后台页面中尝试以下操作时,我已经安装了:

var opt = {
  iconUrl: "http://www.google.com/favicon.ico",
  type: 'list',
  title: 'Primary Title',
  message: 'Primary message to display',
  priority: 1,
  items: [{ title: 'Item1', message: 'This is item 1.'},
        { title: 'Item2', message: 'This is item 2.'},
          { title: 'Item3', message: 'This is item 3.'}]
};
chrome.notifications.create('notify1', opt, function() { console.log('created!'); });

通知创建成功。检查chrome.runtime.lastError是值得的:

var opt = {
    type: 'list',
    title: 'Primary Title',
    message: 'Primary message to display',
    priority: 1,
    items: [{ title: 'Item1', message: 'This is item 1.'},
            { title: 'Item2', message: 'This is item 2.'},
            { title: 'Item3', message: 'This is item 3.'}]
  };
  chrome.notifications.create('notify1', opt, function(id) { console.log("Last error:", chrome.runtime.lastError); });

这将向您显示实际上是必需的属性,而缺少一个。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

google chrome扩展程序:: console.log()从后台页面开始?

在Chrome扩展程序中显示通知

Chrome扩展程序后台页面无效,使该扩展程序只需点击两次即可运行

Chrome扩展程序后台脚本中的AngularJS

我可以在带有Chrome扩展程序的Chrome中禁用“您已全屏显示”通知吗?

Chrome扩展程序后台页面和内容脚本同步

chrome扩展程序-将数据从后台传递到自定义html页面

在Chrome扩展程序后台页面之间无法正确传递消息

Chrome扩展程序:存在参数时显示通知

Chrome扩展程序在页面操作中显示弹出窗口

Chrome扩展程序:URL更新时调用后台

从Google Chrome扩展程序调用页面功能

在Chrome扩展程序后台脚本上接收CORS策略

使用Chrome扩展程序淡出整个页面

我的Chrome扩展程序在扩展程序页面中未显示48x48图标

点击事件在Chrome扩展程序的“后台”页面中不起作用

Chrome扩展程序后台页面以编程方式注入的内容脚本多次注入

Chrome扩展程序中的数据未从弹出窗口传递到后台

Chrome扩展程序-通知

Chrome扩展程序通知未显示contextMessage吗?

弹出式窗口中的Chrome扩展程序后台页面

Chrome扩展程序:仅在页面上显示图像(无文本)

无法在Chrome扩展程序中从后台页面向内容脚本发送消息

Chrome扩展程序-在全屏视频顶部显示自定义通知/弹出窗口(HTML元素)

如何在Chrome扩展程序中动态运行后台脚本?

Chrome 扩展程序 - 使用消息传递的后台页面表单提交。表单只提交一次

Chrome 扩展程序未从备份中恢复

每次加载页面时,如何从后台向 Chrome 扩展程序中的弹出窗口发送消息?

Chrome 扩展程序后台页面的“persistent”属性的默认值是多少?