How do I get the URL of the active Google Chrome tab in Windows?

Viewed 13950

How can my Python script get the URL of the currently active Google Chrome tab in Windows? This has to be done without interrupting the user, so sending key strokes to copy/paste is not an option.

3 Answers

I quite new to StackOverFlow so apologies if the comment is out of tone.

After looking at :

  • Selenium,
  • launching chrome://History directly,
  • doing some keyboard emulation : copy/paste with Pywinauto,
  • trying to use SOCK_RAW connections to capture the headers as per the Network tab of the DevTool (this one was very interesting),
  • trying to get text of the omnibus/searchBar window element,
  • closing and reopening chrome to read the history tables, ....

I resulted in copy/pasting the History file itself (\AppData\Local\Google\Chrome\User Data\Default\History) into my application folder when the title of the window (retrieved using the hwnd + win32) is missing from "my" urls table. This can be done even if the sqlite db is locked and does not interfere with the user experience.

Very basic solution that requires : sqlite3, psutil, win32gui. Hope that helps.

Related