如果我打开多个选项卡或带有选项卡的其他浏览器然后我关闭了我的机器,或者它崩溃或我杀死了所有进程(.exe),下次我启动浏览器时,所有选项卡将在一个浏览器窗口中重新打开,或多个浏览器窗口,因为它在关闭之前存在。
这些信息存储在哪里?具体来说,URL 存储在哪里以便实现这一点?
会话恢复由sessionstore
组件执行。此处描述了启动恢复过程的高级概述:
/**
* Session Storage and Restoration
*
* Overview
* This service reads user's session file at startup, and makes a determination
* as to whether the session should be restored. It will restore the session
* under the circumstances described below. If the auto-start Private Browsing
* mode is active, however, the session is never restored.
*
* Crash Detection
* The CrashMonitor is used to check if the final session state was successfully
* written at shutdown of the last session. If we did not reach
* 'sessionstore-final-state-write-complete', then it's assumed that the browser
* has previously crashed and we should restore the session.
*
* Forced Restarts
* In the event that a restart is required due to application update or extension
* installation, set the browser.sessionstore.resume_session_once pref to true,
* and the session will be restored the next time the browser starts.
*
* Always Resume
* This service will always resume the session if the integer pref
* browser.startup.page is set to 3.
*/
正如我们所见,它提到了SessionFile
. 查找该文件时,我们会看到这个定义,它表明会话信息存储在sessionstore.jsonlz4
文件中,该文件是一个utf-8 编码的 JSON 文件,用 lz4 压缩。
不幸的是,使用的 lz4 压缩不适用于标准工具,但是有一些关于如何在超级用户上解决这个问题的很好的讨论(例如跳过文件的前 8 个字节)。
另一种可能性是创建一个 WebExtension 并使用您的可执行文件执行本机消息传递。如果给予适当的权限,WebExtensions 可以枚举打开的窗口和选项卡并获取它们的 URL。