commit c7904291c05c743d0bce9260e0668e3a9beebc3c parent a2ac368a16af004d63eec30654cfb1af2e7f5435 Author: Henrik Skupin <mail@hskupin.info> Date: Tue, 23 Dec 2025 12:23:00 +0000 Bug 1934326 - [remote] Check for browsing context discarded in "waitForCurrentWindowGlobal()". r=Sasha Differential Revision: https://phabricator.services.mozilla.com/D277409 Diffstat:
| M | remote/shared/messagehandler/transports/BrowsingContextUtils.sys.mjs | | | 13 | +++++++++---- |
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/remote/shared/messagehandler/transports/BrowsingContextUtils.sys.mjs b/remote/shared/messagehandler/transports/BrowsingContextUtils.sys.mjs @@ -188,14 +188,19 @@ export function isBrowsingContextCompatible(browsingContext, options = {}) { * The browsing context to wait for. * * @returns {Promise} - * Promise which resolves when `currentWindowGlobal` is set on the browsing - * context or throws a `DiscardedBrowsingContextError` error if it is still - * not available after 100ms. + * Promise which resolves when `currentWindowGlobal` is available. + * + * @throws DiscardedBrowsingContextError + * Browsing context is discarded or still no + * `currentWindowGlobal` set after 100ms. */ export async function waitForCurrentWindowGlobal(browsingContext) { await lazy.PollPromise( (resolve, reject) => { - if (browsingContext.currentWindowGlobal) { + if (browsingContext.currentWindowGlobal || browsingContext.isDiscarded) { + // If the browsing context is discarded while checking for + // the current window global, return early to avoid waiting + // unnecessarily until the timeout expires. resolve(); } else { reject();