【问题标题】:https request in chrome packaged app (java script)chrome 打包应用程序中的 https 请求(javascript)
【发布时间】: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


【解决方案1】:

我想我已经通过添加清单解决了这个问题: "权限": ["https://accounts.google.com/"]

【讨论】:

    【解决方案2】:

    您看到的错误消息就是答案。第一个是说你违反了 CSP。第二个是说您不能在 Chrome 应用中更改 CSP。

    阅读有关Content Security Policy in a Chrome App 的更多信息,以及another discussion in the context of Chrome Extensions 的完整性。您已经回答了您提出的问题,但您可能想提出一个新问题来解释您正在尝试做什么(而不是为什么您会看到这些错误消息)。如果您的总体目标是在 Chrome 应用程序中运行外部(即下载的)内容,那么根据 Chrome 网上应用店的开发者服务条款执行此操作的唯一方法是将代码和消息沙箱化到您的正常特权代码/ .

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多