How to export all URLs of Firefox tabs at once

I’ve seen the following script proposed on the technet script gallery that should show me “How to export all URLs of Firefox tabs at once”.

I said “should” because it actually doesn’t always work on my computer and there’s no error handling in any way in the proposed code 😦
firefox-tabs-01

First, to save you the hassle of trying that script, you can just open Tools/Options in Firefox and set the following. Even if you’ve 1000 tabs, the browser will open in a few minutes and restore the gazillion tabs without you to have to temporarily record the URL of each Firefox tabs that you want to open in the next session:firefox-tabs-02

Back to the proposed script. It actually threw the following error:
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Why? Because when you have a gazillion of tabs (whatever that means), your Mozilla .js file that stores the JSON data about your tabs can be quite big.
I found the following post in the Windows PowerShell forum that made me go this way:

try {
Add-Type -AssemblyName System.Web.Extensions
$javaScriptSerializer = New-Object System.Web.Script.Serialization.JavaScriptSerializer
$javaScriptSerializer.MaxJsonLength = [System.Int32]::MaxValue
$javaScriptSerializer.RecursionLimit = 99
(
(
$javaScriptSerializer.DeserializeObject(
(Get-Content -Encoding UTF8 -Raw -Path "$($env:APPDATA)\Mozilla\Firefox\Profiles\*\sessionstore-backups\recovery.js" -ErrorAction Stop).Trim('()')
)['windows']
) | Select -First 1
)['tabs'] |
Where { -not($_.hidden) } |
ForEach-Object {
$e = @($_.entries)[-1]
[pscustomobject]@{
url = ($e)['url']
title= ($e)['title']
}
}
} catch {
Write-Warning -Message "Failed because $($_.Exception.Message)"
}
view raw sample-json.ps1 hosted with ❤ by GitHub

1 thought on “How to export all URLs of Firefox tabs at once

  1. Pingback: Dew Drop - December 22, 2016 (#2389) - Morning Dew

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.