Closing popup window created by Google Chrome extension

I'm trying to create a Chrome extension that is a replacement for the Delicious bookmarklet. I know there's already an extension that does it, but the problem with that extension is that after you bookmark a site, the popup window stays open (as opposed to using the bookmarklet, where the popup closes itself after submitting the form. I recreated the extension and ran into the same problem.

Here's my code:


  "name": "Delicious",
  "version": "1.0",
  "description": "Bookmark a site on Delicious",
  "background_page": "background.html",
  "permissions": [ 
  "browser_action": {
    "default_icon": "delicious.png"
  "content_scripts": [
      "matches": ["*"],
      "js": ["contentscript.js"]


chrome.browserAction.onClicked.addListener(function(tab) {
  chrome.tabs.getSelected(null, function(tab) {
    w =''+


if (document.URL == '')
  alert('should have closed by now');

When I click the Delicious button, the popup comes up fine and I can save the bookmark but after I click "Save", the popup does not close. Both alerts show up, but self.close() doesn't seem to do anything. When I remove the URL check in contentscript.js, the popup comes up as normal, the first alert fires right away, and then the popup closes itself (as it should).

Why doesn't this work? It doesn't seem like Chrome is preventing me from doing self.close(). Is Delicious doing something? Is it something else?

The files are here if you want them: [link removed because went out of business]



Try window.close(), but that probably wouldn't work either.

As you are creating regular window (rather than browser action popup), then you can close it using chrome.tabs.remove() from a background page. You can also detect this window from a background page. Something like:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    if(changeInfo.status == "loading") {
        if(tab.url == "") {

I am not sure how Chrome treats created windows though - as tabs or windows. If as windows then above code will be a little different.


I found a very easy work around to this. You just set the selected tab to True and the Popup disappears, like this...

// remove popup by selecting the tab
chrome.tabs.getSelected(null, function(tab) {
    chrome.tabs.update(, { selected: true } )

I've found this solution: chrome.tabs.update({ active: true }); This single line of code closes the browser action's popup window. You even don't need to pass there because by default it is set to id of the current tab. I run it in background page but seems it can be run everywhere in the extension.


getSelected not working for me, so i found this solution

chrome.tabs.create({url: '', active: false});

in background.js you need just



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.