【发布时间】:2014-03-06 14:38:14
【问题描述】:
我正在尝试从 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'"
如何解决这个错误?
【问题讨论】:
-
确保在更改清单后重新加载 chrome://extensions 上的扩展。
-
@abraham,又做了一次。结果相同:尝试安装此扩展程序时出现警告:“content_security_policy”仅允许用于扩展程序和旧版打包应用程序,但这是一个打包应用程序。
-
您是否尝试将
https://accounts.google.com/*添加到您的许可数组中? -
您还想停止使用 jsonp 并直接使用 JSON 有效负载执行 XHR 请求。
标签: javascript google-chrome-extension xmlhttprequest google-chrome-app content-security-policy