Skip to content

Commit be0a6ae

Browse files
committed
Add navigation hooks for WebDriver BiDi history traversal
WebDriver BiDi wants to invoke the 'traverse the history by a delta` algorithm, and get a callback whenever the algoritihm has run to completion, either by failing or by the navigation or state restoration completing. w3c/webdriver-bidi#109 is the WebDriver BiDi side of this change.
1 parent 9fa2a91 commit be0a6ae

File tree

1 file changed

+118
-42
lines changed

1 file changed

+118
-42
lines changed

source

Lines changed: 118 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4147,6 +4147,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
41474147
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-fragment-navigated">WebDriver BiDi fragment navigated</dfn></li>
41484148
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-dom-content-loaded">WebDriver BiDi DOM content loaded</dfn></li>
41494149
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-load-complete">WebDriver BiDi load complete</dfn></li>
4150+
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-page-show">WebDriver BiDi page show</dfn></li>
4151+
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-pop-state">WebDriver BiDi pop state</dfn></li>
41504152
</ul>
41514153
</dd>
41524154

@@ -84908,16 +84910,23 @@ interface <dfn interface>History</dfn> {
8490884910

8490984911
<hr>
8491084912

84911-
<p>To <dfn>traverse the history by a delta</dfn> given <var>delta</var> and <span>browsing
84912-
context</span> <var>source browsing context</var>, the user agent must append a <span
84913-
data-x="concept-task">task</span> to this <span>top-level browsing context</span>'s <span>session
84914-
history traversal queue</span>, the <span data-x="concept-task">task</span> consisting of running
84915-
the following steps:</p>
84913+
<p>To <dfn>traverse the history by a delta</dfn> given <var>delta</var>, <span>browsing
84914+
context</span> <var>source browsing context</var>, and an optional <span
84915+
data-x="navigation-id">navigation id</span> <var>navigationId</var> (default null),
84916+
the user agent must append a <span data-x="concept-task">task</span> to this <span>top-level
84917+
browsing context</span>'s <span>session history traversal queue</span>, the <span
84918+
data-x="concept-task">task</span> consisting of running the following steps:</p>
8491684919

8491784920
<ol>
8491884921
<li><p>If the index of the <span>current entry of the joint session history</span> plus
8491984922
<var>delta</var> is less than zero or greater than or equal to the number of items in the
84920-
<span>joint session history</span>, then return.</p>
84923+
<span>joint session history</span>, invoke <span>WebDriver BiDi navigation failed</span>
84924+
with <var>source browsing context</var>, and a <span>WebDriver BiDi navigation status</span> whose <span
84925+
data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
84926+
data-x="navigation-status-status">status</span> is "<code
84927+
data-x="navigation-status-canceled">canceled</code>", and <span
84928+
data-x="navigation-status-url">url</span> is <var>resource</var>'s <span
84929+
data-x="concept-request-url">url</span>, then return.</p></li>
8492184930

8492284931
<li><p>Let <var>specified entry</var> be the entry in the <span>joint session
8492384932
history</span> whose index is the sum of <var>delta</var> and the index of the
@@ -84927,17 +84936,32 @@ interface <dfn interface>History</dfn> {
8492784936
the <var>specified entry</var>.</p></li>
8492884937

8492984938
<li><p>If <var>source browsing context</var> is not <span>allowed to navigate</span>
84930-
<var>specified browsing context</var>, then return.</p></li>
84939+
<var>specified browsing context</var>, then invoke <span>WebDriver BiDi navigation failed</span> with
84940+
with <var>source browsing context</var>, and a <span>WebDriver BiDi navigation status</span> whose <span
84941+
data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
84942+
data-x="navigation-status-status">status</span> is "<code
84943+
data-x="navigation-status-canceled">canceled</code>", and <span
84944+
data-x="navigation-status-url">url</span> is <var>resource</var>'s <span
84945+
data-x="concept-request-url">url</span>, then return.</p></li>
8493184946

8493284947
<li><p>If the <var>specified browsing context</var>'s <span>active document</span>'s <span>unload
84933-
counter</span> is greater than 0, then return.</p></li>
84948+
counter</span> is greater than 0, then invoke <span>WebDriver BiDi navigation failed</span> with
84949+
with <var>source browsing context</var>, and a <span>WebDriver BiDi navigation status</span> whose <span
84950+
data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
84951+
data-x="navigation-status-status">status</span> is "<code
84952+
data-x="navigation-status-canceled">canceled</code>", and <span
84953+
data-x="navigation-status-url">url</span> is <var>resource</var>'s <span
84954+
data-x="concept-request-url">url</span>, then return.</p></li>
8493484955

8493584956
<li>
8493684957
<p><span>Queue a global task</span> on the <span>history traversal task source</span> given
8493784958
<var>specified browsing context</var>'s <span>active window</span> to perform the following
8493884959
steps:</p>
8493984960

8494084961
<ol>
84962+
<li><p>If <var>navigationId</var> is null, let <var>navigation id</var> be the result of
84963+
<span>generating a random UUID</span>. <ref spec=UUID></p></li>
84964+
8494184965
<li><p>If there is an ongoing attempt to navigate <var>specified browsing context</var>
8494284966
that has not yet <span data-x="concept-navigate-mature">matured</span> (i.e. it has not passed the
8494384967
point of making its <code>Document</code> the <span>active document</span>), then cancel that
@@ -84951,7 +84975,13 @@ interface <dfn interface>History</dfn> {
8495184975
<ol>
8495284976
<li><p><span>Prompt to unload</span> the <span>active document</span> of the <var>specified
8495384977
browsing context</var>. If the user <span>refused to allow the document to be
84954-
unloaded</span>, then return.</p></li>
84978+
unloaded</span>, then invoke <span>WebDriver BiDi navigation failed</span> with
84979+
with <var>source browsing context</var>, and a <span>WebDriver BiDi navigation status</span>
84980+
whose <span data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
84981+
data-x="navigation-status-status">status</span> is "<code
84982+
data-x="navigation-status-canceled">canceled</code>", and <span
84983+
data-x="navigation-status-url">url</span> is <var>resource</var>'s <span
84984+
data-x="concept-request-url">url</span>, then return.</p></li>
8495584985

8495684986
<li><p><span data-x="unload a document">Unload</span> the <span>active document</span> of the
8495784987
<var>specified browsing context</var>.</p></li>
@@ -84960,7 +84990,8 @@ interface <dfn interface>History</dfn> {
8496084990

8496184991
<li><p><span>Traverse the history</span> of the <var>specified browsing context</var> to
8496284992
the <var>specified entry</var> with <var><span>explicitHistoryNavigation</span></var> set to
84963-
true.</p>
84993+
true, and <span data-x="traverse-history-navigationid">navigation id</span> set to
84994+
<var>navigationId</var>.</p>
8496484995
</ol>
8496584996
</li>
8496684997
</ol>
@@ -86539,8 +86570,6 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
8653986570
context</span>'s <span>active window</span> has <span>transient activation</span>; otherwise
8654086571
false.</p></li>
8654186572

86542-
<li><p>Let <var>navigationStatus</var> be </li>
86543-
8654486573
<li><p>Invoke <span>WebDriver BiDi navigation started</span> with <var>browsingContext</var>, and
8654586574
a new <span>WebDriver BiDi navigation status</span> whose <span
8654686575
data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
@@ -87659,7 +87688,8 @@ new PaymentRequest(&hellip;); // Allowed to use
8765987688
<li><p><span>Traverse the history</span> to <var>sessionHistory</var>'s <span>current
8766087689
entry</span> with <var data-x="traverse-history-hh">historyHandling</var> set to
8766187690
<var>navigationParams</var>'s <span data-x="navigation-params-hh">history
87662-
handling</span>.</p></li>
87691+
handling</span>, and <span data-x="traverse-history-navigationid">navigation id</span>
87692+
set to <var>navigationId</var>.</p></li>
8766387693
</ol>
8766487694
</dd>
8766587695

@@ -87689,7 +87719,9 @@ new PaymentRequest(&hellip;); // Allowed to use
8768987719

8769087720
<li><p><span>Traverse the history</span> to <var>newEntry</var> with
8769187721
<var data-x="traverse-history-hh">historyHandling</var> set to "<code
87692-
data-x="hh-replace">replace</code>".</p></li>
87722+
data-x="hh-replace">replace</code>", and <span
87723+
data-x="traverse-history-navigationid">navigation id</span> set to <var>navigationId</var>.
87724+
</p></li>
8769387725
</ol>
8769487726
</dd>
8769587727

@@ -87718,7 +87750,9 @@ new PaymentRequest(&hellip;); // Allowed to use
8771887750
<li><p><span data-x="list append">Append</span> <var>newEntry</var> to
8771987751
<var>sessionHistory</var>.</p></li>
8772087752

87721-
<li><p><span>Traverse the history</span> to <var>newEntry</var>.</p></li>
87753+
<li><p><span>Traverse the history</span> to <var>newEntry</var> with <span
87754+
data-x="traverse-history-navigationid">navigation id</span> set to <var>navigationId</var>.
87755+
</p></li>
8772287756
</ol>
8772387757
</dd>
8772487758
</dl>
@@ -88111,18 +88145,11 @@ new PaymentRequest(&hellip;); // Allowed to use
8811188145
mode</span>.</p></li>
8811288146

8811388147
<li><p><span>Traverse the history</span> to the new entry, with <var
88114-
data-x="traverse-history-hh">historyHandling</var> set to <var>historyHandling</var> and with
88115-
<var><span>nonBlockingEvents</span></var> set to true. This will <span>scroll to the
88116-
fragment</span> given in what is now the document's <span
88148+
data-x="traverse-history-hh">historyHandling</var> set to <var>historyHandling</var>,
88149+
<var><span>nonBlockingEvents</span></var> set to true, and <span
88150+
data-x="traverse-history-navigationid">navigation id</span> set to <var>navigationId</var>.
88151+
This will <span>scroll to the fragment</span> given in what is now the document's <span
8811788152
data-x="concept-document-url">URL</span>.</p></li>
88118-
88119-
<li><p><p>Invoke <span>WebDriver BiDi fragment navigated</span> with <var>browsingContext</var>,
88120-
and a new <span>WebDriver BiDi navigation status</span> whose <span
88121-
data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
88122-
data-x="navigation-status-url">url</span> is <var>resource</var>'s <span
88123-
data-x="concept-request-url">url</span>, and <span
88124-
data-x="navigation-status-status">status</span> is "<code
88125-
data-x="navigation-status-complete">complete</code>".</p></li>
8812688153
</ol>
8812788154

8812888155
<p class="note">If the scrolling fails because the relevant <span data-x="concept-id">ID</span> has
@@ -88253,8 +88280,9 @@ new PaymentRequest(&hellip;); // Allowed to use
8825388280
with an optional <span>history handling behavior</span> <dfn
8825488281
data-x="traverse-history-hh"><var>historyHandling</var></dfn> (default "<code
8825588282
data-x="hh-default">default</code>"), an optional boolean <dfn><var>nonBlockingEvents</var></dfn>
88256-
(default false), and an optional boolean <dfn><var>explicitHistoryNavigation</var></dfn> (default
88257-
false):</p>
88283+
(default false), an optional boolean <dfn><var>explicitHistoryNavigation</var></dfn> (default
88284+
false), optional <span data-x="navigation-id">navigation id</span>
88285+
<dfn data-x="traverse-history-navigationid"><var>navigationId</var></dfn> (default null):</p>
8825888286

8825988287
<p class="note">This algorithm is not just invoked when <span data-x="traverse the history by a
8826088288
delta">explicitly going back or forwards in the session history</span> &mdash; it is also invoked
@@ -88280,11 +88308,12 @@ new PaymentRequest(&hellip;); // Allowed to use
8828088308
<li>
8828188309
<p><span>Navigate</span><!--DONAV history traversal after eviction--> the <span>browsing
8828288310
context</span> to <var>request</var> with <var data-x="navigation-hh">historyHandling</var>
88283-
set to "<code data-x="hh-entry-update">entry update</code>" and with <var
88311+
set to "<code data-x="hh-entry-update">entry update</code>", with <var
8828488312
data-x="navigation-historypolicycontainer">historyPolicyContainer</var> set to
88285-
<var>entry</var>'s <span data-x="she-policy-container">policy container</span>. The navigation
88286-
must be done using the same <span>source browsing context</span> as was used the first time
88287-
<var>entry</var> was created.</p>
88313+
<var>entry</var>'s <span data-x="she-policy-container">policy container</span>, and with
88314+
<span data-x="navigation-navigationid">navigation id</span> set to <var>navigationId</var>.
88315+
The navigation must be done using the same <span>source browsing context</span> as was
88316+
used the first time <var>entry</var> was created.</p>
8828888317

8828988318
<p class="note">The "<span>navigate</span>" algorithm reinvokes this "traverse" algorithm to
8829088319
complete the traversal, at which point <var>entry</var>'s <span
@@ -88306,6 +88335,20 @@ new PaymentRequest(&hellip;); // Allowed to use
8830688335
<li><p>Let <var>newDocument</var> be <var>entry</var>'s <span
8830788336
data-x="she-document">document</span>.</p></li>
8830888337

88338+
<li><p>If <var>navigationId</var> is null:</p>
88339+
<!-- In practice I think the only case that we use the navigation id in subsequent steps is
88340+
when we have a page loaded from the bfcache, in which case document's navigation id is always null.
88341+
We could just use null as the navigation id in that case, but it would mean a difference between
88342+
a WebDriver-initiated history traversal from the bfcache and a UA initated history traversal. -->
88343+
<ol>
88344+
<li><p>If <var>newDocument</var>'s <span data-x="concept-document-navigation-id">navigation
88345+
id</span> is not null, let <var>navigationId</var> be <var>newDocument</var>'s <span
88346+
data-x="concept-document-navigation-id">navigation id</span>. Otherwise let
88347+
<var>navigationId</var> be the result of <span>generating a random UUID</span>.
88348+
<ref spec=UUID></p></li>
88349+
</ol>
88350+
</li>
88351+
8830988352
<li><p>If <var>newDocument</var> is different than the <span>current entry</span>'s <span
8831088353
data-x="she-document">document</span>, or <var>historyHandling</var> is "<code
8831188354
data-x="hh-entry-update">entry update</code>" or "<code data-x="hh-reload">reload</code>",
@@ -88395,6 +88438,14 @@ new PaymentRequest(&hellip;); // Allowed to use
8839588438
<li><p><span>Fire a page transition event</span> named <code
8839688439
data-x="event-pageshow">pageshow</code> at <var>newDocument</var>'s <span>relevant global
8839788440
object</span> with true.</p></li>
88441+
88442+
<li><p>Invoke <span>WebDriver BiDi page show</span> with <var>newDocument</var>'s
88443+
<span data-x="concept-document-bc">browsing context</span>, and a new <span>WebDriver BiDi
88444+
navigation status</span> whose <span data-x="navigation-status-id">id</span> is the
88445+
<var>navigationId</var>, <span data-x="navigation-status-status">status</span> is
88446+
"<code data-x="navigation-status-complete">complete</code>", and <span
88447+
data-x="navigation-status-url">url</span> is the <var>newDocument</var>'s <span
88448+
data-x="concept-document-url">URL</span>.</p></li>
8839888449
</ol>
8839988450

8840088451
<!-- an interesting thing to test would be to traverse back during onload, before the first
@@ -88467,19 +88518,44 @@ new PaymentRequest(&hellip;); // Allowed to use
8846788518
object</span> to run the following steps instead.</p>
8846888519

8846988520
<ol>
88470-
<li><p>If <var>stateChanged</var> is true, then <span data-x="concept-event-fire">fire an
88471-
event</span> named <code data-x="event-popstate">popstate</code> at <var>newDocument</var>'s
88472-
<span>relevant global object</span>, using <code>PopStateEvent</code>, with the <code
88473-
data-x="dom-PopStateEvent-state">state</code> attribute initialized to <var>state</var>.</p></li>
88521+
<li><p>If <var>stateChanged</var> is true:</p>
88522+
<ol>
88523+
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
88524+
data-x="event-popstate">popstate</code> at <var>newDocument</var>'s
88525+
<span>relevant global object</span>, using <code>PopStateEvent</code>, with the <code
88526+
data-x="dom-PopStateEvent-state">state</code> attribute initialized to <var>state</var>.
88527+
</p></li>
88528+
88529+
<li><p>Invoke <span>WebDriver BiDi pop state</span> with with <var>newDocument</var>'s
88530+
<span data-x="concept-document-bc">browsing context</span>, and a new <span>WebDriver
88531+
BiDi navigation status</span> whose <span data-x="navigation-status-id">id</span> is
88532+
<var>navigationId</var>, <span data-x="navigation-status-url">url</span> is
88533+
<var>resource</var>'s <span data-x="concept-request-url">url</span>, and <span
88534+
data-x="navigation-status-status">status</span> is "<code
88535+
data-x="navigation-status-complete">complete</code>".</p></li>
88536+
</ol>
88537+
</li>
8847488538

8847588539
<li><p><span>Restore persisted state</span> from <var>entry</var>.</p></li>
8847688540

88477-
<li><p>If <var>hashChanged</var> is true, then <span data-x="concept-event-fire">fire an
88478-
event</span> named <code data-x="event-hashchange">hashchange</code> at the <span>browsing
88479-
context</span>'s <span>active window</span>, using <code>HashChangeEvent</code>, with the <code
88480-
data-x="dom-HashChangeEvent-oldURL">oldURL</code> attribute initialized to <var>oldURL</var>
88481-
and the <code data-x="dom-HashChangeEvent-newURL">newURL</code> attribute initialized to
88482-
<var>newURL</var>.</p></li>
88541+
<li><p>If <var>hashChanged</var> is true:</p>
88542+
<ol>
88543+
<li><p><span data-x="concept-event-fire">Fire an event</span> named
88544+
<code data-x="event-hashchange">hashchange</code> at the <span>browsing context</span>'s
88545+
<span>active window</span>, using <code>HashChangeEvent</code>, with the <code
88546+
data-x="dom-HashChangeEvent-oldURL">oldURL</code> attribute initialized to <var>oldURL</var>
88547+
and the <code data-x="dom-HashChangeEvent-newURL">newURL</code> attribute initialized to
88548+
<var>newURL</var>.</p></li>
88549+
88550+
<li><p>Invoke <span>WebDriver BiDi fragment navigated</span> with <var>newDocument</var>'s
88551+
<span data-x="concept-document-bc">browsing context</span>, and a new <span>WebDriver
88552+
BiDi navigation status</span> whose <span data-x="navigation-status-id">id</span> is
88553+
<var>navigationId</var>, <span data-x="navigation-status-url">url</span> is
88554+
<var>resource</var>'s <span data-x="concept-request-url">url</span>, and <span
88555+
data-x="navigation-status-status">status</span> is "<code
88556+
data-x="navigation-status-complete">complete</code>".</p></li>
88557+
</ol>
88558+
</li>
8848388559
</ol>
8848488560
</li>
8848588561
</ol>

0 commit comments

Comments
 (0)