22

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.

5
  • Removed .net tag, this is not a .NET question.
    – Richard
    Sep 9, 2010 at 7:54
  • Ok, feel free to add any appropriate tag.
    – stej
    Sep 9, 2010 at 7:56
  • Not an answer, but when my Firefox crashes (or more often my whole system), it does save my tabs, and allow me to reopen them on next startup... which Firefox version do you use ?
    – Bahbar
    Sep 9, 2010 at 8:00
  • Yes, ff asks me if I want to open new session or restore the tabs. But from time to time, it really doesn't offer it. + see updated question.
    – stej
    Sep 9, 2010 at 8:42
  • Nice idea to parse sessionstorage.js to extract the list of URLs, but fortunately there is a much more comfortable way now. Check out sessionmanager.mozdev.org It basically stores a backup of your current Firefox session periodically and offers tons of other features. I can really recommend it.
    – Thorben
    Oct 9, 2015 at 19:22

4 Answers 4

7

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.

1
  • Thx, Jaykul. Since nobody else added any other info, I'll just accept your answer :)
    – stej
    Sep 25, 2010 at 8:29
4

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
3

not in PowerShell but I recently faced this problem so maybe this onliner can help someone:

cat recovery.js | sed 's#{"url":"#\n\n#g' | cut -d'"' -f1 | grep . | sort -u
0
#Test in Firefox 5.0
$sessionStoreFile = "$env:APPDATA\Mozilla\Firefox\Profiles\*.default\sessionstore-backups\recovery.js"
$sessionStoreFileExists = Test-Path $sessionStoreFile
If($sessionStoreFileExists -eq $False) {
    #Test in Firefox 2.0, 3.0 and 4.0
    $sessionStoreFile = "$env:APPDATA\Mozilla\Firefox\Profiles\*.default\sessionstore.js"
}
(Get-Content -Encoding UTF8 -Raw -Path $sessionStoreFile).Trim('()') | ConvertFrom-Json |
Select -Expand Windows | Select -Expand Tabs | 
Where { !$_.hidden } | ForEach { @($_.Entries)[-1] } | 
Select Url, Title | Export-Csv -Path $CsvFile  -Encoding UTF8  -NoTypeInformation   

You can download detail SQL script from how to export all URLs of Firefox tabs at once(PowerShell)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.