Reputation: 41
I need close all tabs in Chrome window via my extension. What is the best practice now? How would you have done?
Upvotes: 2
Views: 6465
Reputation: 10897
In your background page, use chrome.tabs.query(...) to get all tabs, then call chrome.tabs.remove(...) to close that, code will look like:
chrome.tabs.query({}, function (tabs) {
for (var i = 0; i < tabs.length; i++) {
chrome.tabs.remove(tabs[i].id);
}
});
Upvotes: 8
Reputation: 1962
You can only close windows/tabs that you create yourself. That is, you cannot programmatically close a window/tab that the user creates.
For example, if you create a window with window.open() you can close it with window.close().
from https://stackoverflow.com/a/14373670/789377
Upvotes: -2