编写了我的第一个chrome扩展名,并且在内容政策上遇到了一些困难。即使删除了我认为引起问题的内联事件,我仍然收到内联事件错误。现在,我想使此警报正常工作。这是代码减去无关信息。
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="js/popup.js"></script>
<title>Placeholder popup</title>
</head>
<body>
<form action="">
<label for="numWeeks">Nombre de semaines :</label>
<input type="number" id="numWeeks" name="numWeeks"></input>
<button type="submit">Submit</button>
</form>
</body>
</html>
popup.js:
var myAlert = function() {
alert("Hello World!");
//event listener for click of the button
if (document.getElementById('submit') != null) {
document.getElementById('download').addEventListener('click', myAlert);
}
}
manifest.json:
{
"background": {
"persistant": false
},
"browser_action": {
"default_popup": "popup.html"
},
"content_scripts": [ {
"js": ["some scripts, popus.js is not in this line],
} ],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"key": "placeholderPublicKey",
"manifest_version": 2,
"name": "__MSG_extName__",
"options_ui": {
"open_in_tab": true,
"page": "description.html"
},
"version_name": "alpha0",
"version":"1.0",
"web_accessible_resources": [ ]
}
使用此代码,我继续看到:“拒绝执行内联事件处理程序,因为它违反了以下内容安全策略指令:“ script-src'self''unsafe-eval'”。'unsafe-inline'关键字,散列('sha256 -...')或随机数('nonce -...')才能启用内联执行。”我删除了以前的onclick(),并认为应该可以解决此问题。 任何帮助表示赞赏!