Changeset 246456 in webkit


Ignore:
Timestamp:
Jun 14, 2019 8:20:42 PM (5 years ago)
Author:
Devin Rousso
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.

Location:
trunk/Source/WebKit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r246452 r246456  
     12019-06-14  Devin Rousso  <drousso@apple.com>
     2
     3        waitForNavigationToComplete may be called before WebPageProxy knows it's loading
     4        https://bugs.webkit.org/show_bug.cgi?id=198741
     5        <rdar://problem/31164316>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        There's a potential race in `WebAutomationSession::waitForNavigationToCompleteOnPage` when
     10        querying for the `WebPageProxy`'s loading state (via `PageLoadingState::isLoading`), in that
     11        a pending load may be committed _after_ the `WebAutomationSession` checks it's value. This
     12        makes the automation session think that it isn't loading, so it will continue running
     13        commands, which can lead to a JavaScript error ("Callback was not called before the unload
     14        event") as any injected scripts will be cleared by the impending navigation, leaving the
     15        script evaluation callbacks "dangling".
     16
     17        Expose more information from `PageLoadState` about whether it thinks there _may_ be a
     18        navigation currently happening, which the `WebAutomationSession` can use to delay commands.
     19
     20        In the best case, no navigations are "missed".
     21
     22        In the worst case, the automation session will wait `pageLoadTimeout` before continuing.
     23
     24        * UIProcess/Automation/WebAutomationSession.cpp:
     25        (WebKit::WebAutomationSession::waitForNavigationToCompleteOnPage):
     26
     27        * UIProcess/PageLoadState.h:
     28        * UIProcess/PageLoadState.cpp:
     29        (WebKit::PageLoadState::hasUncommittedLoad const): Added.
     30
    1312019-06-14  Youenn Fablet  <youenn@apple.com>
    232
  • trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp

    r245796 r246456  
    485485{
    486486    ASSERT(!m_loadTimer.isActive());
    487     if (loadStrategy == Inspector::Protocol::Automation::PageLoadStrategy::None || !page.pageLoadState().isLoading()) {
     487    if (loadStrategy == Inspector::Protocol::Automation::PageLoadStrategy::None || (!page.pageLoadState().isLoading() && !page.pageLoadState().hasUncommittedLoad())) {
    488488        callback->sendSuccess(JSON::Object::create());
    489489        return;
  • trunk/Source/WebKit/UIProcess/PageLoadState.cpp

    r244361 r246456  
    173173}
    174174
     175bool PageLoadState::hasUncommittedLoad() const
     176{
     177    return isLoading(m_uncommittedState);
     178}
     179
    175180String PageLoadState::activeURL(const Data& data)
    176181{
  • trunk/Source/WebKit/UIProcess/PageLoadState.h

    r244361 r246456  
    126126    bool isFinished() const { return m_committedState.state == State::Finished; }
    127127
     128    bool hasUncommittedLoad() const;
     129
    128130    const String& provisionalURL() const { return m_committedState.provisionalURL; }
    129131    const String& url() const { return m_committedState.url; }
Note: See TracChangeset for help on using the changeset viewer.