Open and Close a Simple Popup Window in Chrome Extension

I have a Chrome extension should allow the users to log in with Google via a popup because it won't display in the iframe. I was doing this with which worked fine except that I could not close the pop-up after the user logged in.

I have been trying with no success to use instead of in hopes that I will be able to close the popup once I detect via the URL that they have successfully logged in.

In popup_google.js I have simple function:

function login(login_url) {
    // var win =, "windowname1", 'width=800, height=600');{'url': '', 'type': 'popup'}, function(window) { });

The login function is called via "onclick" something like this:

<a href='#' onClick='login("");' id="loginText"> Click here to login </a>

I can't for the life of me get the to open a new popup window, even in the simplest form you see here, but works like a charm (I just can't seem to get it closed in Chrome).


It looks like your popup_google.js file is a content script. Content scripts cannot use chrome.*APIs except for a few exceptions. This is why you can't use the chrome.window API at all. On a similar note, adding "tabs" to the permissions utilizes the chrome.Tabs API which is not one of the few allowed chrome APIs for content scripts. Try using the matches: [/url pattern/] field to limit the urls in which your content script will run, as shown in the content script API.

Content scripts have full access to the DOM but not to any variables or functions defined by the web pages. While you can create your own popup using, the content script has no way to be sure it is referencing the correct 'window' variable when you wish to call window.close() because the script sees two windows: the one it created using and the window loaded on the page's DOM.

Try looking at Chrome's examples using popups and modify them to achieve your desired functionality. Or check out other great SO explanations to develop a working popup login.

Need Your Help

Jenkins clearcase Plugin

plugins jenkins

I am new to Jenkins and looking to download Clearcase plugin for it.

HTML 5 Video Tag

video html5

This is my first dip into HTML5, firstly is there a special way to open the html tag? I read a stack overflow question, which seemed to result in the fact that an rtsp could be srced in a video tag.