diff --git a/modules/zen/ZenWindowSync.sys.mjs b/modules/zen/ZenWindowSync.sys.mjs index 8daa5b3..33474a5 100644 --- a/modules/zen/ZenWindowSync.sys.mjs +++ b/modules/zen/ZenWindowSync.sys.mjs @@ -781 +781 @@ class nsZenWindowSync { - return; + return false; @@ -785 +785 @@ class nsZenWindowSync { - return; + return false; @@ -787 +787 @@ class nsZenWindowSync { - await this.#styleSwapedBrowsers(aOurTab, aOtherTab, () => { + return this.#styleSwapedBrowsers(aOurTab, aOtherTab, () => { @@ -789 +789 @@ class nsZenWindowSync { - this.#swapBrowserDocShellsInner(aOurTab, aOtherTab); + return this.#swapBrowserDocShellsInner(aOurTab, aOtherTab); @@ -794,0 +795 @@ class nsZenWindowSync { + return false; @@ -829,7 +830,8 @@ class nsZenWindowSync { - tabListener = new otherTabBrowser.zenTabProgressListener( - aTab, - otherBrowser, - true, - false - ); - otherTabBrowser.zenSetTabProgressListener(aTab, tabListener); + try { + tabListener = new otherTabBrowser.zenTabProgressListener( + aTab, + otherBrowser, + true, + false + ); + otherTabBrowser.zenSetTabProgressListener(aTab, tabListener); @@ -837,3 +839,6 @@ class nsZenWindowSync { - const notifyAll = Ci.nsIWebProgress.NOTIFY_ALL; - filter.addProgressListener(tabListener, notifyAll); - otherBrowser.webProgress.addProgressListener(filter, notifyAll); + const notifyAll = Ci.nsIWebProgress.NOTIFY_ALL; + filter.addProgressListener(tabListener, notifyAll); + otherBrowser.webProgress.addProgressListener(filter, notifyAll); + } catch (e) { + console.error(`Error restoring tab progress listener:`, e); + } @@ -899 +904 @@ class nsZenWindowSync { - return; + return false; @@ -903,0 +909 @@ class nsZenWindowSync { + let didSwap = false; @@ -913,0 +920 @@ class nsZenWindowSync { + didSwap = true; @@ -918,0 +926 @@ class nsZenWindowSync { + return; @@ -962,0 +971,3 @@ class nsZenWindowSync { + if (!didSwap) { + return false; + } @@ -972,9 +983,13 @@ class nsZenWindowSync { - for (let attr of kAttributesToRemove) { - aOtherTab.removeAttribute(attr); - } - if (focus) { - // Recalculate the focus in order to allow the user to continue typing - // inside the web content area without having to click outside and back in. - aOurTab.linkedBrowser.blur(); - aOurTab.documentGlobal.gBrowser._adjustFocusAfterTabSwitch(aOurTab); - aOurTab.linkedBrowser.docShellIsActive = true; + try { + for (let attr of kAttributesToRemove) { + aOtherTab.removeAttribute(attr); + } + if (focus) { + // Recalculate the focus in order to allow the user to continue typing + // inside the web content area without having to click outside and back in. + aOurTab.linkedBrowser.blur(); + aOurTab.documentGlobal.gBrowser._adjustFocusAfterTabSwitch(aOurTab); + aOurTab.linkedBrowser.docShellIsActive = true; + } + } catch (e) { + console.error(`Error cleaning up browser after docshell swap:`, e); @@ -981,0 +997 @@ class nsZenWindowSync { + return true; @@ -997,7 +1013,17 @@ class nsZenWindowSync { - const browserBlob = - await aOtherTab.documentGlobal.PageThumbs.captureToBlob( - aOtherTab.linkedBrowser, - { - fullScale: true, - fullViewport: true, - backgroundColor: "transparent", + let mySrc = ""; + try { + const browserBlob = + await aOtherTab.documentGlobal.PageThumbs.captureToBlob( + aOtherTab.linkedBrowser, + { + fullScale: true, + fullViewport: true, + backgroundColor: "transparent", + } + ); + + mySrc = await new Promise(r => { + const reader = new FileReader(); + if (!browserBlob) { + r(""); + return; @@ -1005,17 +1031,9 @@ class nsZenWindowSync { - ); - - let mySrc = await new Promise(r => { - const reader = new FileReader(); - if (!browserBlob) { - r(""); - return; - } - reader.readAsDataURL(browserBlob); - reader.onloadend = function () { - // result includes identifier 'data:image/png;base64,' plus the base64 data - r(reader.result); - }; - reader.onerror = function () { - r(""); - }; - }); + reader.readAsDataURL(browserBlob); + reader.onloadend = function () { + // result includes identifier 'data:image/png;base64,' plus the base64 data + r(reader.result); + }; + reader.onerror = function () { + r(""); + }; + }); @@ -1023,2 +1041,7 @@ class nsZenWindowSync { - await this.#createPseudoImageForBrowser(otherBrowser, mySrc); - callback(); + await this.#createPseudoImageForBrowser(otherBrowser, mySrc); + } catch (e) { + // The thumbnail only hides the visual transition. It must not block + // the docshell transfer or leave the global swap queue pending. + console.error(`Error preparing docshell swap styling:`, e); + } + const didSwap = callback(); @@ -1026,5 +1049,10 @@ class nsZenWindowSync { - otherBrowser.setAttribute("zen-pseudo-hidden", "true"); - ourBrowser.removeAttribute("zen-pseudo-hidden"); - this.#maybeRemovePseudoImageForBrowser(ourBrowser); - ourBrowser.focus(); - resolve(); + try { + otherBrowser.setAttribute("zen-pseudo-hidden", "true"); + ourBrowser.removeAttribute("zen-pseudo-hidden"); + this.#maybeRemovePseudoImageForBrowser(ourBrowser); + ourBrowser.focus(); + } catch (e) { + console.error(`Error cleaning up docshell swap styling:`, e); + } finally { + resolve(didSwap); + } @@ -1126 +1153,0 @@ class nsZenWindowSync { - targetTab._zenContentsVisible = true; @@ -1130 +1157 @@ class nsZenWindowSync { - delete tab._zenContentsVisible; + let didSwap = false; @@ -1132 +1159 @@ class nsZenWindowSync { - this.#swapBrowserDocShellsInner(targetTab, tab, { + didSwap = this.#swapBrowserDocShellsInner(targetTab, tab, { @@ -1141,0 +1169,5 @@ class nsZenWindowSync { + if (!didSwap) { + continue; + } + targetTab._zenContentsVisible = true; + delete tab._zenContentsVisible; @@ -1186,3 +1218,8 @@ class nsZenWindowSync { - otherTabToShow._zenContentsVisible = true; - delete tab._zenContentsVisible; - await this.#swapBrowserDocShellsAsync(otherTabToShow, tab); + const didSwap = await this.#swapBrowserDocShellsAsync( + otherTabToShow, + tab + ); + if (didSwap) { + otherTabToShow._zenContentsVisible = true; + delete tab._zenContentsVisible; + } @@ -1204 +1240,0 @@ class nsZenWindowSync { - selectedTab._zenContentsVisible = true; @@ -1206 +1241,0 @@ class nsZenWindowSync { - delete otherSelectedTab._zenContentsVisible; @@ -1208 +1243,8 @@ class nsZenWindowSync { - this.#swapBrowserDocShellsAsync(selectedTab, otherSelectedTab) + this.#swapBrowserDocShellsAsync(selectedTab, otherSelectedTab).then( + didSwap => { + if (didSwap) { + selectedTab._zenContentsVisible = true; + delete otherSelectedTab._zenContentsVisible; + } + } + ) @@ -1209,0 +1252,2 @@ class nsZenWindowSync { + } else { + selectedTab._zenContentsVisible = true;