Skip to content

Instantly share code, notes, and snippets.

@ivankolesnik
Created July 27, 2016 17:57
Show Gist options
  • Save ivankolesnik/b4f09f5d5f1de12b06cf53611265e986 to your computer and use it in GitHub Desktop.
Save ivankolesnik/b4f09f5d5f1de12b06cf53611265e986 to your computer and use it in GitHub Desktop.
Watch for closed Google Sign In oauth window
/*
* This is a snippet used to track Google Sign In oauth window
* Based on this comment https://github.com/google/google-api-javascript-client/issues/25#issuecomment-76695596
* You can wrap this into function to use promises, timeouts etc
* Shame on you, Google!
*/
// Get current open function
var winOpen = window.open;
// Regexp to valiate if it is really Googe Oauth page
var googleRegex = /^.*(google\.com).*(oauth).*$/i;
window.open = function(){
if (!googleRegex.test(arguments[0])) {
winOpen.apply(this, arguments);
return;
}
// Return stock open function
window.open = winOpen;
// Get Google window
var googWndw = winOpen.apply(this, arguments);
// Check if it is closed periodically
var interval = setInterval(function(){
if (!googWndw.closed) {
return;
}
clearInterval(interval);
interval = undefined;
googWndw = undefined;
console.log('google window was closed!')
}, 1000);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment