【问题标题】:Loading Script Error in Chrome extensions在 Chrome 扩展程序中加载脚本错误
【发布时间】:2012-09-04 06:02:43
【问题描述】:

我收到此错误,但我无法找到解决方法:

拒绝加载脚本“http://api.ustream.tv/json/channel/...”,因为它违反了以下内容安全策略指令:“script-src 'self' chrome-extension-resource: ”。

有什么办法可以消除这个错误吗?这是我的 json 代码。

{
    "manifest_version": 2,
    "name": "COD Television Live Checker",
    "version": "1.0",
    "description": "The Official Crome Extension of CodTelevision.com - Live Checker",
    "browser_action": 
    {
    "default_icon": "icon.png",
    "default_popup": "main.html"
    }
    "permissions": ["http://api.ustream.tv/json/channel/*"]
}

还有我的html代码:

<!DOCTYPE HTML>
<html> 

<head>
<script type="text/javascript" src="jquery-latest.js"></script>
<script type="text/javascript" src="popup.js"></script>
</head>

<body>

<center><span id="status1">No Data</span></center>

</body> 
</html> 

最后是我的 javascript:

var query = 'http://api.ustream.tv/json/channel/...';
jQuery.getJSON(query, function(data) {
    if (data == 'live') {
        document.getElementById("status1").innerText = "LIVE";
    } else {
        document.getElementById("status1").innerText = "OFFLINE";
    }
});

【问题讨论】:

  • 不要使用 JSONP,而是使用常规 JSON。将清单文件中permissions 中的 Web 服务 URL 列入白名单。
  • 等等,我该怎么做呢?
  • @RobW 喜欢这个权限:['api.ustream.tv']

标签: javascript jquery html google-chrome-extension


【解决方案1】:

您必须在清单文件中设置正确的权限:

"permissions": [
  "http://api.ustream.tv/json/channel/*"
]

可以在the docs 中找到。

更新

我看到您正在使用v2 manifest。在这种情况下,您应该在清单中添加以下内容:

"content_security_policy": "script-src 'self' http://api.ustream.tv; object-src 'self'",

【讨论】:

  • 看看我更新的 json 代码。应该是这样吗?如果是这样,我得到一个错误
  • 哦,“*”在哪里,我需要保留它还是用我的 api 密钥和其他东西添加大链接的其余部分?
  • 视情况而定。这是一个通配符。所以* 应该可以工作。
  • 好吧,不管有没有它,我仍然会收到有关内容安全的错误
  • 是的,我是肯定的,以防万一,让我删除它然后重新添加包
猜你喜欢
  • 2013-12-28
  • 2016-08-12
  • 2017-03-30
  • 1970-01-01
  • 2020-04-20
  • 1970-01-01
  • 2016-08-20
  • 2015-04-21
  • 2017-11-29
相关资源
最近更新 更多