admin管理员组文章数量:1024206
I'm trying to make an extremely simple chrome extension that alerts something when you click a button, but it's not working. I'm getting the following error:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
Can anyone help? This is what I have right now:
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"
}
}
I'm trying to make an extremely simple chrome extension that alerts something when you click a button, but it's not working. I'm getting the following error:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
Can anyone help? This is what I have right now:
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"
}
}
Share
Improve this question
asked Oct 11, 2014 at 22:06
DavidDavid
7331 gold badge7 silver badges21 bronze badges
2 Answers
Reset to default 4The problem is here
<script> src = "popup.js" </script>
To include the js file use
<script src="popup.js"></script>
This error will happen when you try to put inline Javascript in your files. Chrome extensions plain about that.
You would get the same error message if you were to try
<script> alert("hello world"); </script>
From Google Chrome extension documentation
Inline JavaScript will not be executed. This restriction bans both inline blocks and inline event handlers (e.g. <button onclick="...">).
This also means that your inline event handler is not going to work, you have to bind the event dynamically instead, in your popup.js script:
document.getElementById("the_button").addEventListener("click", function()
{
// click code here
}, false);
<script> src = "popup.js" </script>
should be
<script src="popup.js"></script>
I think...
I'm trying to make an extremely simple chrome extension that alerts something when you click a button, but it's not working. I'm getting the following error:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
Can anyone help? This is what I have right now:
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"
}
}
I'm trying to make an extremely simple chrome extension that alerts something when you click a button, but it's not working. I'm getting the following error:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
Can anyone help? This is what I have right now:
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"
}
}
Share
Improve this question
asked Oct 11, 2014 at 22:06
DavidDavid
7331 gold badge7 silver badges21 bronze badges
2 Answers
Reset to default 4The problem is here
<script> src = "popup.js" </script>
To include the js file use
<script src="popup.js"></script>
This error will happen when you try to put inline Javascript in your files. Chrome extensions plain about that.
You would get the same error message if you were to try
<script> alert("hello world"); </script>
From Google Chrome extension documentation
Inline JavaScript will not be executed. This restriction bans both inline blocks and inline event handlers (e.g. <button onclick="...">).
This also means that your inline event handler is not going to work, you have to bind the event dynamically instead, in your popup.js script:
document.getElementById("the_button").addEventListener("click", function()
{
// click code here
}, false);
<script> src = "popup.js" </script>
should be
<script src="popup.js"></script>
I think...
本文标签: javascriptWhat39s wrong with this simple chrome extensionStack Overflow
版权声明:本文标题:javascript - What's wrong with this simple chrome extension? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745588062a2157719.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论