我正在使用 jQuery simple whether 插件来获取是否并尝试创建一个 chrome 小部件。
将文件作为 chrome 扩展程序加载时,出现错误,在查看了 google 提供的所有帮助和此处的帮助后,我仍然无法解决此问题。
下面是雅虎的错误
> jquery-2.1.3.min.js:4 Refused to load the script
> 'https://query.yahooapis.com/v1/public/yql?format=json&rnd=2016437&diagnosti…ces(1)%20where%20text=%22New%20Delhi%22)%20and%20u=%22c%22&_=1462326587463'
> because it violates the following Content Security Policy directive:
> "script-src 'self' blob: filesystem: chrome-extension-resource:".
另一个关于字体的错误,
> Refused to load the font
> 'data:application/octet-stream;base64,AAEAAAAPAIAAAwBwR1NVQrD+s+0AAAD8AAAAQk…GIUViwQIhYsQNkRLEmAYhRWLoIgAABBECIY1RYsQMARFlZWVmzDAIBDCq4Af+FsASNsQIARAAA'
> because it violates the following Content Security Policy directive:
> "default-src *". Note that 'font-src' was not explicitly set, so
> 'default-src' is used as a fallback.
使用的 list 代码是
"content_security_policy": "script-src 'self'; object-src 'self' https://query.yahooapis.com/",
"permissions": [
"tabs", "<all_urls", "http://localhost/",
"http://*/*", "https://*/*", "https://query.yahooapis.com/*"
],
"content_scripts":
[{
"css": [
"css/component.css",
"css/tooltip-line.css",
"css/modal.css"
],
"js": [
"js/modernizr.custom.js",
"js/jquery-2.1.3.min.js",
"js/jquery.simpleWeather.min.js",
"js/handlebars-v4.0.5.js",
"js/moment.min.js",
"js/background.js"
],
"matches": [ "http://*/*", "https://*/*"]
}]
另外,在我的 html 文件中,我使用了这个元标记
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' http://* 'unsafe-inline'; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval'" />
谁能帮我解决这个问题。
最佳答案
您的内容安全策略有 "script-src 'self'
这意味着无法从第三方 URL 加载脚本。
您已在 object-src
中指定了 yahoo API指示。 object-src
指令 ( MDN ) 指定 <object>
的有效来源, <embed>
, 和 <applet>
元素。
要从第三方加载脚本,您必须在 script-src
中指定像这样的指令:
"content_security_policy": "script-src https://query.yahooapis.com/ 'self'; ..."
关于javascript - 内容安全策略指令 : "script-src ' self' blob: filesystem: chrome-extension-resource:"While fetching whether,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37017192/