【问题标题】:XMLHttpRequest in Chrome locks up browserChrome 中的 XMLHttpRequest 锁定浏览器
【发布时间】:2018-02-05 04:40:32
【问题描述】:

我有以下代码(不建议运行):

     let req = new XMLHttpRequest();
     req.open('GET', 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=' + token);
     req.onload = function() {
        console.log('response:', req.response);
     };
     req.send();

这会打开一个新标签,而这个标签完全占据了所有焦点。我无法使用任何其他 Chrome 选项卡,它会快速切换回身份验证选项卡。如果我使用身份验证选项卡登录,它只会重新加载相同的身份验证选项卡,然后我又回到原点。

通过此调用获取令牌:

chrome.identity.getAuthToken({interactive: true}, function (token) {}):

有人见过这个可怕的问题吗?我无法让 Chrome 停止向屏幕截图中的 url 发出身份验证请求。它不断窃取焦点,并迫使我一遍又一遍地登录。

据我所知,实际上是这个调用将我带到了黑洞身份验证选项卡:

chrome.identity.getAuthToken()

这过去没有发生,但似乎在我将它添加到我的 manifest.json 文件后开始发生:

  "oauth2": {
    "client_id": "5461xxx462-7gebv033e9csxxxxg5f6ggu22rju9374.apps.googleusercontent.com",
    "scopes": [
      "https://www.googleapis.com/oauth2/v1/userinfo", // added this line
      "https://www.googleapis.com/oauth2/v1/userinfo.picture", // and added this line
      "https://www.googleapis.com/auth/chromewebstore.readonly"
    ]
  },

旧的登录屏幕看起来像这样,而且效果非常好:

我目前相当确定范围数组中的这两行是导致问题的原因:

"https://www.googleapis.com/oauth2/v1/userinfo"
"https://www.googleapis.com/oauth2/v1/userinfo.picture"

我该怎么办?

【问题讨论】:

  • 您是否在 Google API 控制台中为您的项目启用了受影响的 API?
  • 我启用了 IAM(身份)API...我不确定要启用哪些其他 API
  • 我使用范围为“googleapis.com/auth/drive.file”的google drive api,遇到了同样的问题。我的密钥、client_id 和 app id 都是正确的。即使用户已经登录,登录页面也会出现,用户应该登录以允许我的应用访问谷歌驱动器文件。

标签: google-chrome google-chrome-extension


【解决方案1】:

我以前也遇到过这个问题,但那是几个月前的事了。如果我没记错的话,最终是 client_id 无效。仔细检查您的 oauth client_id 以确保您使用的是正确的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 2011-06-29
    • 2015-05-27
    • 2011-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多