Skip to content
This repository was archived by the owner on Apr 18, 2026. It is now read-only.
This repository was archived by the owner on Apr 18, 2026. It is now read-only.

popup_closed_by_user thrown when calling signIn in Chrome #405

Closed

Description

@sugarmanz

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
}

Activity

  1. TMSCH commented on Mar 5, 2018

    @TMSCH
    Contributor

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

  2. sugarmanz commented on Mar 5, 2018

    @sugarmanz
    Author

    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?

  3. TMSCH commented on Mar 6, 2018

    @TMSCH
    Contributor

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

  4. sugarmanz commented on Mar 6, 2018

    @sugarmanz
    Author

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

  5. TMSCH commented on Mar 7, 2018

    @TMSCH
    Contributor

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

  6. TMSCH commented on Mar 7, 2018

    @TMSCH
    Contributor

    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!

  7. emhagman commented on Mar 12, 2018

    @emhagman

    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.

  8. TMSCH commented on Mar 12, 2018

    @TMSCH
    Contributor

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

  9. jiucheng-front commented on Mar 21, 2018

    @jiucheng-front

    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/

  10. jiucheng-front commented on Mar 21, 2018

    @jiucheng-front

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

  11. TMSCH commented on Mar 28, 2018

    @TMSCH
    Contributor

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

  12. sugarmanz commented on Mar 29, 2018

    @sugarmanz
    Author

    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.

  13. TMSCH commented on Mar 29, 2018

    @TMSCH
    Contributor

    @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!

  14. jiucheng-front commented on Mar 30, 2018

    @jiucheng-front

    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

  15. 10 remaining items

  16. lopugit commented on Oct 17, 2018

    @lopugit

    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
  17. SatoshiOoO commented on Oct 17, 2018

    @SatoshiOoO

    @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?

  18. kongguibin commented on Oct 17, 2018

    @kongguibin

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

  19. vamshikilari commented on Nov 30, 2018

    @vamshikilari

    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

  20. wichopy commented on Nov 30, 2018

    @wichopy

    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?

  21. yoyoyvr commented on Dec 4, 2018

    @yoyoyvr

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

    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?

  22. IstvanD commented on Dec 6, 2019

    @IstvanD

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

  23. StasUshomirsky commented on Sep 28, 2020

    @StasUshomirsky

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

  24. omar-dulaimi commented on Oct 24, 2020

    @omar-dulaimi

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

  25. tmasrat commented on Oct 26, 2020

    @tmasrat

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

  26. pexak commented on Dec 12, 2020

    @pexak

    Started working on Version 87.0.4280.88

  27. TLKG commented on Sep 21, 2021

    @TLKG

    Version 93.0.4577.82 (Official Build) (64-bit). popup_closed_by_user occured only in debug mode of VSC, stand-alone Chrome and Edge are all fine. Removing all account from Chrome works.

  28. namanbarkiya commented on May 22, 2022

    @namanbarkiya

    2022 update for React and JS!

    Experienced the identical problem, and after trying numerous workarounds, realised that I was missing gapi initialization!

    React:

    1. install gapi-script
      npm i gapi-script

    2. import gapi from gapi-script
      import { gapi } from "gapi-script";

    3. load gapi in App()

    gapi.load("client:auth2", () => {
          gapi.client.init({
            clientId:
              "*****.apps.googleusercontent.com",
            plugin_name: "chat",
          });
        });
    

    JS:

     window.gapi.load('client:auth2', () => {
                window.gapi.client.init({
                    clientId: '******.apps.googleusercontent.com',
                    plugin_name: "chat"
                })
        })
    

    Hope the steps work for you ^_^

  29. tungnguyenvan commented on Jul 17, 2022

    @tungnguyenvan

    2022 update for react!

    I was facing the same issue.. after a lot of workaround I got to know that I was missing gapi initialization!

    Here are the steps:

    First install gapi-script

    npm i gapi-script

    import the gapi from gapi-script

    import { gapi } from "gapi-script";

    then initialize in App()

    gapi.load("client:auth2", () => {
          gapi.client.init({
            clientId:
              "*****.apps.googleusercontent.com",
            plugin_name: "chat",
          });
        });
    

    after these steps your app should be working fine ^_^

    JS update

    I am not 100% sure about JS workaround but including this might work on your application

     window.gapi.load('client:auth2', () => {
                window.gapi.client.init({
                    clientId: '******.apps.googleusercontent.com',
                    plugin_name: "chat"
                })
        })
    

    Thank you so much @naman9199, it work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions