Created
July 27, 2016 17:57
-
-
Save ivankolesnik/b4f09f5d5f1de12b06cf53611265e986 to your computer and use it in GitHub Desktop.
Watch for closed Google Sign In oauth window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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