Search code examples
javascriptgoogle-chrome-extension

How can I close popup from background?


I know we can close a popup using window.close() from popup.

But is there any way to close the popup from the background page in a Chrome extension?


Solution

  • It's possible with chrome.extension.getViews:

    var windows = chrome.extension.getViews({type: "popup"});
    if (windows.length) {
      windows[0].close(); // Normally, there shouldn't be more than 1 popup 
    } else {
      console.log("There was no popup to close");
    }