Title: [246456] trunk/Source/WebKit
Revision
246456
Author
[email protected]
Date
2019-06-14 20:20:42 -0700 (Fri, 14 Jun 2019)

Log Message

waitForNavigationToComplete may be called before WebPageProxy knows it's loading
https://bugs.webkit.org/show_bug.cgi?id=198741
<rdar://problem/31164316>

Reviewed by Joseph Pecoraro.

There's a potential race in `WebAutomationSession::waitForNavigationToCompleteOnPage` when
querying for the `WebPageProxy`'s loading state (via `PageLoadingState::isLoading`), in that
a pending load may be committed _after_ the `WebAutomationSession` checks it's value. This
makes the automation session think that it isn't loading, so it will continue running
commands, which can lead to a _javascript_ error ("Callback was not called before the unload
event") as any injected scripts will be cleared by the impending navigation, leaving the
script evaluation callbacks "dangling".

Expose more information from `PageLoadState` about whether it thinks there _may_ be a
navigation currently happening, which the `WebAutomationSession` can use to delay commands.

In the best case, no navigations are "missed".

In the worst case, the automation session will wait `pageLoadTimeout` before continuing.

* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::waitForNavigationToCompleteOnPage):

* UIProcess/PageLoadState.h:
* UIProcess/PageLoadState.cpp:
(WebKit::PageLoadState::hasUncommittedLoad const): Added.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (246455 => 246456)


--- trunk/Source/WebKit/ChangeLog	2019-06-15 03:09:19 UTC (rev 246455)
+++ trunk/Source/WebKit/ChangeLog	2019-06-15 03:20:42 UTC (rev 246456)
@@ -1,3 +1,33 @@
+2019-06-14  Devin Rousso  <[email protected]>
+
+        waitForNavigationToComplete may be called before WebPageProxy knows it's loading
+        https://bugs.webkit.org/show_bug.cgi?id=198741
+        <rdar://problem/31164316>
+
+        Reviewed by Joseph Pecoraro.
+
+        There's a potential race in `WebAutomationSession::waitForNavigationToCompleteOnPage` when
+        querying for the `WebPageProxy`'s loading state (via `PageLoadingState::isLoading`), in that
+        a pending load may be committed _after_ the `WebAutomationSession` checks it's value. This
+        makes the automation session think that it isn't loading, so it will continue running
+        commands, which can lead to a _javascript_ error ("Callback was not called before the unload
+        event") as any injected scripts will be cleared by the impending navigation, leaving the
+        script evaluation callbacks "dangling".
+
+        Expose more information from `PageLoadState` about whether it thinks there _may_ be a
+        navigation currently happening, which the `WebAutomationSession` can use to delay commands.
+
+        In the best case, no navigations are "missed".
+
+        In the worst case, the automation session will wait `pageLoadTimeout` before continuing.
+
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::WebAutomationSession::waitForNavigationToCompleteOnPage):
+
+        * UIProcess/PageLoadState.h:
+        * UIProcess/PageLoadState.cpp:
+        (WebKit::PageLoadState::hasUncommittedLoad const): Added.
+
 2019-06-14  Youenn Fablet  <[email protected]>
 
         WebProcessPool::clearWebProcessHasUploads cannot assume its given processIdentifier is valid

Modified: trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp (246455 => 246456)


--- trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2019-06-15 03:09:19 UTC (rev 246455)
+++ trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2019-06-15 03:20:42 UTC (rev 246456)
@@ -484,7 +484,7 @@
 void WebAutomationSession::waitForNavigationToCompleteOnPage(WebPageProxy& page, Inspector::Protocol::Automation::PageLoadStrategy loadStrategy, Seconds timeout, Ref<Inspector::BackendDispatcher::CallbackBase>&& callback)
 {
     ASSERT(!m_loadTimer.isActive());
-    if (loadStrategy == Inspector::Protocol::Automation::PageLoadStrategy::None || !page.pageLoadState().isLoading()) {
+    if (loadStrategy == Inspector::Protocol::Automation::PageLoadStrategy::None || (!page.pageLoadState().isLoading() && !page.pageLoadState().hasUncommittedLoad())) {
         callback->sendSuccess(JSON::Object::create());
         return;
     }

Modified: trunk/Source/WebKit/UIProcess/PageLoadState.cpp (246455 => 246456)


--- trunk/Source/WebKit/UIProcess/PageLoadState.cpp	2019-06-15 03:09:19 UTC (rev 246455)
+++ trunk/Source/WebKit/UIProcess/PageLoadState.cpp	2019-06-15 03:20:42 UTC (rev 246456)
@@ -172,6 +172,11 @@
     return isLoading(m_committedState);
 }
 
+bool PageLoadState::hasUncommittedLoad() const
+{
+    return isLoading(m_uncommittedState);
+}
+
 String PageLoadState::activeURL(const Data& data)
 {
     // If there is a currently pending URL, it is the active URL,

Modified: trunk/Source/WebKit/UIProcess/PageLoadState.h (246455 => 246456)


--- trunk/Source/WebKit/UIProcess/PageLoadState.h	2019-06-15 03:09:19 UTC (rev 246455)
+++ trunk/Source/WebKit/UIProcess/PageLoadState.h	2019-06-15 03:20:42 UTC (rev 246456)
@@ -125,6 +125,8 @@
     bool isCommitted() const { return m_committedState.state == State::Committed; }
     bool isFinished() const { return m_committedState.state == State::Finished; }
 
+    bool hasUncommittedLoad() const;
+
     const String& provisionalURL() const { return m_committedState.provisionalURL; }
     const String& url() const { return m_committedState.url; }
     const String& unreachableURL() const { return m_committedState.unreachableURL; }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to