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 .
Syntax
source share