javascript - Chrome 打包应用程序中的 https 请求(javascript)

标签 javascript google-chrome-extension xmlhttprequest google-chrome-app content-security-policy

我正在尝试从 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.

应用程序的 list 文件包含以下内容:

   "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 网上应用店的开发人员服务条款,唯一的方法是将代码和消息沙盒化到/从您的普通特权代码.

关于javascript - Chrome 打包应用程序中的 https 请求(javascript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21657311/

相关文章:

javascript - 为什么我会收到 "' documentScan' is not allowed for specified platform"警告?

excel - 如何用VBA和选择器将该网站的内容导出到Excel?

ajax - AJAX 请求的礼貌频率?

javascript - 小书签和 CoffeeScript

javascript - Chrome : Passing data between contentscript and popup. html

javascript - 无法使用js在单击按钮时隐藏div

javascript - 在 Chrome 中启用音频的自动播放策略标志

jquery - ajax 和相对 url

javascript - Angular 在循环内设置 ng-modal 值

javascript - 如何使用 JS 类创建自定义元素来创建元素的属性