我正在尝试从Chrome打包的应用发送请求:
$.ajax({
url: "https://accounts.google.com/o/oauth2/auth?client_id=xxxapps.googleusercontent.com&response_type=id_token&scope=openid%20email", //"https://www.googleapis.com/plus/v1/people/me",
jsonp: "responseText",
dataType: "jsonp",
data: {
q: "select *",
format: "json"
},
success: function( response ) {
console.log( response );
}
});
并收到以下错误:
Refused to load the script
'https://accounts.google.com/o/oauth2/auth?client_id=xxx&q=select+*&format=json&_=xxx'
because it violates the following Content Security Policy directive:
"default-src 'self' chrome-extension-resource:". Note that
'script-src' was not explicitly set, so 'default-src' is used as a fallback.
该应用程序的清单文件包含以下内容:
"content_security_policy": "script-src 'self' https://accounts.google.com; object-src 'self'"
如何解决这个错误?
最佳答案
您看到的错误消息就是答案。第一个是说您违反了CSP。第二个是说您不能在Chrome应用中更改CSP。
阅读有关Content Security Policy in a Chrome App和完整性another discussion in the context of Chrome Extensions的更多信息。您可以对所问的问题有答案,但是您可能想问一个新问题,以说明您要做什么(而不是为什么看到这些错误消息)。如果您的总体目标是在Chrome应用中运行外部(即下载的)内容,那么根据Chrome Web Store开发者服务条款,唯一的方法是将代码和消息沙箱化到普通特权代码中。
关于javascript - chrome打包应用中的https请求(java脚本),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21657311/