【发布时间】:2019-01-07 07:12:19
【问题描述】:
我正在制作一个 chrome newtab 扩展,通过查询雅虎天气来加载用户天气。我收到来自 chrome 的“Content-Security-Policy”违规,说我无法加载脚本:
拒绝执行内联脚本,因为它违反了以下内容 内容安全策略指令:“script-src 'self' blob: 文件系统:chrome-extension-resource:”。要么是“不安全的内联” 关键字,哈希 ('sha256-PeWalvgfJE6xbsZk1lp14cxuyPBUbuIbzFNlAxarXxU='),或随机数 ('nonce-...') 是启用内联执行所必需的。
这是我的清单:
{
"name": "WeatherTodo",
"version": "1.0",
"description": "Extension that shows a weather animation and todolist",
"manifest_version": 2,
"permissions": ["storage"],
"chrome_url_overrides": {
"newtab": "index.html"
}
}
问题在于查询是不同的 URL,具体取决于用户所在的位置,因此我不确定是否可以将其作为安全链接添加到清单。请帮忙。
我认为这是导致错误的行,我不确定,因为 chrome 指向具有我的脚本标记的 html 行:
fetch("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(SELECT%20woeid%20FROM%20geo.places%20WHERE%20text%3D%22("
+ position.coords.latitude + "%2C" + position.coords.longitude
+ ")%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys")
【问题讨论】:
-
TL;DR,把你的js代码放到一个单独的文件中,通过
<script src=...>标签加载。
标签: javascript html google-chrome google-chrome-extension yahoo-api