打包应用中的 Chrome 通知“Chrome.notifications.create”

Chrome Notification in a packaged app. "chrome.notifications.create"

本文关键字:Chrome 通知 notifications create 包应用 应用      更新时间:2023-09-26

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

$('#save').bind('click', function(e){
var opt = {
    type: "basic",
    title: "Deploy",
    message: "It worked!"
  };
chrome.notifications.create("", opt, function(id) {});
});

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

请注意

,文档将iconUrl列为chrome.notifications.createopt必需选项

因此,假设您将图片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);
   }
});

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