我試圖做一個非常簡單的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