0

我正在为我的观众做一个 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.
4

1 回答 1

0

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

 "content_security_policy": "script-src 'self' https://example.com; object-src 'self'"
于 2019-07-10T11:42:20.043 回答