Here is my code..
if (loginWindow) {
//Creating an interval to detect popup window location change event
interval = setInterval(function () {
//get the url of all the open window
chrome.tabs.query({
active: true,
currentWindow: true
},function(tabs){
var tabURL = tabs[0].url;
var p=tabs[0].
url.id;
console.log(tabURL);
if ((tabURL).indexOf(that.callbackURL) == 0)
{
chrome.tabs.remove(p);
clearInterval(interval);
that.oauthCallback('#' + tab.url.split('#')[1]);
}
});
if (loginWindow.closed) {
clearInterval(interval);
}
}, 250);