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

发布于 2024-09-18 12:39:33 字数 873 浏览 1 评论 0原文

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

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

(通过文件中的选项卡,我还可以使用 GitSVN,或任何存储它们的内容,并可选择查找一些“我在浏览器中看到但不记得是什么”的链接是的。)

到目前为止我得到了什么:

我能够得到一些 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

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

初见你 2024-09-25 12:39:34
#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   

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

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

故事↓在人 2024-09-25 12:39:33

使用 PoshCode 中的 JSON 模块,这看起来是正确的(请记住:我在 Firefox 4 上测试了这一点,其中选项卡全景会产生“隐藏”选项卡,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

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

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.

请叫√我孤独 2024-09-25 12:39:33

我建议使用 brotab 获取所有打开的选项卡的 URL:

pip install brotab
brotab install

同时安装 Web 扩展: https://addons.mozilla.org/en-US/firefox/addon /brotab/

重新启动 Firefox,您可以使用 brotab list 进行解析:

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

然后用普通 Firefox 打开 urls-backup.txt 中的所有 URL:

while read url; do
    firefox "$url"
done < urls-backup.txt

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
两相知 2024-09-25 12:39:33

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

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文