打包应用中的Chrome通知."chrome.notifications.create"

Bly*_*ynn 1 javascript google-chrome-app

这是我的代码.我不确定这是否应该有效.

$('#save').bind('click', function(e){

var opt = {
    type: "basic",
    title: "Deploy",
    message: "It worked!"
  };
chrome.notifications.create("", opt, function(id) {});
});
Run Code Online (Sandbox Code Playgroud)

我已将权限设置为使用通知,因此我认为这不是问题.

Xan*_*Xan 7

请注意,该文件列出了iconUrl作为一个必需的选项optchrome.notifications.create.

因此,假设您将图片添加icon.png到扩展程序的根目录.然后您的代码可以像这样修改:

var opt = {
   type: "basic",
   title: "Deploy",
   message: "It worked!",
   iconUrl: "icon.png"
};
chrome.notifications.create("", opt, function(id) {
   if(chrome.runtime.lastError) {
     console.error(chrome.runtime.lastError.message);
   }
});
Run Code Online (Sandbox Code Playgroud)

这应该有效,如果通知有任何问题,您将在控制台中收到通知.