tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 48564078bcf0ecc4dcee85da6765e42992bebaeb
parent 16bb714ac1314f5cafdfa162a66f0d8e33ebb7b1
Author: Matthew Kwee <mkwee@andrew.cmu.edu>
Date:   Wed, 10 Dec 2025 17:46:37 +0000

Bug 1938752 - Prevent unexpected session restoration when private window opens before normal window. r=sfoster,sessionstore-reviewers

Only restore the deferred session if SessionStartup indicates we should restore. This prevents session from being restored unexpectedly when a private window is opened first followed by a normal window. This bug does not affect the MacOS version of Firefox.

Differential Revision: https://phabricator.services.mozilla.com/D275546

Diffstat:
Mbrowser/components/sessionstore/SessionStore.sys.mjs | 25+++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs @@ -2142,16 +2142,21 @@ var SessionStoreInternal = { // after starting up with a single private or web app window. // Let's restore the session we actually wanted to restore at startup. } else if (this._deferredInitialState && isRegularWindow) { - // global data must be restored before restoreWindow is called so that - // it happens before observers are notified - this._globalState.setFromState(this._deferredInitialState); - - this._restoreCount = this._deferredInitialState.windows - ? this._deferredInitialState.windows.length - : 0; - this.restoreWindows(aWindow, this._deferredInitialState, { - firstWindow: true, - }); + // Only restore the deferred session if SessionStartup indicates we should + // restore (e.g., crash recovery or user preference to restore sessions). + // This prevents incorrect session restoration when a private window was + // opened first followed by a normal window. See Bug 1938752. + if (lazy.SessionStartup.willRestore()) { + // global data must be restored before restoreWindow is called so that + // it happens before observers are notified + this._globalState.setFromState(this._deferredInitialState); + this._restoreCount = this._deferredInitialState.windows + ? this._deferredInitialState.windows.length + : 0; + this.restoreWindows(aWindow, this._deferredInitialState, { + firstWindow: true, + }); + } this._deferredInitialState = null; } else if ( this._restoreLastWindow &&