Chrome Extension for Twittch API给我有关内容安全策略的错误

时间:2019-07-10 11:39:20

标签: javascript jquery ajax google-chrome-extension twitch-api

我正在做一个chrome扩展程序,以便我的观众知道我什么时候播出, 所以我已经完成了,但是它返回了一个错误

首先,我尝试使用JQuery XMLHttpRequest进行此操作,但我发现JSONP更适合那些扩展,因此我使用JSONP这样的请求完成了

checkStream();

setInterval(function(){
  checkStream();
}, 5000);

function checkStream() {
  $.ajax({
    url: 'https://api.twitch.tv/kraken/streams/cew_kuhaku?client_id=myclientid',
    jsonp: "callback",
    dataType: "jsonp",
    data: {},
    // Work with the response
    success: function( response ) {
        console.log( response ); // server response

              $("#json").html(response)
              if(response["stream"] == null){
                $("#info").html("Kuhaku n'est pas en stream");
                      chrome.browserAction.setIcon({path: "img/off.png"});
              }else {
                $("#info").html("Kuhaku est en stream")
                      chrome.browserAction.setIcon({path: "img/on.png"});
              }
    }
  });
}

我的清单如下:

{
  "manifest_version":2,
  "name":"CEW Kuhaku Streaming",
  "version":"1.0",
  "description":"Extension de stream de CEW Kuhaku",
  "browser_action": {
    "default_popup":"index.html"
  },
  "icons":{
    "64" : "img/on.png"
  },
  "background": {
    "scripts": ["jquery.js", "background.js"]
  }
}

这是我的index.html

<h1>Stream CEW Kuhaku</h1>
<p id="info">Kuhaku est en live</p>
<p id="json"></p>
<script src="jquery.js"></script>
<script src="app.js"></script>

我希望验证自己的信息流状态,但是我知道了:

Refused to load the script because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

1 个答案:

答案 0 :(得分:0)

您需要将内容安全策略配置添加到manifest.json

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