我有一个简单的调用chrome.notifications.create(id,options)函数,我已经检查了十次参数。
id参数是一个字符串。 options参数是这样的对象:
{type:"basic",message:"message",title:"message",iconUrl:chrome.extension.getURL("icons/icon.png")}
它只适用于Firefox。 边缘 Opera和Chrome都无法显示通知。边缘只是崩溃了!
我检查了一切。没有错误,iconUrl是正确的。
我还检查了清单json的名称字段。没关系。 (Microsoft Edge notification in an extension)
样本相关简化代码
此简化版本与完整版本具有相同的问题。
//For hooking up event handlers
try {
chrome.runtime.onStartup.addListener(doHandshake);
}catch(ex) {
console.error("onStartup function in Edge is not supported.");
}
chrome.webRequest.onBeforeRequest.addListener(onBeforeRequestCallback, { types:['main_frame'],urls:['*://*/*']}, ['blocking']);
function onBeforeRequestCallback(requestDetails) {
showMessage();
return {};
}
function showMessage() {
console.log("about to show notification...");
var notificationOptions ={type:"basic",message:"msg",title:"title",iconUrl:chrome.extension.getURL("icons/icon.png")};
chrome.notifications.create("",notificationOptions);
}
manifest.json
{
"manifest_version": 2,
"author" : "whatever Ltd.",
"name": "21charsName",
"version": "1.0",
"description": "whatever",
"permissions": [
"*://*/*",
"tabs",
"webRequest",
"webRequestBlocking",
"storage",
"notifications"
],
"browser_action": {
"default_icon": "icons/icon.png",
"default_title": "extension"
},
"background": {
"scripts": [
"background.js"
],
"persistent": true
},
"web_accessible_resources": []
}