How to stop opening the account selection window under the current window

Periodically, I get periods when calling gapi.auth.authorize leads to the opening of the account selection window under my application window, where, of course, it is not noticed by the user.

Is there a way to get it on top, or at least discover that it is open, so I can warn the user?

I am currently testing Chrome, but I also saw it in Firefox.

To recreate ...

  • Sign in to more than one Google Account
  • Go to my application that calls the gapi.auth.authorize call
  • Usually a pop-up window will appear asking you to choose which Google account I want to authenticate with. However, sometimes this pop-up window is located under the window of my application, so it is hidden and not noticed by the user.

What should (and sometimes does) look like ...

enter image description here

That it should not, but sometimes it looks like ...

enter image description here

+7
javascript google-chrome google-oauth
source share
2 answers

I could not reproduce your problem when the popup started in the background, but I may have a solution for you.

This is a hack, but it avoids the need to modify the Google code directly.

This is an important part, the demo is given below. Essentially, you redefine window.open and focus the popup shortly after creating it. After opening the window, you restore the functionality of window.open to default.

 function handleAuthClick(event) { // Hijack window.open var windowOpen = window.open; window.open = function(url, name, options) { var newWindow = windowOpen.apply(this, arguments); setTimeout(function() { newWindow.focus(); }, 0); return newWindow; }; gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult); // Release window.open window.open = windowOpen; return false; } 


Demo : http://jsbin.com/sefozinu/1/edit

Later versions of Chrome and FireFox are not known to respect window.focus .

0
source share

I followed the steps and, like others, could not reproduce this. (using Chrome 34.0.1847.131 on Windows 8.1)

The problem may be the browser, not the content.

It looks like you're using a Chrome / Chromium browser that I don't know about. Looking at the screenshot, I see a soccer ball in the upper left corner of the window. Could you please indicate it so that we can reproduce it?

(Or consider installing a new Chrome browser browser in your browser browser as a basic test.)

0
source share

All Articles