tor-browser

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

commit 8589511d8327aa57d344453859329d2b4cef8991
parent bf831dda4234b9f9c65afdc05d1f6aba4461e8a4
Author: Rob Wu <rob@robwu.nl>
Date:   Tue,  7 Oct 2025 12:50:37 +0000

Bug 1992762 - Replace promiseDocumentLoaded usage in ext-identity.js r=zombie

If we attach an "unload" listener to a newly created browser window, it
fires twice: once for initial about:blank, and eventually again when the
window is closed.

Previously the implementation avoided the first by using
`promiseDocumentLoaded`, now we avoid it by filtering the unwanted event
in `unloadListener` itself.

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

Diffstat:
Mtoolkit/components/extensions/parent/ext-identity.js | 11++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/toolkit/components/extensions/parent/ext-identity.js b/toolkit/components/extensions/parent/ext-identity.js @@ -8,8 +8,6 @@ XPCOMUtils.defineLazyGlobalGetters(this, ["XMLHttpRequest", "ChannelWrapper"]); -var { promiseDocumentLoaded } = ExtensionUtils; - const checkRedirected = (url, redirectURI) => { return new Promise((resolve, reject) => { let xhr = new XMLHttpRequest({ mozAnon: false }); @@ -111,14 +109,17 @@ const openOAuthWindow = (details, redirectURI) => { // If the user just closes the window we need to reject unloadListener = () => { + if (window.document.isInitialDocument) { + // The "unload" event also fires when the initial "about:blank" + // document transitions to the browser document, ignore it. + return; + } window.removeEventListener("unload", unloadListener); httpActivityDistributor.removeObserver(httpObserver); reject({ message: "User cancelled or denied access." }); }; - promiseDocumentLoaded(window.document).then(() => { - window.addEventListener("unload", unloadListener); - }); + window.addEventListener("unload", unloadListener); }); };