commit 75486f100a5da0731574accd4690e36410879eac
parent 39bc83bb8632d54d70542dc5d98c046a317ec99d
Author: Henrik Skupin <mail@hskupin.info>
Date: Thu, 4 Dec 2025 12:20:30 +0000
Bug 2003768 - [marionette] Improve load check for newly opened chrome windows for initial "about:blank" changes. r=jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D274911
Diffstat:
2 files changed, 46 insertions(+), 13 deletions(-)
diff --git a/testing/marionette/harness/marionette_harness/runner/mixins/window_manager.py b/testing/marionette/harness/marionette_harness/runner/mixins/window_manager.py
@@ -89,13 +89,34 @@ class WindowManagerMixin(object):
def loaded(handle):
with self.marionette.using_context("chrome"):
- return self.marionette.execute_script(
+ return self.marionette.execute_async_script(
"""
+ const [handle, resolve] = arguments;
+
const { NavigableManager } = ChromeUtils.importESModule(
"chrome://remote/content/shared/NavigableManager.sys.mjs"
);
- const win = NavigableManager.getBrowsingContextById(arguments[0]).window;
- return win.document.readyState == "complete";
+
+ const isLoaded = window =>
+ window?.document.readyState === "complete" &&
+ !window?.document.isUncommittedInitialDocument;
+
+ const browsingContext = NavigableManager.getBrowsingContextById(handle);
+ const targetWindow = browsingContext?.window;
+
+ if (isLoaded(targetWindow)) {
+ resolve();
+ } else {
+ const onLoad = () => {
+ if (isLoaded(targetWindow)) {
+ targetWindow.removeEventListener("load", onLoad);
+ resolve();
+ } else {
+ dump(`** Target window not loaded yet. Waiting for the next "load" event\n`);
+ }
+ };
+ targetWindow.addEventListener("load", onLoad);
+ }
""",
script_args=[handle],
)
@@ -129,12 +150,7 @@ class WindowManagerMixin(object):
)
# Before continuing ensure the window has been completed loading
- Wait(self.marionette).until(
- lambda _: loaded(new_window),
- message="Window with handle '{}'' did not finish loading".format(
- new_window
- ),
- )
+ loaded(new_window)
# Bug 1507771 - Return the correct handle based on the currently selected context
# as long as "WebDriver:NewWindow" is not handled separtely in chrome context
diff --git a/testing/web-platform/mozilla/tests/webdriver/support/fixtures.py b/testing/web-platform/mozilla/tests/webdriver/support/fixtures.py
@@ -190,12 +190,16 @@ def new_chrome_window(current_session):
]);
}
+ const isLoaded = window =>
+ window?.document.readyState === "complete" &&
+ !window?.document.isUncommittedInitialDocument;
+
(async function() {
// Open a window, wait for it to receive focus
- let win = window.openDialog(url, null, "chrome,centerscreen");
- let focused = waitForFocus(win);
+ let newWindow = window.openDialog(url, null, "chrome,centerscreen");
+ let focused = waitForFocus(newWindow);
- win.focus();
+ newWindow.focus();
await focused;
// The new window shouldn't get focused. As such set the
@@ -206,7 +210,20 @@ def new_chrome_window(current_session):
await focused;
}
- resolve(win);
+ // Wait for the new window to be finished loading
+ if (isLoaded(newWindow)) {
+ resolve(newWindow);
+ } else {
+ const onLoad = () => {
+ if (isLoaded(newWindow)) {
+ newWindow.removeEventListener("load", onLoad);
+ resolve(newWindow);
+ } else {
+ dump(`** Target window not loaded yet. Waiting for the next "load" event\n`);
+ }
+ };
+ newWindow.addEventListener("load", onLoad);
+ }
})();
""",
args=[url, focus],