Google chrome extension manifest.json文件中的CSP问题
当作为.crx加载时,我的第一个GC扩展的脚本无法工作。我已经检查了调试部分,这是我的错误: 拒绝执行内联事件处理程序,因为它违反了以下内容安全策略指令:“script src‘self’”。 popup.html:8 拒绝执行内联事件处理程序,因为它违反了以下内容安全策略指令:“script src‘self’”。 popup.html:9 因此,我猜错误来自manifest.json文件:Google chrome extension manifest.json文件中的CSP问题,google-chrome-extension,manifest,content-security-policy,Google Chrome Extension,Manifest,Content Security Policy,当作为.crx加载时,我的第一个GC扩展的脚本无法工作。我已经检查了调试部分,这是我的错误: 拒绝执行内联事件处理程序,因为它违反了以下内容安全策略指令:“script src‘self’”。 popup.html:8 拒绝执行内联事件处理程序,因为它违反了以下内容安全策略指令:“script src‘self’”。 popup.html:9 因此,我猜错误来自manifest.json文件: { "name": "LolKing Searcher", "version": "1.1", "ma
{
"name": "LolKing Searcher",
"version": "1.1",
"manifest_version": 2,
"description": "Search your LoL profile",
"content_security_policy": "script-src 'self' https://www.lolking.net/; object-src 'self'",
"permissions": [
"tabs",
"http://*/*/"
],
"content_scripts": [
{
"matches": ["http://*/*/","https://*/*/"],
"js": ["popup.js"]
}
],
"browser_action": {
"default_title": "LolKing Searcher",
"default_icon": "icon.png",
"default_popup": "popup.html"
}
}
而且每一个建议都被广泛接受 错误,正如它在错误本身中所说的,在您的
popup.html
文件中。html文件中不能有任何内联代码,这些文件包括像onclick=“dosomething()”
这样的内联事件处理程序。将所有内联代码移动到外部文件
例如:
popup.html
<head>
<script src="popup.js"></script>
</head>
<body>
<input type="text" id="userText" placeholder="Enter Summoner's name" />
<input type="button" id="button" value="Search"/>
</body>
此外,您还需要删除
内容脚本部分,因为您试图将弹出代码注入到每一个没有任何意义的页面中。很抱歉,我应该将这些内联事件处理程序移动到js文件中吗?类似这样的吗?文件。添加的监听器(“onclick”,Check,false);我已经试过了,但它不起作用。document.getElementById(“按钮”).addEventListener(“onclick”,Check,false);你能再帮我一次吗?@GinoGinuzzi更新了你的代码,如果有任何问题,请告诉我。
window.onload = function(){
document.getElementById("button").addEventListener("click",check,false);
};
function check(){
var val = document.getElementById("userText").value;
if(val != ""){
var url="http://www.lolking.net/search?name=" + val;
chrome.tabs.create({url:url});
}
else
alert("Please enter a name");
}