如何通过命令行应用程序获取Firefox中打开的选项卡列表?

时间:2022-02-16 20:43:51

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.

我在Firefox中打开了很多标签。在我关闭Firefox然后再次运行它之后,选项卡就在那里。没关系。

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?

但是,Firefox有时会崩溃,我的标签会丢失。如何获取打开的选项卡并将列表备份到某个文件?

(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'.)

(使用文件中的选项卡,我也可以使用Git,SVN或其他任何内容来存储它们,并可选择找到我在浏览器中看到的但不记得它是什么的链接。)

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:

我能够获得一些URL,但这似乎不是我在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.

请不要告诉我“使用这个插件或那个插件”。我真的很想按照我的描述去做。

3 个解决方案

#1


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).

使用PoshCode的JSON模块,这看起来是正确的(请记住:我在Firefox 4上进行了测试,其中Tab Panorama导致“隐藏”选项卡,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.

第一行中的所有*都只是为了缩短它。如果您关心搜索的(毫秒)秒,请随意将其扩展到完整路径。

#2


3  

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

不是在PowerShell,但我最近遇到了这个问题所以也许这个在线人可以帮助某人:

cat recovery.js | sed 's#{"url":"#\n\n#g' | cut -d'"' -f1 | grep . | sort -u

#3


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)

您可以从如何一次性导出Firefox选项卡的所有URL下载详细的SQL脚本(PowerShell)

#1


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).

使用PoshCode的JSON模块,这看起来是正确的(请记住:我在Firefox 4上进行了测试,其中Tab Panorama导致“隐藏”选项卡,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.

第一行中的所有*都只是为了缩短它。如果您关心搜索的(毫秒)秒,请随意将其扩展到完整路径。

#2


3  

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

不是在PowerShell,但我最近遇到了这个问题所以也许这个在线人可以帮助某人:

cat recovery.js | sed 's#{"url":"#\n\n#g' | cut -d'"' -f1 | grep . | sort -u

#3


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)

您可以从如何一次性导出Firefox选项卡的所有URL下载详细的SQL脚本(PowerShell)