XMLHttpRequest in Chrome locks up browser

雨燕双飞 提交于 2019-12-24 09:28:00

问题


I have the following code (I don't recommend running it):

     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();

What happens is this opens up a new tab, and this tab completely steals all the focus. I can't use any of the other Chrome tabs, it quickly switches back to the auth tab. And if I log-in with the auth tab, it just reloads the same auth tab, and I am back to square one.

The token is acquired via this call:

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

Has anyone seen this horrible problem? I can't get Chrome to stop making an auth request to the url in the screenshot. It keeps stealing the focus, and forcing me to login over and over again.

From what I can tell, it's actually this call this brings to me to the black hole authentication tab:

chrome.identity.getAuthToken()

This didn't use to happen, but seems like it started happening after I added this to my manifest.json file:

  "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"
    ]
  },

The old login screen looks like this, and this worked really nicely:

I am currently fairly certain that these two lines in the scopes array are what are causing the problem:

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

what do I do?


回答1:


I've had this problem before but it was months ago. If I recall correctly, it ended up being that the client_id was invalid. Double check your oauth client_id to make sure you're using the correct one.



来源:https://stackoverflow.com/questions/48615964/xmlhttprequest-in-chrome-locks-up-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!