diff --git a/src/zen/common/modules/ZenStartup.mjs b/src/zen/common/modules/ZenStartup.mjs index d64378d3b..31c339d21 100644 --- a/src/zen/common/modules/ZenStartup.mjs +++ b/src/zen/common/modules/ZenStartup.mjs @@ -11,6 +11,9 @@ class ZenStartup { #hasInitializedLayout = false; isReady = false; + promiseInitialized = new Promise(resolve => { + this.promiseInitializedResolve = resolve; + }); init() { this.openWatermark(); @@ -94,6 +97,8 @@ class ZenStartup { .getElementById("tabbrowser-arrowscrollbox") .setAttribute("orient", "vertical"); this.isReady = true; + this.promiseInitializedResolve(); + delete this.promiseInitializedResolve; }); } diff --git a/src/zen/sessionstore/ZenWindowSync.sys.mjs b/src/zen/sessionstore/ZenWindowSync.sys.mjs index 22a53199f..2b95cf218 100644 --- a/src/zen/sessionstore/ZenWindowSync.sys.mjs +++ b/src/zen/sessionstore/ZenWindowSync.sys.mjs @@ -810,11 +810,18 @@ class nsZenWindowSync { aOtherTab, () => { this.log(`Swapping docshells between windows for tab ${aOurTab.id}`); - aOurTab.ownerGlobal.gBrowser.swapBrowsersAndCloseOther( - aOurTab, - aOtherTab, - false - ); + try { + aOurTab.ownerGlobal.gBrowser.swapBrowsersAndCloseOther( + aOurTab, + aOtherTab, + false + ); + } catch (e) { + console.error( + `Error swapping browsers for tabs ${aOurTab.id} and ${aOtherTab.id}:`, + e + ); + } // Swap permanent keys if (!onClose) { @@ -1221,9 +1228,15 @@ class nsZenWindowSync { {}, /* zenForceSync = */ true ); - win.gZenWorkspaces.promiseInitialized.then(() => { - moveAllTabsToWindow(); - }); + win.addEventListener( + "MozBeforeInitialXULLayout", + () => { + win.gZenStartup.promiseInitialized.then(() => { + moveAllTabsToWindow(); + }); + }, + { once: true } + ); return; } moveAllTabsToWindow(true);