2024-06-08 Managing Firefox tabs from command line with brotab

It’s a real shame that you can’t drive Firefox from command line. (In fact, I already complained about it on this very blog.) In an ideal world, you could say firefox --eval '...' and put some (possibly) JavaScript code there to do stuff like navigate to a page, get the URL of the current page, get the list of open tabs etc.

Even in the simplest case I needed – getting information about the current tab – the situation is quite difficult. I spent a considerable amount of time trying to do this in a reliable way, and I still failed. I even fished through the Firefox profile directory to see if there is some obscure json file or sqlite database which holds that information, but I didn’t find it anywhere.

Interestingly, something like what I need (sort of) possible, using a tool called Marionette. It doesn’t seem very well suited for this particular job, however – it’s meant for testing, not regular usage. Technically, you can start Firefox with the --marionette command line parameter and use it (more or less) normally, but I’m not sure about e.g. security implications. Also, the address bar gets a “robot” icon (apparently meaning that this Firefox is not meant to be driven by a human), and (which is probably the most annoying thing) you don’t seem to have access to the saved login data and passwords. With all that in mind, the fact that you need to use Python to drive the Marionette-enabled Firefox seems the least worry (as you may have guessed, I’m not a Python fan).

Fortunately, there is another solution, which is much less comprehensive, but sufficient for quite a few use cases: BroTab. It is a simple command line tool, accompanied by a browser extension, which lets you access your browser’s tabs from command line. It does not allow to do a lot, but it is more than enough for my needs – that is, getting information about the state of Firefox (like how many tabs are open or what the current tab is). If you ever need to control (some aspects) of a brwoser from the command line or get some information about the open tabs, go and check out BroTab – it’s really useful! (And by the way, it seems that it does support at least one other browser besides Firefox.)

CategoryEnglish, CategoryBlog