Archive
This post is archived and may contain outdated information. It has been set to 'noindex' and should stop showing up in search results.
This post is archived and may contain outdated information. It has been set to 'noindex' and should stop showing up in search results.
How To Get The Window Count - Chrome Extension Development
Oct 23, 2014ProgrammingComments (0)
Use this code to get the number of open Chrome windows. It must be used inside the extension scope, such as on a background or event page. It cannot be used in a content script (though you can pass this information via a message if needed).
The getAll() method of the chrome.windows object sends an array to the callback function. This array contains each window object. You can then use the length property of the array to get the total number of open windows. This includes any non-browser window such as a developer tools popout window.
chrome.windows.getAll(function(windows) {
console.log(windows.length);
});
The getAll() method of the chrome.windows object sends an array to the callback function. This array contains each window object. You can then use the length property of the array to get the total number of open windows. This includes any non-browser window such as a developer tools popout window.