为什么 Edge 扩展通知未定义 "create"?
Why is "create" undefined for Edge extension notifications?
运行 Edge 扩展中的代码抛出类型错误,无法获取 属性 'create' 未定义或空引用。
我已经尝试 运行在弹出窗口脚本和后台脚本中使用它。我在清单中有通知权限。我确实看到某些 API 需要在内容脚本中 运行,但由于我不参与标签或网页,我认为这不适用于我...?
清单:
{
"name": "xxx",
"author": "xxx", "version": "1.1",
"options_page": "options.html",
"background": {
"scripts": ["jquery-3.3.1.min.js","background.js"], "persistent": true
},
"permissions": [
"xxx",
"background",
"notifications",
"storage"
],
"offline_enabled": true,
"browser_action": {
"default_title": "xxx",
"default_popup": "popup.html",
"default_icon": "32.png"
},
"manifest_version": 2
}
后台脚本:
try{
browser.notifications.create("test",{
"type": "basic",
"title": "Test",
"iconUrl": "48.png",
"message": "This is a test"
});
}catch(e){
alert(e);
}
根据您的描述,您可以先尝试将Edge浏览器升级到最新版本,再尝试使用browser.notifications.create的方法。
但是,在我看来,我更喜欢使用 Web Notifications API 显示通知,您可以查看 this article。
运行 Edge 扩展中的代码抛出类型错误,无法获取 属性 'create' 未定义或空引用。
我已经尝试 运行在弹出窗口脚本和后台脚本中使用它。我在清单中有通知权限。我确实看到某些 API 需要在内容脚本中 运行,但由于我不参与标签或网页,我认为这不适用于我...?
清单:
{
"name": "xxx",
"author": "xxx", "version": "1.1",
"options_page": "options.html",
"background": {
"scripts": ["jquery-3.3.1.min.js","background.js"], "persistent": true
},
"permissions": [
"xxx",
"background",
"notifications",
"storage"
],
"offline_enabled": true,
"browser_action": {
"default_title": "xxx",
"default_popup": "popup.html",
"default_icon": "32.png"
},
"manifest_version": 2
}
后台脚本:
try{
browser.notifications.create("test",{
"type": "basic",
"title": "Test",
"iconUrl": "48.png",
"message": "This is a test"
});
}catch(e){
alert(e);
}
根据您的描述,您可以先尝试将Edge浏览器升级到最新版本,再尝试使用browser.notifications.create的方法。
但是,在我看来,我更喜欢使用 Web Notifications API 显示通知,您可以查看 this article。