Google-api-javascript-client: `popup_closed_by_user` thrown when calling `signIn` in Chrome

Created on 5 Mar 2018  Â·  36Comments  Â·  Source: google/google-api-javascript-client

From all of the browsers I've tested, this only seems to occur on Chrome, both incognito and in an authenticated browser. First, I check if the gapi object is properly authenticated. If not, I call the signIn method to authenticate. If the browser is not authenticated, the popup works as intended and I am able to sign in and then the signIn promise resolves. However, if the browser is already linked to a Google account, the popup opens and immediately closes (I assume this is because it is trying to use the authenticated account). This causes the popup_closed_by_user exception to be thrown and the gapi object is never authenticated. Below is the code.

const auth = gapi.auth2.getAuthInstance();
if (!auth.isSignedIn.get()) {
   auth.signIn().then(() => // Do the thing);
} else {
   // Do the thing
}

Most helpful comment

This happens when using multiple accounts, simple as that.

All 36 comments

Hi @sugarmanz, is this snippet called after a user clicks a button?

Yes. Though it is through a Vue Store action. So, I'm not sure if that would affect anything.

Additionally, I'm not sure this is 100% related, but it seems as though the gapi object has trouble authenticating through cookies on Chrome. On Opera, once I authenticate, the gapi object says its authenticated until I explicitly sign out of the Google account, even persisting through different tabs of the same origin. Now that I think about it, this makes sense and is definitely the desired outcome. Any thoughts on why this wouldn't be working the same in Chrome?

What version of Chrome are you using? Are you blocking third-party cookies?

I am not blocking third-party cookies. And my Chrome version is: 64.0.3282.140 (Official Build) (64-bit)

Would you have a public app I could try? Or a full snippet of code?

Alternatively, can you check with the same setup than you have, the button here: https://developers.google.com/identity/sign-in/web/sign-in#add_a_google_sign-in_button. See if it changes from "Sign in" to "Signed in". Thanks!

This is also occurring for me. If you open a new tab on Chrome, the issue goes away. If you refresh the same page, the issue remains.

@emhagman can you reproduce the issue in the link I gave?

I got the same problem ,this example online.
Clicking Google sign in and Google sign out will works on any browser.
https://wjf444128852.github.io/demo01/login/

@TMSCH This error will only appear on 32-bit chrome

@wjf444128852 interesting, that's valuable information. I will see if I can get reproduce on a 32-bit Chrome.

Not sure if you guys pushed a fix, but I can't seem to reproduce on my 64-bit version of Chrome. It is interesting to note that I originally encountered the issue using a 64-bit version of Chrome, and I was able to consistently reproduce it until today. I would test on 32-bit, but since 32-bit Chrome is deprecated on Ubuntu, that's a bit more difficult for me to test.

@sugarmanz thanks for the update. It seems that the 32-bit issue that @wjf444128852 observes might be due to a different browser configuration (not the fact it's 32-bit) as we are discussing in another thread.
Let me know if you observe again the issue @sugarmanz!

Thanks a lot.. Because the setting about chrome://settings/content/cookies of the Chrome 32-bit on ensure that "Block third-party cookies" option is enabled !!!!

@TMSCH @sugarmanz

Hi,

I am still getting this below error in both chrome and mozilla:
ERROR
Error
​
columnNumber: 31
​
fileName: "http://localhost:4200/polyfills.js"
​
lineNumber: 3136
​
message: "Uncaught (in promise): Object: {\"error\":\"popup_closed_by_user\"}"
​
promise: Object { __zone_symbol__state: 0, __zone_symbol__value: {…} }
​
rejection: Object { error: "popup_closed_by_user" }
​
stack: "resolvePromise@http://localhost:4200/polyfills.js:3136:31\nmakeResolver/<@http://localhost:4200/polyfills.js:3046:17\n./node_modules/angularx-social-login/angularx-social-login.es5.js/AuthService.prototype.signIn/http://localhost:4200/vendor.js:95269:21\n./node_modules/zone.js/dist/zone.js/invoke@http://localhost:4200/polyfills.js:2710:17\nonInvoke@http://localhost:4200/vendor.js:33770:24\n./node_modules/zone.js/dist/zone.js/invoke@http://localhost:4200/polyfills.js:2709:17\n./node_modules/zone.js/dist/zone.js/run@http://localhost:4200/polyfills.js:2460:24\nscheduleResolveOrReject/<@http://localhost:4200/polyfills.js:3194:29\n./node_modules/zone.js/dist/zone.js/invokeTask@http://localhost:4200/polyfills.js:2743:17\nonInvokeTask@http://localhost:4200/vendor.js:33761:24\n./node_modules/zone.js/dist/zone.js/invokeTask@http://localhost:4200/polyfills.js:2742:17\n./node_modules/zone.js/dist/zone.js/runTask@http://localhost:4200/polyfills.js:2510:28\ndrainMicroTaskQueue@http://localhost:4200/polyfills.js:2917:25\n./node_modules/zone.js/dist/zone.js/invokeTask@http://localhost:4200/polyfills.js:2822:21\nZoneTask/this.invoke@http://localhost:4200/polyfills.js:2807:28\ntimer@http://localhost:4200/polyfills.js:4376:17\n"
​
task: Object { runCount: 0, _state: "notScheduled", type: "microTask", … }
​
zone: Object { _properties: {…}, _parent: {…}, _name: "angular", … }
​
__proto__: Object { … }

Could somebody help me ?

I already checked block third-party cookies and it is not blocked.

Facing the same problem. Any workaround?
Happens only in Chrome. Works in Firefox.
My current chrome version: Version 67.0.3396.62 (Official Build) (64-bit)

Update:
Updating to Version 67.0.3396.79 (Official Build) (64-bit) seems to have fixed it.

We are observing the same issue on Chrome version 67.0.3396.99 (64-bit). It is working on Mozilla for us.

I also encounter this in Safari Version 12.0 (14606.1.20.40.2)

Any update on this? Is there a Chromium bug to track? I noted some similar behavior in #377

Having this issue as well. Chrome 67.0.3396.99 (Official Build) (64-bit) on OS X 10.11.6. Just copy-pasting the code from the Building a button with a custom graphic sample and swapping in my own client ID is enough to trigger it. I think I'm even having the same issue with the sample mentioned above, but there's no error message to test it.

Block Third Party Cookies is disabled. It works without issue when I'm in incognito mode. I went onto a computer I hadn't used before and it worked there as well. It seems like it maybe has something to do with Chrome knowing the login email address already?

If I'm logged into my Google account and I try to use the sign-in button, the sign-in window flashes up for a split second, closes, and I get the popup_closed_by_user error alert. If I'm not logged into my account, the window comes up, asks me for my username and password, and then closes and I get the same error.

Not seeing any issues in Safari.

Edited to mention: this is only happening on one of my computers. The computer where it's working is running the same Chrome version but OS X 10.13.5. It also only started not working on my other computer today. I was logged into the same site yesterday with no issues.

I was having this issue using the angular5-social-login plugin. Unbelievably the issue was solved by simply deleting the credential and then re-adding it. According to this post, there are many others having the same issue and solution: https://stackoverflow.com/a/44488113/4553162

This happens when using multiple accounts, simple as that.

This happens when using multiple accounts, simple as that.

so..... pretty broke...

@bochunz hey sorry to annoy you but this is still broken and it's a pretty big feature, don't lots of people use multiple accounts??

I tested in incognito mode and single user works, multi breaks, on

Google Chrome | 69.0.3497.100 (Official Build) (64-bit)
-- | --
Revision | 8920e690dd011895672947112477d10d5c8afb09-refs/branch-heads/3497@{#948}
OS | Mac OS X
JavaScript | V8 6.9.427.23

@lopugit I saw similar issues earlier on some other websites. I could even reproduce it with single user. But it seems the issue is gone now. Are you still experiencing this issue?

We submitted a fix for the 'popup_closed_by_user' error. Please verify the bug is fixed.

Having this issue as well. Chrome 67.0.3396.99 (Official Build) (64-bit) on OS X 10.11.6. Just copy-pasting the code from the Building a button with a custom graphic sample and swapping in my own client ID is enough to trigger it. I think I'm even having the same issue with the sample mentioned above, but there's no error message to test it.

Block Third Party Cookies is disabled. It works without issue when I'm in incognito mode. I went onto a computer I hadn't used before and it worked there as well. It seems like it maybe has something to do with Chrome knowing the login email address already?

If I'm logged into my Google account and I try to use the sign-in button, the sign-in window flashes up for a split second, closes, and I get the popup_closed_by_user error alert. If I'm not logged into my account, the window comes up, asks me for my username and password, and then closes and I get the same error.

Not seeing any issues in Safari.

Edited to mention: this is only happening on one of my computers. The computer where it's working is running the same Chrome version but OS X 10.13.5. It also only started not working on my other computer today. I was logged into the same site yesterday with no issues.

Simply Enable the cookies. it solved the issue for me

Having this issue as well. Chrome 67.0.3396.99 (Official Build) (64-bit) on OS X 10.11.6. Just copy-pasting the code from the Building a button with a custom graphic sample and swapping in my own client ID is enough to trigger it. I think I'm even having the same issue with the sample mentioned above, but there's no error message to test it.
Block Third Party Cookies is disabled. It works without issue when I'm in incognito mode. I went onto a computer I hadn't used before and it worked there as well. It seems like it maybe has something to do with Chrome knowing the login email address already?
If I'm logged into my Google account and I try to use the sign-in button, the sign-in window flashes up for a split second, closes, and I get the popup_closed_by_user error alert. If I'm not logged into my account, the window comes up, asks me for my username and password, and then closes and I get the same error.
Not seeing any issues in Safari.
Edited to mention: this is only happening on one of my computers. The computer where it's working is running the same Chrome version but OS X 10.13.5. It also only started not working on my other computer today. I was logged into the same site yesterday with no issues.

Simply Enable the cookies. it solved the issue for me

But what if the user of your app decides to block third party cookies?

I'm having this problem too. Chrome 70.0.3538.102 (Official Build) (64-bit) on Windows 7.

  • Block Third Party Cookies is disabled.
  • I'm logged in on two different google accounts. Selecting the account I want from the list results in the popup_closed_by_user error.
  • Works in incognito mode. Works in Internet Explorer. In both cases I was not logged into Google and went through the full sign-in flow.
  • I'm connecting to http://localhost:3000 for testing.

EDIT: About 20 minutes later it started working. The client ID and developer dashboard configuration for my app was brand new, perhaps it needed to percolate into a database somewhere?

The error is present on Version 78.0.3904.108 (Official Build) (64-bit)

This error is still present in Version 85.0.4183.121 (Official Build) (64-bit)

Still occurring in Version 85.0.4183.83 (Official Build) (64-bit)

I am on version 86.0.4240.111 (Official Build) (64-bit) and it's still happening

Started working on Version 87.0.4280.88

Was this page helpful?
0 / 5 - 0 ratings