commit d1180226a76e68cf5ad853792faad5f70364b6f3
parent d6eadc17d8c38c0caf29ad83bbe10b7826710d8d
Author: Julian Descottes <jdescottes@mozilla.com>
Date: Thu, 11 Dec 2025 07:24:33 +0000
Bug 2003857 - [bidi] Update helper to wait for visibility to use visibilityChange event r=Sasha
The current polling approach is very likely to miss updates and face race issues.
Differential Revision: https://phabricator.services.mozilla.com/D275234
Diffstat:
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/remote/webdriver-bidi/modules/windowglobal/browsingContext.sys.mjs b/remote/webdriver-bidi/modules/windowglobal/browsingContext.sys.mjs
@@ -20,7 +20,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
OriginType:
"chrome://remote/content/webdriver-bidi/modules/root/browsingContext.sys.mjs",
OwnershipModel: "chrome://remote/content/webdriver-bidi/RemoteValue.sys.mjs",
- PollPromise: "chrome://remote/content/shared/Sync.sys.mjs",
pprint: "chrome://remote/content/shared/Format.sys.mjs",
});
@@ -498,14 +497,14 @@ class BrowsingContextModule extends WindowGlobalBiDiModule {
async _awaitVisibilityState(options) {
const { value } = options;
const win = this.messageHandler.window;
-
- await lazy.PollPromise((resolve, reject) => {
- if (win.document.visibilityState === value) {
- resolve();
- } else {
- reject();
- }
- });
+ if (win.document.visibilityState !== value) {
+ await new Promise(r => {
+ // The visibilityState can only be hidden or visible, so if the current
+ // value is not the expected one, the next visibilitychange event is
+ // guaranteed to have the correct value.
+ win.document.addEventListener("visibilitychange", r, { once: true });
+ });
+ }
}
_getBaseURL() {