Skip to content

Instantly share code, notes, and snippets.

@jlewin
Last active March 7, 2023 17:21
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save jlewin/5343915 to your computer and use it in GitHub Desktop.
Save jlewin/5343915 to your computer and use it in GitHub Desktop.
Count of open tabs in Chrome

A quick technique to determine how many tabs are open in Chrome. After a bit of searching I couldn't find any useful solutions and didn't really want to install an extension to see my tab count. This approach uses the chrome.windows module to access the required info and thus must be run from an environment with the appropriate permissions. As such, it's simply a matter of co-opting any extensions background page and executing the script...

Usage

  1. Open the Extensions page; ala chrome://extensions/
  • Inspect the background page of any extension that has the Access Tabs permission
  • Switch to the console tab and execute the included script
  • Review the array of Window objects and their 'tabs' property for the tab count and additional details
chrome.windows.getAll({populate: true}, function(allWindows)
{
console.log(allWindows);
});
@rxw1
Copy link

rxw1 commented Dec 5, 2013

thanks! :)

@rxw1
Copy link

rxw1 commented Jun 23, 2014

For further reference:

chrome.windows.getAll({populate:true},function(windows){
  windows.forEach(function(window){
    window.tabs.forEach(function(tab){
      //collect all of the urls here, I will just log them instead
      console.log(tab.url);
    });
  });
});

Source: http://stackoverflow.com/a/16185419/220472

@alterisian
Copy link

No longer works. Sorry.

@dniku
Copy link

dniku commented May 17, 2017

@alterisian it has just worked for me. I'm on Chrome 58.0.3029.110.

@omril1
Copy link

omril1 commented Aug 7, 2017

@Pastafarianist Does it still work? I'm on 59.0.3071.115 and can't use this functionality.

@hfaran
Copy link

hfaran commented Oct 27, 2017

chrome.windows.getAll({populate:true},function(windows){
  var i=0; 
  windows.forEach(function(window){
    window.tabs.forEach(function(tab){
      //collect all of the urls here, I will just log them instead
      console.log(tab.url);
      i++;
    });
  });
  console.log(i);
});

Works for me in Chrome 61.0.3163.100 (Official Build) (64-bit).

Remember to open a page which has Access Tabs permission as mentioned in the original gist (I opened the extension page for OneTab for example, which I have installed and obviously had that permission).

@Zibri
Copy link

Zibri commented Jun 30, 2018

OMG... I have 174 tabs open right now :O

@SmartManoj
Copy link

extension page

I used Tampermonkey

@edmontdants
Copy link

OMG... I have 174 tabs open right now :O

r u kidding i've 2226 tab opened right now in 68 window one of them have 174 opened tab 😂

@Farbod29
Copy link

Farbod29 commented Sep 8, 2021

Thanks all esp, @jlewin @hfaran @rwilhelm really cool solutions all worked for me I made all solution + event listener that when the user open the new tab it counts all together in a simple Chrome Extension under this GitHub links 👍 +1
Link:
https://github.com/Farbod29/extract-and-find-the-new-tab-frome-the-browser-with-chrome-extention

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment