我正在构建一个chrome扩展。当我在本地测试它时,我可以采取一些导致违反CSP的操作:
Refused to run the JavaScript URL because it violates the following Content Security Policy directive: "script-src https://apis.google.com 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.但是,我的代码没有任何内联javascript!error console将我的HTML的第一行(即<!DOCTYPE html> )指向罪魁祸首:
Stack Trace
html/popup.html:1 (anonymous function)
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=600, height=600, initial-scale=1.0">
<link rel="stylesheet" href="../css/bootstrap-3.3.7-dist/css/bootstrap.min.css">
<link rel="stylesheet" href="../css/font-awesome-4.7.0/css/font-awesome.min.css">
<script src="https://apis.google.com/js/api.js"></script>
<script src="../go/go.js"></script>
</head>
<body style="width: 500px; height: 600px">
<div> ...文档中没有其他<script>标记。使用gopherjs从golang编译go.js文件。
怎么一回事?如何找出导致此CSP违规的原因?
发布于 2019-03-13 03:36:13
<script src="https://apis.google.com/js/api.js"></script>这就是原因。在您的manifest.json中,尝试添加以下内容:
"content_security_policy": "script-src 'self' 'unsafe-eval' https://apis.google.com; object-src 'self'",https://stackoverflow.com/questions/55129255
复制相似问题