Skip to content

Commit 335d7f4

Browse files
domeniczcorpan
authored andcommitted
Abort ongoing navigations when firing certain navigate events
In particular, when firing same-document (synchronous) push/replace navigate events, i.e., those originating from history.pushState()/replaceState(), or fragment navigations. This fixes an assertion failure, and better aligns with Chromium's behavior (although, it does so while avoiding a crash bug that Chromium has). Closes #11184.
1 parent 4989b34 commit 335d7f4

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

source

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96854,6 +96854,45 @@ interface <dfn interface>NavigationDestination</dfn> {
9685496854
null):</p>
9685596855

9685696856
<ol>
96857+
<li>
96858+
<p>If <var>isSameDocument</var> is true:</p>
96859+
96860+
<ol>
96861+
<li>
96862+
<p><span>While</span> <var>navigation</var>'s <span>ongoing <code
96863+
data-x="event-navigate">navigate</code> event</span> is not null:</p>
96864+
96865+
<ol>
96866+
<li><p><span>Abort the ongoing navigation</span> given <var>navigation</var>.</p></li>
96867+
</ol>
96868+
96869+
<div class="note">
96870+
<p>If there is an ongoing cross-document navigation, this means it will signaled to the
96871+
navigation API as aborted, e.g., by firing <code
96872+
data-x="event-navigateerror">navigateerror</code> events. This is somewhat accurate, since
96873+
the next navigation the <code>Document</code> experiences will be this same-document
96874+
navigation, so a developer which was expecting the next navigation completion to be that of
96875+
the cross-document navigation gets a useful signal that this did not happen. However, it is
96876+
also somewhat inaccurate, as the browser will continue to process the ongoing cross-document
96877+
navigation (applying it after this same-document one synchronously finishes).</p>
96878+
96879+
<p>Ultimately, the navigation API gets a bit messy with overlapping cross- and same-document
96880+
navigations, as the <a href="#ongoing-navigation-tracking">ongoing navigation tracking</a>
96881+
machinery and APIs are built to expose only a single ongoing navigation. Web developers will
96882+
be best-served if they do not create such overlapping situations, e.g., by <code
96883+
data-x="">await</code>ing promises returned from <code
96884+
data-x="dom-Navigation-navigate">navigation.navigate()</code> before starting new
96885+
navigations.</p>
96886+
</div>
96887+
96888+
<p class="note">This is a loop, since <span>abort the ongoing navigation</span> can run
96889+
JavaScript (e.g., via the <code data-x="event-navigateerror">navigateerror</code> event),
96890+
which might start a new navigation. Since such a newly-started navigation will be superseded
96891+
by the completion of this navigation, it gets signaled to the navigation API as aborted.</p>
96892+
</li>
96893+
</ol>
96894+
</li>
96895+
9685796896
<li><p>Let <var>event</var> be the result of <span>creating an event</span> given
9685896897
<code>NavigateEvent</code>, in <var>navigation</var>'s <span
9685996898
data-x="concept-relevant-realm">relevant realm</span>.</p></li>

0 commit comments

Comments
 (0)