5

So, as many have encountered Chrome's memory usage can be debilitating so I want to PROGRAMMATICALLY access "Chrome's Task Manager" or something equivalent which displays Tabs, their PIDs, AND SUBFRAMES (if possible) so I can create a script to kill them. After a ton of reading, and a lot of answers suggesting that it might not be possible and some where the posters didn't answer the question, I'm just not sure that the answer to THIS question has truly definitively been given yet.

The closest I've gotten is using "chrome://system/" in the omnibox, but when you expand "mem_usage" it doesn't give you useful memory usage numbers per tab at all and lacks the subframes, but with this method I'd planned to use the tab titles to kill the tabs if I could have actually gotten their memory footprint.

I tried using the win32gui's FindWindowEx method to get the text, but that requires you to know the child element of the text displayed so I downloaded "Window Detective" to see the name of the element(s) the "Chrome Task Manager" displays, the PIDs, and Tab names for, but "Window Detective" only came back with the "EmbeddedMenuWindowClass" which is the entire Window, not related to the text displayed.

I made a fleeting effort to use Selenium, but it seems as though it's just not capable of grabbing Special Menus inside of Chrome over just grabbing tab names and elements within a webpage.

I also tried "pywinauto" but that thing's documentation is really, really bad. I've tried using the "connect" method, "hwndwrapper", etc. but grasping what parameters to use, how their being passed, and what to expect along with how to then use the output you get (such as a list of PIDs or Handles) is seriously bungled. I would have loved if the documentation included the OUTPUT so I could actually see what I'm supposed to get so I don't end up rabbit-holing only to find out that everything I've tested doesn't deliver what I'm looking for. Sorry if that sounds whiny, but I spent hours reading the PDF and the official docs and got badly frustrated.

I also tried launching chrome via the Command Line following this document for logging (http://www.chromium.org/for-testers/enable-logging), but it may be a Chromium only thing, but cannot find the logging document that's created and when I redirect its output to a file, I get nothing useful.

But yes, does anyone know how to programmatically access "Chrome Task Manager's" text, or something else that will deliver similar output? Thank you.

FailSafe
  • 482
  • 4
  • 12
  • pywinauto has no tutorial for begginers, but how about the [Getting Started Guide](https://pywinauto.readthedocs.io/en/latest/getting_started.html)? It has output and code samples. Is that really so bad? – Vasily Ryabov Mar 04 '19 at 16:41
  • Also there is one trick to enable accessibility features in Chrome: https://github.com/pywinauto/pywinauto/wiki/How-to-enable-accessibility-(tips-and-tricks) – Vasily Ryabov Mar 04 '19 at 16:43
  • Thanks Vasily. As an entry point, whenever I "Show/Copy Accessibility Tree" via "chrome://accessibility/" Chrome immediately crashes for me. But with the link to the github page I was introduced to Qt which I'm gonna read up on and experiment with in the coming days. pywinauto's Getting Started Guide was a bit better, but I still wound up banging my head out when I got deeper into it. It's just not my mode of documentation I guess. But man, thanks. I really want to screw around with Qt. – FailSafe Mar 05 '19 at 19:26

1 Answers1

-1

Why to just to use the python os module something like this:

import subprocess as sub
p = sub.Popen(['your command', 'arg1', 'arg2', ...],stdout=sub.PIPE,stderr=sub.PIPE)
output, errors = p.communicate()
print output

You can use the command ps to list all the proceses running in chrome however that only will give you the pid not the name of tab to get that I think the only way is to get the data directly from chorme by creating an extension.

https://developer.chrome.com/extensions/tabs

  • Yea, I needed more than just the PIDs, I needed the tab names. I was trying to avoid using an extension so it could be something that could be used locally from outside of Chrome to kill the tabs because when Chrome hangs I can't even access the extensions as far as I know anyway. Thanks for the suggest. I really appreciate it. – FailSafe Mar 04 '19 at 00:08