window.open returns undefined in chrome extension

Viewed 18123

I have content script based Chrome extension. I initiate the sign in process through a popup window in the content script.

I open a popup window using the below code and then wait till its closed.

However, I get an 'undefined' from window.open method. Does anybody know why this happens?

loginwin is undefined in below code although the popup window opens up fine with the specified login_url. The code below is called from my content script.

var loginWin = window.open(login_url, 'LoginWindow', "width=655,height=490");
console.log(loginWin);
// Check every 100 ms if the popup is closed.
var finishedInterval = setInterval(function() {
    console.log('checking if loginWin closed');
    if (loginWin.closed) {
        clearInterval(finishedInterval);
        console.log('popup is now closed');
        Backbone.history.navigate('index', true);
    }
}, 1000);
2 Answers

In my case, Chrome was blocking the popup and the user had to unblock by clicking the "blocked popup" icon in the upper-right corner of the window. (They can also enable/disable exceptions under "Content settings..." in Chrome settings.)

I would suggest adding some code after window.open() so that the user knows what to do. For example:

if (!loginWin)
    alert("You must first unblock popups and try again for this to work!");
Related