Skip to content

Instantly share code, notes, and snippets.

@jcottrell
Last active January 3, 2026 16:01
Show Gist options
  • Select an option

  • Save jcottrell/074b59e37fb6baf53d866695a97cf624 to your computer and use it in GitHub Desktop.

Select an option

Save jcottrell/074b59e37fb6baf53d866695a97cf624 to your computer and use it in GitHub Desktop.
Count browser tabs that match a regular expression
/*
* I needed something to count the number of open browser tabs needing code review
*
* Use the Browser Console in Firefox to run this.
* firefox ctrl+shift+j to open Browser (not web!) console
* If you don't see the Browser Control command line, that's because they hide
* it on you. Go to about:config and change `devtools.chrome.enabled` to
* `true` (with the toggle button).
* https://firefox-source-docs.mozilla.org/devtools-user/browser_console/index.html
*
* Chatgpt helped figure out how to access the tab urls:
* https://chatgpt.com/c/68d68f56-c324-832e-9050-4e1b99fe8352
*/
function getBrowserTabCount(regexp) {
let count = 0
for (let win of Services.wm.getEnumerator('navigator:browser')) {
for (let tab of win.gBrowser.tabs) {
let url = tab.linkedBrowser.currentURI.spec;
if (regexp.test(url)) {
count += 1
}
}
}
return count
}
console.log("Matching tabs:", getBrowserTabCount(/bitbucket.org\/.*?\/.*?\/commits/))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment