Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] signInWithPopup creates new tab instead of popup in Chrome 59 #63

Closed
DanielAndrews43 opened this issue Jun 16, 2017 · 11 comments
Closed

Comments

@DanielAndrews43
Copy link

DanielAndrews43 commented Jun 16, 2017

Describe your environment

  • Operating System version: OSX Sierra 10.12.4
  • Firebase SDK version: 4.1.2
  • Firebase Product: Auth

Describe the problem

When using firebase.auth.signInWithPopup(provider) a new tab is created with the auth instead of creating a popup as it did in Chrome 58 and earlier.

https://stackoverflow.com/questions/44417724/facebook-authentication-opening-tab-instead-of-popup-in-chrome-59 seems to say that the parameter 'location=no' needs to be passed in window.open(), but this is not accessible using the SDK.

Steps to reproduce:

Create an auth button with signInWithPopup() and click on it. A new tab will pop up instead of a new popup window.

Relevant Code:

This link describes the problem perfectly.

https://stackoverflow.com/questions/44417724/facebook-authentication-opening-tab-instead-of-popup-in-chrome-59

@DanielAndrews43 DanielAndrews43 changed the title signInWithPopup creates new tab instead of popup in Chrome 59 [Bug] signInWithPopup creates new tab instead of popup in Chrome 59 Jun 16, 2017
@bojeil-google
Copy link
Contributor

@bojeil-google
Copy link
Contributor

The only way we can fix it is via a hack.
We currently use something like this:
window.open('about:blank', '_blank', 'width=515,height=680,top=260,left=702,location=1,resizable=1,statusbar=1,toolbar=0');
This should open in a popup. However, chrome 59 broke this.
We'd have to set location=0 to get it to work as expected.

@bojeil-google
Copy link
Contributor

The fix I mentioned is a hack in my opinion. This should be fixed on Chrome's end.

@yarnball
Copy link

yarnball commented Jul 17, 2017

Also having this issue. What is the work around? @bojeil-google could you be more specific?

Ideally I could do this in a modal even.

I was unsuccessful with this:

  handleGoogleLogin = () => {
        window.open('about:blank', '_blank', 'width=515,height=680,top=260,left=702,location=1,resizable=1,statusbar=1,toolbar=0');
        loginWithGoogle()
            .catch(function (error) {
                alert(error);
            });
  }
export function loginWithGoogle() {
    return firebaseAuth().signInWithPopup(googleProvider);
}

@bojeil-google
Copy link
Contributor

This is a Chrome bug. There is no workaround. Chrome breaks this expected behavior. Please check the link: https://bugs.chromium.org/p/chromium/issues/detail?id=723655

@yarnball
Copy link

I see. Well I'm using react.js with it, and I used your "window.open" method for a new route which does the "loginWithGoogle". It opens a new window successfully.

However, I can't do 'window.close' when the sign in is complete. The promise doesn't seem to work.

Am I using it right?

This code never invokes the .'then'

'''
handleGoogleLogin = () => {
loginWithGoogle()
.catch(function (error) {
alert(error);
})
.then(window.close());
}
'''

This code causes the 'then' to happen immediately (ie before redirect even happens).

'''
export function loginWithGoogle() {
return firebaseAuth().signInWithreRedirect(googleProvider).then(window.close());;
}
'''

@bojeil-google
Copy link
Contributor

Internally we call something like:
window.open('about:blank', '_blank', 'width=515,height=680,top=260,left=702,location=1,resizable=1,statusbar=1,toolbar=0');
In the current version of Chrome this opens a tab and not a popup. This is a bug in Chrome. There is not much we can do until it is fixed.

I am not sure about your case as you are using signInWithRedirect and not signInWithPopup.

@yarnball
Copy link

yarnball commented Jul 18, 2017 via email

@bojeil-google
Copy link
Contributor

Oh, I see. So you are implementing your own sign in with popup where you open a popup and then signInWithRedirect on that window. You need to call firebase.auth().getRedirectResult() on the popup to get the result. If the popup is the same domain as the parent page, you should detect the sign-in completion without any additional work on the parent page via firebase.auth().onAuthStateChanged listener. You may need to pass the result.credential if you need the returned OAuth credential.

Let me know if I am understanding this correctly.

@yarnball
Copy link

I tried your suggestion, by doing

return firebase.auth().getRedirectResult(googleProvider)

However it gave this error:

auth.js:244 Uncaught 
O {code: "auth/argument-error", message: "getRedirectResult failed: Expected 0 arguments but got 1."}

Could you give a bit of an example? Thanks

@bojeil-google
Copy link
Contributor

Check the documentation on this:
https://firebase.google.com/docs/auth/web/google-signin
When you start the sign in, you can firebase.auth().signInWithRedirect(provider)
When you return to the page and want to get back the result, you call firebase.auth().getRedirectResult()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants