Chrome.notifications.create 不起作用,抛出 lastError



我无法让 chrome 扩展程序通知正常工作。

我相信它有所有必需的部分,lastError 在控制台(未定义)中没有抛出任何错误。图标文件也存在。我还在清单中添加了web_accessible_resources,但在这种情况下似乎无关紧要。

manifest.json 的一部分:

"web_accessible_resources": [
    "icon.png"
],
"permissions": [
    "storage",
    "notifications"
]

部分选项.js:

function resetTotal() {
chrome.storage.sync.set({'total':0}, function(){
    var opt = {
        type: "basic",
        title: "Total reset",
        message: "Total has been reset back to 0.",
        iconUrl: "icon.png"
    }
    chrome.notifications.create('reset', opt, function(){console.log("last error: ", chrome.runtime.lastError)});
});
resetButton.addEventListener("click", resetTotal, false);

检查您是否在Windows中启用了Google Chrome通知。转到"通知和操作">配置并启用通知。如果仍然不显示,请尝试更改通知的 ID。可能是它显示过一次,但不再显示,因为您尚未单击它。尝试在屏幕右下角的通知中心单击它。

最新更新