Get the number of open tabs in Chrome

Hello!

Is there a way to get the number of tabs that are currently open in Chrome?

Hi @bcm yes it is possible.

I done in this logic.

Initialse a count variable (int32) with intial value as zero.

  1. Use a while loop with condition as true.

  2. inside the while loop use element exists with element as chrome window (selector is root node)

That selector in element exist will represent the window of any tab (irrespective of the website
and store its output in a boolean variable let say tabs_exist

after the element exists, use if condition with condition as tabs_exist

if the condition is True:
In then section use send hotkey to close the current tab using ctrl+w
after this increment the count variable by 1 (count = count+1)

if the condition is false:

Then use break activity to break out of loop

  1. Outside the while loop use writeline/message box to display the value of count variable.

See the attached workflow.

BlankProcess2.zip (352.5 KB)

Hope it helps

Regards

Nived N

Happy Automation

1 Like

Hi @bcm,

  1. Every Chrome and Edge instance has an inspect webpage. Both of these show the current sessions and tabs open in different windows of the browser.

    • "chrome://inspect/#pages"
    • "edge://inspect/#pages"
  2. Within this page we can query a javascript code in the Browser's console. This will give us the number of Tabs open in N number of windows in Chrome or Edge.

  3. Finally, we get the value of the query result and subtract 1 from it. We do this to ensure that we do not calculate the session we opened ourselves to check for number of tabs.

    • (Cint(Value)-1).ToString+" tabs are open in the Chrome browser."

Here is a workflow for Chrome browser:
ChromeTabs.xaml (22.1 KB)

The selectors will differ for Edge (Chromium) browser, but the above approach will work there too.

1 Like

That did not work for me. When enter the “chrome://inspect/#pages” into the address bar, chrome goes out to my search engine with that expression.

Intersting solution but I was hoping for something simpler.

Let me see if any simple solution is also available for this :blush:

@bcm - After opening the page ‘chrome://inspect/#pages’ , use sendHotkey or Keyboard shortcuts ==> Ctrl + F (Find) → Then in the searchbar look for ‘InspectPause’ it will give your a count like 1\5 . Here 5-1 = 4 is the count. To get that do a String.Split method to get the second part of the #.

2 Likes

Hi @prasath17,

That’s really the shortest way to get this done. Learnt something new!

@bcm good to know. I think the method I suggest requires you to have Google as the search engine as well. With Google as search engine, the suggested method will work, but solution suggested by @prasath17 will work better.

1 Like

@bcm - Here you go…

image

Output:

image

Thanks Bro @jeevith … But the idea is yours truly…

2 Likes

@prasath17 :clap:t2::clap:t2::fire:

Learned something new .

Thank you

1 Like

Clever solution.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.