Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get list of open tabs in Firefox via a command-line application?

Tags:

I have a lot of tabs open in Firefox. After I close Firefox and then run it again, the tabs are there. That's all right.

However, from time to time, Firefox crashes and my tabs are lost. How do I get the open tabs and backup the list to some file?

(With tabs in a file, I can also use Git, SVN, or whatever to store them and optionally find some link 'that I saw in my browser but can't remember what it was'.)

What I got so far:

I'm able to get some URLs, but that's doesn't seem to be exactly what I see in Firefox:

$c = ((gc c:\Users\..\AppData\Roaming\Mozilla\Firefox\Profiles\xfvj8vd5.default\sessionstore.js ) -join '')
$sess = [Jayrock.Json.Conversion.JsonConvert]::Import( $c.trim('()') )
$sess.windows[0].tabs |
  % { $_.entries } |
  % { $_.url } |
  Select-Object -Unique

Please, don't tell me "use this addon or that addon". I really would like do it as I described.

like image 993
stej Avatar asked Sep 09 '10 07:09

stej


People also ask

How do I see all open tabs in Firefox?

Firefox lets you find a specific tab when you have a lot of tabs open: Click the List all tabs button in the tab bar. Click Search Tabs in the menu that opens.

How do I use Firefox command line?

You can open the command line interface by pressing Shift+F2.

Which command launches the web browser Firefox from the command line?

On Windows machines, go to Start > Run, and type in "firefox -P" ​On Linux machines, open a terminal and enter "firefox -P"


2 Answers

Using the JSON module from PoshCode, this looks right (bear in mind: I tested this on Firefox 4, where the Tab Panorama results in "hidden" tabs, ymmv).

ConvertFrom-Json -File ~\AppData\R*\M*\F*\P*\*\sessionstore.js -Type PSObject -EA 0 |
Select -Expand Windows | Select -Expand Tabs | 
Where { !$_.hidden } | ForEach { @($_.Entries)[-1] } | 
Select Title, Url

All the * in the first line are just to make it short. Feel free to expand that to the full path if you care about the (milli)seconds spent searching.

like image 181
Jaykul Avatar answered Sep 17 '22 19:09

Jaykul


I'd recommend using brotab to get the URLs of all open tabs:

pip install brotab
brotab install

Install the web extension as well: https://addons.mozilla.org/en-US/firefox/addon/brotab/

Restart Firefox, and you can use brotab list and parse it as so:

bt list | awk -F'\t' '{
    print $2
}' > urls-backup.txt

Then open all URLs in urls-backup.txt with normal Firefox:

while read url; do
    firefox "$url"
done < urls-backup.txt
like image 30
Doron Behar Avatar answered Sep 21 '22 19:09

Doron Behar