5

How can I get the current chromium tab URL from an external process in linux programmatically?

There are many similar questions to this one, but I haven't found any with the following requirements

  • Solution should work from outside of the chrome process, i.e. not within javascript or a chrome extension.
  • Solution should not be based on autohotkey, xdotool, wmctrl or similar tools for simulating keyboard or mouse input
  • No OSX or Windows-specific solutions

In firefox, there is mozrepl, which exposes browser internals through an interactive repl over a TCP port. I am looking for something similar in chromium or chrome, even if it means installing a chrome extension.

ealfonso
  • 6,622
  • 5
  • 39
  • 67
  • Can you start chrome with a debugging port? – Tarun Lalwani Jun 25 '18 at 06:19
  • Yes. Although it would be helpful to also know about the security implications of such a solution. – ealfonso Jun 26 '18 at 02:57
  • Not much of security implications, but the problems seems to be able to identify which one is the current tab. See this https://stackoverflow.com/questions/51039569/puppeteer-chrome-get-active-visible-tab – Tarun Lalwani Jun 26 '18 at 12:03
  • This is not going to be easy. There's one way to do it w/o modifying Chromium source code so it will work in Chrome too. You should create an extension which will inform your another native messaging host extension about the current tab's URL. Then that native messaging host extension will write that data to a pipe or whatever IPC method you prefer so that you can use your external process to read that data – Asesh Jun 29 '18 at 05:00

1 Answers1

1

I implemented @Asesh suggestion in https://github.com/erjoalgo/chrome-current-url, it is a chrome extension that exposes the currently active tab's URL through a local http server.

pip install chromeurl
sudo chromeurl --install-manifest native

Then install the extension from the webstore

Finally, query the current chrome url:

$ curl http://localhost:19615/tabs/current/url
https://developer.chrome.com/extensions/activeTab
ealfonso
  • 6,622
  • 5
  • 39
  • 67