Chrome扩展:yql API错误:内容安全

Chrome Extension: yql API ERROR: Content Security

本文关键字:错误 安全 API 扩展 yql Chrome      更新时间:2023-09-26

我正在尝试调用yql api。但是得到一个错误:我有以下

Manfiest.json:
"content_security_policy": "script-src 'self'; object-src 'self'", 
Error:
Refused to load the script 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where…withkeys&callback=jQuery20208888747137971222_1400373036635&_=1400373036638' because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:".'

我试过在没有"content_security_policy"的情况下这样做但我还是会得到一个错误。

调用的代码:

yqlAPI = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(query) + ' &format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=?';
$.getJSON(yqlAPI, function(r){
$.each(r.query.results.li, function(){ 
  if(typeof this.font !== 'undefined')
      {        
        gogoAnime1.push([this.a.href,this.font.content]);
      }
});
gotFollowersOfA(gogoAnime1);});

我一直在找CSP (https://developer.chrome.com/extensions/contentSecurityPolicy # relaxing-remote-script)但我不明白我必须在manifest.json中添加什么。为了使它工作所有的帮助将不胜感激!

我想知道这是不是因为请求一个外部对象。

内容安全策略(CSP) - Google Chrome

如果您需要一些外部JavaScript或对象资源,您可以通过安全源列入白名单,从而在一定程度上放宽策略。

所以相应地调整,manifest .json:

"content_security_policy": 
       "script-src 'self'; object-src 'self' https://query.yahooapis.com/"

你需要使用HTTPS origin:

由于中间人攻击在HTTP上既微不足道又无法检测,因此这些来源将不被接受。目前,我们允许使用以下方案加入白名单:HTTPS、chrome-extension和chrome-extension-resource。