我试图做一个非常简单的Chrome扩展,当你点击一个按钮时会发出警告,但它不起作用。我收到以下错误:这个简单的Chrome扩展有什么问题?
拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“script-src”self'chrome-extension-resource:“。无论是“不安全内联”的关键字,散列(“SHA256 -...”),或者随机数(“随机数-...”)是必需的,以使内联执行。
任何人都可以帮忙吗?这就是我现在所拥有的:
popup.html
<html>
<body>
<input type = "button" id = "the_button" value = "My button" onclick = "sayHi()"></input>
</body>
<script> src = "popup.js" </script>
</html>
popup.js
function sayHi() {
alert("hi")
}
manifest.json的
{
"manifest_version": 2,
"name": "Test",
"description": "Test Extension",
"version": "1.0",
"icons": {
"48": "icon.png"
},
"permissions": [
"http://*/*",
"https://*/*"
],
"content_scripts": [{
"matches": ["http://*/*", "http://*/*"],
"js": ["jquery.js", "popup.js"]
}],
"browser_action": {
"default_title": "This is a test",
"default_icon": "icon.png",
"default_popup": "popup.html"
}
}
谢谢,但它似乎仍然不会o正在工作。我现在甚至没有出现错误。 – David 2014-10-11 22:12:49
@David内联事件处理程序也不起作用,请参阅更新。您可以获取元素并动态绑定事件。 – BrunoLM 2014-10-11 22:15:47