H3XED

How To Get The Window Count - Chrome Extension Development

Oct 23, 2014   Programming   Nick Vogt   Comments
Please note that this post is over a year old and may contain outdated information.
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).

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.
Share This Post
Twitter

Comments (0)

Share This Post
Twitter
H3XED © Nick Vogt   RSS   Policies   Twitter