我正在创建Chrome扩展程序,但我在使用通知 webkit时遇到了一些困难。当我尝试显示通知时,会抛出异常:
未捕获错误:SecurityError:DOM异常18
Bellow关注我的 Javascript代码:
var icon = 'icon_48.png';
var title = 'Test Plugin';
var body = message;
var popup = window.webkitNotifications.createNotification(icon, title, body);
popup.show();
Bellow跟随我的 manifest.json :
{
"name": "Test Plugin",
"version": "1.0.6",
"manifest_version": 2,
"description": "This is a test",
"browser_action": {
"default_icon": "images/icon_32.png",
"default_popup": "popup.html"
},
"icons": {
"128": "images/icon_128.png",
"16": "images/icon_32.png",
"48": "images/icon_48.png"
},
"permissions": [
"http://*/*",
"https://*/*",
"contextMenus",
"tabs",
"notifications",
"management",
"webRequest"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["webtoolkit-sha1.js","content.js"],
"run_at": "document_end",
"css" : ["css/style.css"]
}
],
"web_accessible_resources": ["webtoolkit-sha1.js","inject.js","icon_48.png"]
}
我做错了什么?
谢谢大家!
信息更新:
manifest.json在权限部分中有通知属性,但是当我打印 webkitNotifications.checkPermission()时,结果为1(PERMISSION_NOT_ALLOWED )。
答案 0 :(得分:1)
notifications
权限仅适用于扩展程序。为了使您的代码有效,需要添加background(或event)页面,以创建通知。内容脚本可以使用messaging API来请求通知。