[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor-browser] 20/76: Bug 1739008 - [marionette] Monitor navigation using the webprogresslistener for NewSession. r=whimboo, a=RyanVM
This is an automated email from the git hooks/post-receive script.
richard pushed a commit to branch tor-browser-91.8.0esr-11.0-1
in repository tor-browser.
commit 3eeac87680a0daf536e3862a3fe0fdef64395abb
Author: Julian Descottes <jdescottes@xxxxxxxxxxx>
AuthorDate: Mon Nov 8 09:35:48 2021 +0000
Bug 1739008 - [marionette] Monitor navigation using the webprogresslistener for NewSession. r=whimboo, a=RyanVM
---
remote/marionette/driver.js | 44 ++++++++++++++++++++++++++++++++++++++-----
remote/marionette/navigate.js | 8 +-------
2 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/remote/marionette/driver.js b/remote/marionette/driver.js
index 9560b051752c5..133f4dfdd52db 100644
--- a/remote/marionette/driver.js
+++ b/remote/marionette/driver.js
@@ -576,14 +576,48 @@ GeckoDriver.prototype.newSession = async function(cmd) {
if (this.curBrowser.tab) {
const browsingContext = this.curBrowser.contentBrowser.browsingContext;
this.currentSession.contentBrowsingContext = browsingContext;
- // If the currently selected tab is loading, wait until it's done.
+
+ let resolveNavigation;
+
+ // Prepare a promise that will resolve upon a navigation.
+ const onProgressListenerNavigation = new Promise(
+ resolve => (resolveNavigation = resolve)
+ );
+
+ // Create a basic webprogress listener which will check if the browsing
+ // context is ready for the new session on every state change.
+ const navigationListener = {
+ onStateChange: (progress, request, flag, status) => {
+ const isStop = flag & Ci.nsIWebProgressListener.STATE_STOP;
+ if (isStop) {
+ resolveNavigation();
+ }
+ },
+
+ QueryInterface: ChromeUtils.generateQI([
+ "nsIWebProgressListener",
+ "nsISupportsWeakReference",
+ ]),
+ };
+
+ // Monitor the webprogress listener before checking isLoadingDocument to
+ // avoid race conditions.
+ browsingContext.webProgress.addProgressListener(
+ navigationListener,
+ Ci.nsIWebProgress.NOTIFY_STATE_WINDOW |
+ Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT
+ );
+
if (browsingContext.webProgress.isLoadingDocument) {
- await navigate.waitForNavigationCompleted(this, () => {}, {
- loadEventExpected: true,
- unknownState: true,
- });
+ await onProgressListenerNavigation;
}
+ browsingContext.webProgress.removeProgressListener(
+ navigationListener,
+ Ci.nsIWebProgress.NOTIFY_STATE_WINDOW |
+ Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT
+ );
+
this.curBrowser.contentBrowser.focus();
}
diff --git a/remote/marionette/navigate.js b/remote/marionette/navigate.js
index dbb02b55fd43a..50a0bce413d5a 100644
--- a/remote/marionette/navigate.js
+++ b/remote/marionette/navigate.js
@@ -201,9 +201,6 @@ navigate.refresh = async function(browsingContext) {
* @param {boolean=} requireBeforeUnload
* If false and no beforeunload event is fired, abort waiting
* for the navigation. Defaults to true.
- * @param {boolean=} unknownState
- * Needs to be true if a navigation check is resumed and the current
- * state of navigation is unknown. Defaults to false.
*/
navigate.waitForNavigationCompleted = async function waitForNavigationCompleted(
driver,
@@ -214,7 +211,6 @@ navigate.waitForNavigationCompleted = async function waitForNavigationCompleted(
browsingContextFn = driver.getBrowsingContext.bind(driver),
loadEventExpected = true,
requireBeforeUnload = true,
- unknownState = false,
} = options;
const chromeWindow = browsingContextFn().topChromeWindow;
@@ -231,9 +227,7 @@ navigate.waitForNavigationCompleted = async function waitForNavigationCompleted(
let browsingContextChanged = false;
let seenBeforeUnload = false;
-
- // With an unknown state assume that unload has already been received.
- let seenUnload = unknownState;
+ let seenUnload = false;
let unloadTimer;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits