我已将Chrome扩展程序配置为发送通知,如下所示:
我有一个按钮,其中有一个调用createNotification的事件。但是如果我在apache上运行扩展程序,按钮就会发送通知。
我做错了什么?
等于示例http://jsbin.com/ziwod/1/edit?html,js,output 对我来说,这个例子只是在我点击"用JS运行"。
时工作这是我的清单
{
"name": "EXTENSION EXAMPLE",
"version": "0.0.1",
"manifest_version": 2,
"description" : "This extension is...",
"icons": { "16": "icons/16x16.png", "48": "icons/48x48.png", "128": "icons/128x128.png" },
"omnibox": { "keyword" : "example" },
"browser_action": {
"default_icon": {
"19": "icons/19x19.png",
"38": "icons/38x38.png"
},
"default_title": "Launcher",
"default_popup": "browseraction/popup.html"
},
"background": {
"scripts": ["background.js"],
"persistent": false
},
"permissions" : ["notifications"],
"options_page" : "notification.html",
"chrome_url_overrides" : {
"newtab": "newtab/newtab.html"
},
"devtools_page": "devtools/devtools.html"
}
这是我的 notification.html http://codepen.io/anon/pen/VYWQwB
答案 0 :(得分:1)
从您的html文件和"manifest_version": 2
的清单文件中默认启用Content Security Policy。 Chrome开发人员选择严格控制并始终禁止使用内联JavaScript代码 - 只允许执行放置在外部JavaScript文件中的代码(以防止扩展中的跨站点脚本漏洞)。因此,您的html文件中不允许<button onclick="notifyMe()">
。 onclick
属性是内联脚本。您应该改为指定ID属性:<button id="button">
。