From 76966ee1c3564e7f6b95bcc92300a7221abcf7b7 Mon Sep 17 00:00:00 2001 From: "mr. m" Date: Mon, 9 Feb 2026 23:14:51 +0100 Subject: [PATCH] feat: Make sure to always restore tabs from a crash, b=no-bug, c=no-component --- .../sessionstore/SessionStartup-sys-mjs.patch | 13 ++++++++-- .../sessionstore/ZenSessionManager.sys.mjs | 24 +++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/browser/components/sessionstore/SessionStartup-sys-mjs.patch b/src/browser/components/sessionstore/SessionStartup-sys-mjs.patch index 2dceba548..b36096b06 100644 --- a/src/browser/components/sessionstore/SessionStartup-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionStartup-sys-mjs.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/sessionstore/SessionStartup.sys.mjs b/browser/components/sessionstore/SessionStartup.sys.mjs -index 86600ffb5178599ab23270a964064ca657a3283f..e7014e5bce547d37ec92377a95bad5be4d52152e 100644 +index 86600ffb5178599ab23270a964064ca657a3283f..97975af7822a157eafe02ec8bbebdf1a6b564ccb 100644 --- a/browser/components/sessionstore/SessionStartup.sys.mjs +++ b/browser/components/sessionstore/SessionStartup.sys.mjs @@ -40,6 +40,7 @@ ChromeUtils.defineESModuleGetters(lazy, { @@ -28,7 +28,16 @@ index 86600ffb5178599ab23270a964064ca657a3283f..e7014e5bce547d37ec92377a95bad5be if (this._initialState == null) { // No valid session found. this._sessionType = this.NO_SESSION; -@@ -336,12 +339,7 @@ export var SessionStartup = { +@@ -276,6 +279,8 @@ export var SessionStartup = { + `Previous shutdown ok? ${this._previousSessionCrashed}, reason: ${previousSessionCrashedReason}` + ); + ++ lazy.ZenSessionStore.onCrashCheckpoints(this._initialState); ++ + Services.obs.addObserver(this, "sessionstore-windows-restored", true); + + if (this.sessionType == this.NO_SESSION) { +@@ -336,12 +341,7 @@ export var SessionStartup = { isAutomaticRestoreEnabled() { if (this._resumeSessionEnabled === null) { this._resumeSessionEnabled = diff --git a/src/zen/sessionstore/ZenSessionManager.sys.mjs b/src/zen/sessionstore/ZenSessionManager.sys.mjs index 8e5eaa3df..ef163af69 100644 --- a/src/zen/sessionstore/ZenSessionManager.sys.mjs +++ b/src/zen/sessionstore/ZenSessionManager.sys.mjs @@ -10,6 +10,7 @@ const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs", SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs", + SessionStartup: "resource:///modules/sessionstore/SessionStartup.sys.mjs", gWindowSyncEnabled: "resource:///modules/zen/ZenWindowSync.sys.mjs", gSyncOnlyPinnedTabs: "resource:///modules/zen/ZenWindowSync.sys.mjs", DeferredTask: "resource://gre/modules/DeferredTask.sys.mjs", @@ -231,6 +232,13 @@ export class nsZenSessionManager { ); } + get #shouldRestoreFromCrash() { + return ( + lazy.SessionStartup.previousSessionCrashed && + Services.prefs.getBoolPref("browser.sessionstore.resume_from_crash") + ); + } + /** * Called when the session file is read. Restores the sidebar data * into all windows. @@ -270,9 +278,22 @@ export class nsZenSessionManager { }, ]; } + return initialState; + } + + /** + * Called after @onFileRead, when session startup has crash checkpoint information available. + * Restores the sidebar data into all windows, and runs any crash checkpoint related logic, + * such as restoring only pinned tabs if the previous session was not crashed and the user + * preference is set to do so. + * + * @param {object} initialState + * The initial session state read from the session file, possibly modified by onFileRead. + */ + onCrashCheckpoints(initialState) { // When we don't have browser.startup.page set to resume session, // we only want to restore the pinned tabs into the new windows. - if (this.#shouldRestoreOnlyPinned && this.#sidebar?.tabs) { + if (this.#shouldRestoreOnlyPinned && !this.#shouldRestoreFromCrash && this.#sidebar?.tabs) { this.log("Restoring only pinned tabs into windows"); const sidebar = this.#sidebar; sidebar.tabs = (sidebar.tabs || []).filter((tab) => tab.pinned); @@ -304,7 +325,6 @@ export class nsZenSessionManager { this.saveState(Cu.cloneInto(initialState, {})); } delete this._shouldRunMigration; - return initialState; } get #sidebar() {