Can I control my firefox browser externally (from CLI or make an app) ?

I would like to be able to perform the following actions from outside the browser, for example from a script

‘’’ Obtain a list of all tabs, and which URL is open Obtain a list of all firefox windows and which tab is in each and in what order Obtain a list of firefox running instances Actions on tabs Close a tab Open a new tab and enter URL move a tab in a window’s tab order move a tab to another window mute/unmute a tab make a tab hidden or unhide pin/unpin a tab select/unselect a tab discard a tab reload a tab copy tab body or a specific xpath run a javascript cmdlet, (bookmarklet ? ) Run a function of a script in somethingmonkey bookmarks list all bookmarks folder and bookmarks move a bookmark to another folder delete a bookmark create a bookmark get/change position of a firefox window close a window/ open a new window list installed addons turn an addon on or off ‘’’

I would love to be able to write script, from outside firefox, and do these actions

I have found about the remote debugger, but I can’t figure out if it’s only for debugging firefox on android via adb ? Or can I use that directly from a script ?

firefox-source-docs.mozilla.org/…/index.html#conn…

wiki.mozilla.org/Firefox_OS/Remote_Control

wiki.mozilla.org/Firefox/CommandLineOptions

devtools.debugger.remote-enabled -start-debugger-server ?

Is any of this possible ?

thanks !

lemmyreader,

Your question reminded me of TabFS omar.website/tabfs

Examples of stuff you can do!

  • List the titles of all the tabs you have open
  • Cull tabs like any other files
  • Close all Stack Overflow tabs
  • Save text of all tabs to a file
  • Evaluate JavaScript on a page / watch expressions: demo
  • Get images / scripts / other resource files from page
  • Retrieve what’s playing on YouTube Music: youtube-music-tabfs
  • Reload an extension when you edit its source code
  • TODO: Live edit a running Web page
  • TODO: Import data (JSON? XLS? JS?)
sugar_in_your_tea,

Wow, I never knew I needed this. :)

There’s a bunch of stuff I have wanted to do, but it’s been too annoying:

  • copy URLs from a list of tabs - e.g. to send to a friend/coworker
  • close tabs with a common theme - Github, Confluence, Jira, etc
  • search across open tabs

I’m going to play with this today.

interdimensionalmeme,

That is amazing

leanleft,
@leanleft@lemmy.ml avatar
interdimensionalmeme,

I don’t think firefox is that. At least not on purpose in that context.

ahal,

Sounds like you want Webdriver (aka what Selenium uses).

interdimensionalmeme,

How can I use it from the console with my firefox portable instance ?

ahal,

Try: www.selenium.dev/…/getting_started/

It requires programming knowledge though.

interdimensionalmeme,

Thanks that is a great lead ! So webdriver is a common interface of browser remote control.

Firefox has geckodriver which is a bridge from webdriver protocol to “marionette” which is firefox’ internal remote control protocol.

Apparently, marionette is an open TCP port where you send a command and it replies in json.

I could make a batch script that uses netcat to send my commands ! I just need to figure put how to open that port and what the commands are.

ReversalHatchery,

I just need to figure put how to open that port

I’m not sure what you mean by this, but you should not need to open any ports here, especially to the internet.
Even more, if you can find a setting for it, make firefox listen only on localhost, and not on your network interfaces, because this can quickly become a security nightmare.

ahal, (edited )

Yes, IIRC there’s a pref or env that needs to be set too… I want to say MOZ_ENABLE_MARIONETTE, but it’s been awhile.

Max_P,
@Max_P@lemmy.max-p.me avatar

I think it would be much cleaner to make an addon that does this within the browser and exposes the functionality as a web API (or failing that, connects to a relay server locally). Then you can just use curl to send it commands.

You can look at how KDE Connect / Plasma Browser Integration does it, it does very similar things to integrate with Plasma like go to a tab via KRunner.

interdimensionalmeme,

Also I specifically want that from the console. The console is the universal tgat doesn’t require using some particulat language, or even programming at all

interdimensionalmeme,

How can a browser add on receive commands from command line or open a port ?

ReversalHatchery,

They can’t open a port, but they can connect to webservers (and similar things) on localhost.

There’s also “native messaging”, this might be a better choice if you go the addon route.

boredsquirrel,

Can you please make those into a list?

Yes that is likely possible. Firefox uses SQL databases, json files, and more complex stuff to store all its data.

Reading data is possible but complex. Opening windows is done via CLI interface. Moving the windows is part of your compositor and not Firefox, like KWin on KDE.

interdimensionalmeme,

Oops it looked fine when I posted. And I won’t be back at my computer for quite a while.

It is a series of basic browser function. Mostly list tabs, read tab url, move tab, close tab.

CosmicTurtle0,

It might help to know what exactly you’re trying to do. Are you trying to automate something? Buy stonks? Download porn? Click ads?

There might be better solutions than automating a browser.

interdimensionalmeme,

Control basic browser fonction from console and scripts.

Example, move all tab where url contains testpattern1 to new window. Imagine a sinple example like that for all the listed functions.

Deebster,
@Deebster@lemmy.ml avatar

It only looked ok in the textarea you wrote it in, but the format was wrong.

You have a few options:


<span style="color:#323232;">* lists
</span><span style="color:#323232;">* with a * or -
</span>
  • lists
  • with a * or -


<span style="color:#323232;">Blank
</span><span style="color:#323232;">
</span><span style="color:#323232;">Lines
</span><span style="color:#323232;">
</span><span style="color:#323232;">For paragraphs
</span>

Blank

Lines

For paragraphs



<span style="color:#323232;">Double spaces  
</span><span style="color:#323232;">At end of lines  
</span><span style="color:#323232;">If you don't want paragraphs
</span>

Double spaces
At end of lines
If you don’t want paragraphs


It looked like you were trying to use code formatting which is three backticks, but you used single quotes. This is a backtick: `


<span style="color:#323232;">Then
</span><span style="color:#323232;">It'll  keep   exactly what you write
</span><span style="color:#323232;">l1I|
</span>
Deebster,
@Deebster@lemmy.ml avatar

It’s

  • Obtain a list of all tabs, and which URL is open
  • Obtain a list of all firefox windows and which tab is in each and in what order
  • Obtain a list of firefox running instances
  • Actions on tabs
  • Close a tab
  • Open a new tab and enter URL
  • move a tab in a window’s tab order
  • move a tab to another window
  • mute/unmute a tab
  • make a tab hidden or unhide
  • pin/unpin a tab
  • select/unselect a tab
  • discard a tab
  • reload a tab
  • copy tab body or a specific xpath
  • run a javascript cmdlet, (bookmarklet ? )
  • Run a function of a script in somethingmonkey
  • bookmarks
  • list all bookmarks folder and bookmarks
  • move a bookmark to another folder
  • delete a bookmark
  • create a bookmark
  • get/change position of a firefox window
  • close a window/open a new window
  • list installed addons
  • turn an addon on or off
boredsquirrel,

Thanks for your time haha

  • All
  • Subscribed
  • Moderated
  • Favorites
  • firefox@lemmy.ml
  • kavyap
  • ngwrru68w68
  • tacticalgear
  • DreamBathrooms
  • mdbf
  • magazineikmin
  • thenastyranch
  • Youngstown
  • Durango
  • slotface
  • everett
  • vwfavf
  • rosin
  • anitta
  • Leos
  • khanakhh
  • GTA5RPClips
  • cisconetworking
  • InstantRegret
  • ethstaker
  • osvaldo12
  • tester
  • provamag3
  • modclub
  • cubers
  • normalnudes
  • megavids
  • JUstTest
  • All magazines