Google-api-javascript-client: Google Sign-In button doesn't work in Edge/IE

Created on 25 Nov 2017  路  50Comments  路  Source: google/google-api-javascript-client

Installed Google Sign-in button per https://developers.google.com/identity/sign-in/web/sign-in

In Edge and IE 11, an exception is thrown at page load, and clicking the Sign-In button afterwards does nothing.

Error in console:
cb=gapi.loaded_0 (107,58)

Line 107 from https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en_US.c_IFVwZhec4.O/m=signin2/rt=j/sv=1/d=1/ed=1/am=AQ/rs=AGLTcCN-k6uYdYPp8tFvHJ4lZi1GxPxjaA/cb=gapi.loaded_0. I marked the offending throw statement in asterisks.

var tp,$o,ep,Yo;tp=function(a){_.D.setTimeout(function(){***throw a;***},0)};_.qk=function(a){a=Yo(a);!_.vd(_.D.setImmediate)||_.D.Window&&_.D.Window.prototype&&!_.pf("Edge")&&_.D.Window.prototype.setImmediate==_.D.setImmediate?($o||($o=ep()),$o(a)):_.D.setImmediate(a)};

Wish I had the unminified version!

Most helpful comment

Here is my solution, the thing about Javascript is it's all about timing and the DOM...if something fails, just keep trying until it succeeds.

[Important Code, keep calling loadGAPI() until all the checks pass!]

  if(!gapi || typeof(gapi.load) !== 'function') {
    window.isSignedIn = false
    window.loadGAPI_timeout = setTimeout(function() {
      loadGAPI()
    }, 500)
    return
  }

[Entire Code]

function loadGAPI() {
  if(!gapi || typeof(gapi.load) !== 'function') {
    window.isSignedIn = false
    window.loadGAPI_timeout = setTimeout(function() {
      loadGAPI()
    }, 500)
    return
  }
  gapi.load('auth2', function() {
    var options = {
      client_id: google.sign_in_client_id,
      cookie_policy: 'single_host_origin',
      ux_mode: 'redirect'
    }
    console.log(JSON.stringify(options, null, 4))
    auth2 = gapi.auth2.init(options)
    if(!auth2)
      return
    auth2.isSignedIn.listen(signInChanged)
    if(auth2.isSignedIn.get())
      auth2.signIn()
    auth2.currentUser.listen(loginUser)
    googleUser = auth2.currentUser.get()
    window.isSignedIn = true
    hashRedirect()
  })
}

All 50 comments

What is the full error message raised in console?

SCRIPT5022: [object Object]
cb=gapi.loaded_0 (107,58)

That's the whole thing. I honestly don't know how to get a full stacktrace in Edge/IE.

It works properly in the latest versions of Chrome, Safari, and Firefox. I'm running macOS High Sierra 10.13.1

Could you post a snippet of your code? It works fine with me. Do you block third-party data?

Tried upgrading to the latest version of Edge. Here I get the almost identical error cb=gapi.loaded_0 (106,57)

I do not block 3rd party data/cookies.

Inside my <head>:

<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="[ID HERE].apps.googleusercontent.com">

Inside my <body>:

<div class="g-signin2" data-onsuccess="onSignIn"></div>

And now I'm getting cb=gapi.loaded_0 (107,58) in the same instance of Edge. It seems like it intermittently bounces between (107, 58) and (106, 57)

Commented out all js on my site except for the google sign-in related js. Same problem occurs.

Also, the error appears in the console a few seconds after the page loads, and well after the button itself has rendered. At any time, clicking the button does nothing.

Made some progress.

First, my domain wasn't listed under "Authorized JavaScript origins" in my client config. That's what was causing the JS error.

Second, Google sign-in apparently has trouble with your site if its url is a pure IP address (or at least in Edge/IE), so I put a domain in my hostfile and started using that.

Now I'm at a point where everything's working in IE 11 but not Edge. In Edge, clicking the sign-in button opens up the Google sign-in window (fullscreen instead of the usual, smaller size). Then, after entering credentials and after the window closes (it asks me if it can close, and I say yes) the original window seems untouched. The <div> containing the button now has attributes data-gapiscan="true" data-onload="true" but its contents are still "Sign In", not "Signed In". The js function referenced from data-onsuccess is never called.

Tried hosting via https and using the default port, but that didn't seem to have any effect. Also tried putting <script src="https://apis.google.com/js/platform.js" async defer></script> at the bottom of the <body> as opposed to in the <head>, but that made no difference either.

What's odd is that https://google-developers.appspot.com/identity/sign-in/web/demos/signin_contextual_simple?hl=en works completely fine in Edge. Even the Google sign-in window is the right size.

@vptes1 thanks for investigating. I didn't ask to check that the domain was in the Authorized JavaScript origins as you mentioned that it was working under other browsers like Chrome.

I also observed the same issue with the latest version of Edge (15) but not in the previous ones. We will investigate.

@TMSCH Yea, I鈥檓 testing Edge/IE from a Windows VM (using a special IP address as opposed to localhost, which is what I had whitelisted in JavaScript origins). Forgot to mention that!

Hello, I am also experiencing a very similar issue, but only when running Edge InPrivate mode:

Steps to reproduce:
Open Edge Inprivate
Go to: https://google-developers.appspot.com/identity/sign-in/web/demos/signin_contextual_simple?hl=en

or http://gusclass.com/demos/button2/min.html

The following error is thrown:

SCRIPT5022: [object Object]
cb=gapi.loaded_0 (105,57)

"Unable to get property 'open' of undefined or null reference"
"idpiframe_initialization_failed"

Thanks for the report @sagoo33, looking into it.

Hi,
Did anyone find solution for this issue??

I am facing similar issue where in IE11, on click of sign in button( solution is run in visual studio localhost:xxxx and it's white listed in "Authorized JavaScript origins" as well as "Authorized redirect URIs"), Google opens sign in window and on sign in, it says:

"The webpage you are viewing is trying to close the window.
Do you want to close this window?"

On clicking YES, nothing happens and also "data-onsuccess" function not getting called.
Can someone please help me. Here is my code.


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Google Sign In</title>
   <script src="https://apis.google.com/js/platform.js" async defer></script>
    <meta name="google-signin-client_id" content="xxxxxxxxxxxxxx.apps.googleusercontent.com">
    <script>

        function onSignIn(googleUser) {
            alert('In onSignIn');
            var profile = googleUser.getBasicProfile();
            console.log('ID: ' + profile.getId()); 
            console.log('Name: ' + profile.getName());
            console.log('Image URL: ' + profile.getImageUrl());
            console.log('Email: ' + profile.getEmail());
        }

        function signOut() {

            console.log(document);

            var auth2 = window.gapi.auth2.getAuthInstance();
            auth2.signOut().then(function () {
                console.log('User signed out.');
            });
        }
    </script>

</head>
<body>
<h1>Login</h1>
<p>
    This is a simple page to test Google Sign In IE
</p>

<div class="g-signin2" data-onsuccess="onSignIn">
    This is sign on
</div>

<div>
    <a href="#" onclick="signOut();">Sign out</a>
</div>
</body>
</html>

@sureshdrim I am not able to reproduce the issue on IE11/Win10. Can you consistently reproduce it? Could you try clearing the cache and going through the full sign-in and consent flow?

Has any progress been made on this issue on Edge?

I can certainly reproduce the issue consistently in Edge (InPrivate mode) via the steps I mentioned.

We're working on a solution to Edge InPrivate mode issue. The popup closing issue is different and we're investigating.

@TMSCH I am able to reproduce this issue even after clearing cache.
Please find attached my code.

Note:

  1. It's a website created in Visual Studio 2017.
  2. Update your actual value of google-signin-client_id in index.html file.
  3. When you run this site in VS, white-list localhost:xxxx url in "Authorized JavaScript origins" as well as "Authorized redirect URIs" in Google developer console.

Hopefully with this, you should be able to reproduce this issue.

GoogleSignIn.zip

Hi,
Did you find any solution??

@sureshdrim No, as I'm not able to reproduce the issue. Do you have some specific settings enabled? Like third-party data blocked? Or InPrivate mode?

@TMSCH, as of now I got rid of that annoying IE popup asking:

"Do you want to close..."

But still our data-onsuccess callback function after Google authentication is not getting called.

I don't think I have any specific settings as I have reset IE settings to default.

Thanks.

@sureshdrim how did you get rid of the IE popup?

@TMSCH I reset my IE security settings to default from Internet Options>Security

@sureshdrim I'm still not able to reproduce your issue, even after having reset my settings as you do... Have you tried on another computer with IE11?

@TMSCH not tried on another machine.. will try and let u know by tomorrow morning.

Awesome, thanks!

@vptes1 is your app running on https://? What version of Edge are you using?

Hi @TMSCH, it's working on another machine.. seems to be some issue with my machine.. I will look in to it.

Thanks a lot for your timely help.

You're welcome. Let me know what you find out.

@TMSCH I'm using Microsoft Edge 41.16299.15.0 (the latest stable release) running on a Parallels VM on MacOS.

I am using http (not https). I did try https when this bug was first opened, and the same problem occurred. I have my http://domain:port whitelisted under "Authorized Javascript Origins".

@TMSCH When I click Sign In a window opens and I get this error (I removed my client id for privacy reasons):

400. That鈥檚 an error.

Error: invalid_request
Permission denied to generate login hint for target domain.
Request Details
redirect_uri=storagerelay://http/10.211.55.2:8083?id=auth159718
response_type=permission id_token
scope=email profile openid
openid.realm=
client_id=<<Removed for privacy>>.apps.googleusercontent.com
ss_domain=http://10.211.55.2:8083
fetch_basic_profile=true
gsiwebsdk=2
That鈥檚 all we know.

@vptes1 we made recent changes that should fix the problem for https:// domains in Microsoft Edge v15+. For non https: domain, there's unfortunately recent changes in Edge that prevent window to popup communication between different protocol. Could you test on a https: domain?

@TMSCH With https I'm getting a very similar error upon clicking Sign In:

400. That鈥檚 an error.

Error: invalid_request
Permission denied to generate login hint for target domain.
Request Details
redirect_uri=storagerelay://https/10.211.55.2:8081?id=auth368939
response_type=permission id_token
scope=email profile openid
openid.realm=
client_id=<<client id here>>.apps.googleusercontent.com
ss_domain=https://10.211.55.2:8081
fetch_basic_profile=true
gsiwebsdk=2
That鈥檚 all we know.

@TMSCH I am now using https + domain name (not ip) + valid ssl cert. Now I get the login popup, but after entering creds it hangs on "One moment please..." and sometimes on window title "Connecting..." (with no body). It still doesn't work.

@vptes1 is there any logs in the console (from the popup or the main window)?

@TMSCH

After I enter my credentials into that second window, it hangs with "One moment please" in its body. The console has this error:
SCRIPT5022: CustomError: Error in protected function: The window does not have an opener! rs=ABkqax3xgG_m5jT3aoCS4ML8L63suflMRA (423,93)

If I close the hung window and go back to the original window and refresh it, I'm signed in. But if I sign out, then try to sign-in again, that second window opens up and immediately hangs. There's no body and the title says "Connecting...". I'm not able to open the console in time to see anything. The url is https://accounts.google.com/o/oauth2/auth?redirect_uri=storagerelay%3A%2F%2F<<MY DOMAIN>>%3Fid%3Dauth<<SOME DIGITS>>&response_type=permission%20id_token&scope=email%20profile%20openid&openid.realm=&client_id=<<CLIENT ID>>.apps.googleusercontent.com&ss_domain=<<MY DOMAIN>>&fetch_basic_profile=true&gsiwebsdk=2 (I removed some data from public view)

Also, clearing out my cache/cookies will bring me back to the initial state. Sign-In leads to a functioning second window, but hangs after I enter username/password.

@vptes1 thanks for the further details. I'm able to reproduce this issue inconsistently, we are investigating.

@sagoo33 we fixed the issue for Edge InPrivate mode.

@TMSCH Great news! Thanks for update, nice work :)

@TMSCH I have the same issue as vptes1 - any update?

@kongguibin can you provide any assistance with this issue?

Count me in as yet another person who can't make this work. It works in every other browser I've tested, including Firefox (regular and developer), IE 11, Chrome, Safari, and even lesser-known browsers, like Vivaldi.

In Edge, however, the pop-up opens in a full screen and, after login, it does not close, nor does it call the callback function for success. Errors listed above are consistent with what I'm seeing.

This is frustrating because just enough people use Edge for this to be a problem. Who knew there'd be a time where IE would be preferable in some situations?

@vptes1 -- You ever figure this out?

Another coworker re-worked the code to get it to work... not sure exactly what he did to be honest.

Here is my solution, the thing about Javascript is it's all about timing and the DOM...if something fails, just keep trying until it succeeds.

[Important Code, keep calling loadGAPI() until all the checks pass!]

  if(!gapi || typeof(gapi.load) !== 'function') {
    window.isSignedIn = false
    window.loadGAPI_timeout = setTimeout(function() {
      loadGAPI()
    }, 500)
    return
  }

[Entire Code]

function loadGAPI() {
  if(!gapi || typeof(gapi.load) !== 'function') {
    window.isSignedIn = false
    window.loadGAPI_timeout = setTimeout(function() {
      loadGAPI()
    }, 500)
    return
  }
  gapi.load('auth2', function() {
    var options = {
      client_id: google.sign_in_client_id,
      cookie_policy: 'single_host_origin',
      ux_mode: 'redirect'
    }
    console.log(JSON.stringify(options, null, 4))
    auth2 = gapi.auth2.init(options)
    if(!auth2)
      return
    auth2.isSignedIn.listen(signInChanged)
    if(auth2.isSignedIn.get())
      auth2.signIn()
    auth2.currentUser.listen(loginUser)
    googleUser = auth2.currentUser.get()
    window.isSignedIn = true
    hashRedirect()
  })
}

Thanks for sharing your solution to fix the gapi loading issue on IE 11.

I was having the same issues on edge.

SCRIPT5022: SCRIPT5022: The window does not have an opener!

Some folks in the office don't seem to have the issue and after clearing all my cache and local storage things started working again.

On edge 42.17134.1.0 btw

My team is currently experiencing similar symptoms:

  • SCRIPT5022: The window does not have an opener! appears in the pop-up window console (MS Edge 42.17134.1.0)
  • SCRIPT5022: [object Object] cb=gapi.loaded_0 (109,57) appears in the parent window console
  • The login pop-up appears, but hangs once an account is selected and no callbacks are fired. The window says 'Connecting...' on the web page title but the actual pop-up is blank.

This issue is happening consistently for one of my team members (not working on deployed https website) and inconsistently for another (working on localhost; not working on deployed https). For me I cannot reproduce it at all-- it is working fine in localhost and deployed https. I believe they both have actual Windows machines. I am working from a VM. Verified with both team members that no extensions are currently installed.

@vptes1 @TMSCH @ZenEyes @kongguibin Was there a solution or workaround found for this particular issue? Clearing the cache and local storage does not work on the machine experiencing the symptoms. We've also tried repairing and resetting MS Edge which did not help.

This is how the pop-up is appearing for this issue:
Capture_Failed_03 AM_04_051

Hi,
for me, i have this error "cb=gapi.loaded_0" in IE11 when i try to sign in with google in my page.
Someone can help me please?

my script:
$("#customBtn").on('click', function() {
gapi.auth2.getAuthInstance().signIn().then(
function(success) {
alert('success')
}
);

Was this page helpful?
0 / 5 - 0 ratings