commit c90c138fc659905dc90f030aad5af1ef9fa44da0
parent 793fc3bce145d88d30efe245d1eee89a1e7ac061
Author: Julian Descottes <jdescottes@mozilla.com>
Date: Fri, 5 Dec 2025 06:29:51 +0000
Bug 2003857 - [bidi] Reuse waitForVisibility helper to wait for document to be visible r=Sasha
The current helper is named waitForVisibilityChange, which suggests we wait for an event, but this is not the case when looking at the implementation. The window global module is simply polling the document visibility state until it becomes "hidden".
Change the name of the helper to reflect this and add a parameter to also be able to wait for "visible".
Differential Revision: https://phabricator.services.mozilla.com/D275045
Diffstat:
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs b/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs
@@ -318,7 +318,7 @@ class BrowsingContextModule extends RootBiDiModule {
// Bug 1884142: It's not supported on Android for the TestRunner package.
const selectedBrowser = lazy.TabManager.getBrowserForTab(selectedTab);
activated.push(
- this.#waitForVisibilityChange(selectedBrowser.browsingContext)
+ this.#waitForVisibilityState(selectedBrowser.browsingContext, "hidden")
);
}
@@ -686,7 +686,7 @@ class BrowsingContextModule extends RootBiDiModule {
);
}
- let waitForVisibilityChangePromise;
+ let waitForVisibilityStatePromise;
switch (type) {
case "window": {
const newWindow = await lazy.windowManager.openBrowserWindow({
@@ -717,8 +717,9 @@ class BrowsingContextModule extends RootBiDiModule {
// Create the promise immediately, but await it later in parallel with
// waitForInitialNavigationCompleted.
- waitForVisibilityChangePromise = this.#waitForVisibilityChange(
- lazy.TabManager.getBrowserForTab(selectedTab).browsingContext
+ waitForVisibilityStatePromise = this.#waitForVisibilityState(
+ lazy.TabManager.getBrowserForTab(selectedTab).browsingContext,
+ "hidden"
);
}
@@ -750,7 +751,7 @@ class BrowsingContextModule extends RootBiDiModule {
unloadTimeout: 5000,
}
),
- waitForVisibilityChangePromise,
+ waitForVisibilityStatePromise,
blocker.promise,
]);
@@ -772,12 +773,7 @@ class BrowsingContextModule extends RootBiDiModule {
if (!background && !lazy.AppInfo.isAndroid) {
// See Bug 2002097, on slow platforms, the newly created tab might not be
// visible immediately.
- await this._forwardToWindowGlobal(
- "_awaitVisibilityState",
- browser.browsingContext.id,
- { value: "visible" },
- { retryOnAbort: true }
- );
+ await this.#waitForVisibilityState(browser.browsingContext, "visible");
}
return {
@@ -2375,11 +2371,11 @@ class BrowsingContextModule extends RootBiDiModule {
}
}
- #waitForVisibilityChange(browsingContext) {
+ #waitForVisibilityState(browsingContext, expectedState) {
return this._forwardToWindowGlobal(
"_awaitVisibilityState",
browsingContext.id,
- { value: "hidden" },
+ { value: expectedState },
{ retryOnAbort: true }
);
}