Skip to content

Commit 5f17205

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 1b5099f commit 5f17205

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
@@ -4132,6 +4132,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
41324132
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-fragment-navigated">WebDriver BiDi fragment navigated</dfn></li>
41334133
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-dom-content-loaded">WebDriver BiDi DOM content loaded</dfn></li>
41344134
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-load-complete">WebDriver BiDi load complete</dfn></li>
4135+
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-page-show">WebDriver BiDi page show</dfn></li>
4136+
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-pop-state">WebDriver BiDi pop state</dfn></li>
41354137
</ul>
41364138
</dd>
41374139

@@ -84700,16 +84702,23 @@ interface <dfn interface>History</dfn> {
8470084702

8470184703
<hr>
8470284704

84703-
<p>To <dfn>traverse the history by a delta</dfn> given <var>delta</var> and <span>browsing
84704-
context</span> <var>source browsing context</var>, the user agent must append a <span
84705-
data-x="concept-task">task</span> to this <span>top-level browsing context</span>'s <span>session
84706-
history traversal queue</span>, the <span data-x="concept-task">task</span> consisting of running
84707-
the following steps:</p>
84705+
<p>To <dfn>traverse the history by a delta</dfn> given <var>delta</var>, <span>browsing
84706+
context</span> <var>source browsing context</var>, and an optional <span
84707+
data-x="navigation-id">navigation id</span> <var>navigationId</var> (default null),
84708+
the user agent must append a <span data-x="concept-task">task</span> to this <span>top-level
84709+
browsing context</span>'s <span>session history traversal queue</span>, the <span
84710+
data-x="concept-task">task</span> consisting of running the following steps:</p>
8470884711

8470984712
<ol>
8471084713
<li><p>If the index of the <span>current entry of the joint session history</span> plus
8471184714
<var>delta</var> is less than zero or greater than or equal to the number of items in the
84712-
<span>joint session history</span>, then return.</p>
84715+
<span>joint session history</span>, invoke <span>WebDriver BiDi navigation failed</span>
84716+
with <var>source browsing context</var>, and a <span>WebDriver BiDi navigation status</span> whose <span
84717+
data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
84718+
data-x="navigation-status-status">status</span> is "<code
84719+
data-x="navigation-status-canceled">canceled</code>", and <span
84720+
data-x="navigation-status-url">url</span> is <var>resource</var>'s <span
84721+
data-x="concept-request-url">url</span>, then return.</p></li>
8471384722

8471484723
<li><p>Let <var>specified entry</var> be the entry in the <span>joint session
8471584724
history</span> whose index is the sum of <var>delta</var> and the index of the
@@ -84719,17 +84728,32 @@ interface <dfn interface>History</dfn> {
8471984728
the <var>specified entry</var>.</p></li>
8472084729

8472184730
<li><p>If <var>source browsing context</var> is not <span>allowed to navigate</span>
84722-
<var>specified browsing context</var>, then return.</p></li>
84731+
<var>specified browsing context</var>, then invoke <span>WebDriver BiDi navigation failed</span> with
84732+
with <var>source browsing context</var>, and a <span>WebDriver BiDi navigation status</span> whose <span
84733+
data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
84734+
data-x="navigation-status-status">status</span> is "<code
84735+
data-x="navigation-status-canceled">canceled</code>", and <span
84736+
data-x="navigation-status-url">url</span> is <var>resource</var>'s <span
84737+
data-x="concept-request-url">url</span>, then return.</p></li>
8472384738

8472484739
<li><p>If the <var>specified browsing context</var>'s <span>active document</span>'s <span>unload
84725-
counter</span> is greater than 0, then return.</p></li>
84740+
counter</span> is greater than 0, then invoke <span>WebDriver BiDi navigation failed</span> with
84741+
with <var>source browsing context</var>, and a <span>WebDriver BiDi navigation status</span> whose <span
84742+
data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
84743+
data-x="navigation-status-status">status</span> is "<code
84744+
data-x="navigation-status-canceled">canceled</code>", and <span
84745+
data-x="navigation-status-url">url</span> is <var>resource</var>'s <span
84746+
data-x="concept-request-url">url</span>, then return.</p></li>
8472684747

8472784748
<li>
8472884749
<p><span>Queue a global task</span> on the <span>history traversal task source</span> given
8472984750
<var>specified browsing context</var>'s <span>active window</span> to perform the following
8473084751
steps:</p>
8473184752

8473284753
<ol>
84754+
<li><p>If <var>navigationId</var> is null, let <var>navigation id</var> be the result of
84755+
<span>generating a random UUID</span>. <ref spec=UUID></p></li>
84756+
8473384757
<li><p>If there is an ongoing attempt to navigate <var>specified browsing context</var>
8473484758
that has not yet <span data-x="concept-navigate-mature">matured</span> (i.e. it has not passed the
8473584759
point of making its <code>Document</code> the <span>active document</span>), then cancel that
@@ -84743,7 +84767,13 @@ interface <dfn interface>History</dfn> {
8474384767
<ol>
8474484768
<li><p><span>Prompt to unload</span> the <span>active document</span> of the <var>specified
8474584769
browsing context</var>. If the user <span>refused to allow the document to be
84746-
unloaded</span>, then return.</p></li>
84770+
unloaded</span>, , then invoke <span>WebDriver BiDi navigation failed</span> with
84771+
with <var>source browsing context</var>, and a <span>WebDriver BiDi navigation status</span>
84772+
whose <span data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
84773+
data-x="navigation-status-status">status</span> is "<code
84774+
data-x="navigation-status-canceled">canceled</code>", and <span
84775+
data-x="navigation-status-url">url</span> is <var>resource</var>'s <span
84776+
data-x="concept-request-url">url</span>, then return.</p></li>
8474784777

8474884778
<li><p><span data-x="unload a document">Unload</span> the <span>active document</span> of the
8474984779
<var>specified browsing context</var>.</p></li>
@@ -84752,7 +84782,8 @@ interface <dfn interface>History</dfn> {
8475284782

8475384783
<li><p><span>Traverse the history</span> of the <var>specified browsing context</var> to
8475484784
the <var>specified entry</var> with <var><span>explicitHistoryNavigation</span></var> set to
84755-
true.</p>
84785+
true, and <span data-x="traverse-history-navigationid">navigation id</span> set to
84786+
<var>navigationId</var>.</p>
8475684787
</ol>
8475784788
</li>
8475884789
</ol>
@@ -86246,8 +86277,6 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
8624686277
context</span>'s <span>active window</span> has <span>transient activation</span>; otherwise
8624786278
false.</p></li>
8624886279

86249-
<li><p>Let <var>navigationStatus</var> be </li>
86250-
8625186280
<li><p>Invoke <span>WebDriver BiDi navigation started</span> with <var>browsingContext</var>, and
8625286281
a new <span>WebDriver BiDi navigation status</span> whose <span
8625386282
data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
@@ -87363,7 +87392,8 @@ new PaymentRequest(&hellip;); // Allowed to use
8736387392
<li><p><span>Traverse the history</span> to <var>sessionHistory</var>'s <span>current
8736487393
entry</span> with <var data-x="traverse-history-hh">historyHandling</var> set to
8736587394
<var>navigationParams</var>'s <span data-x="navigation-params-hh">history
87366-
handling</span>.</p></li>
87395+
handling</span>, and <span data-x="traverse-history-navigationid">navigation id</span>
87396+
set to <var>navigationId</var>.</p></li>
8736787397
</ol>
8736887398
</dd>
8736987399

@@ -87393,7 +87423,9 @@ new PaymentRequest(&hellip;); // Allowed to use
8739387423

8739487424
<li><p><span>Traverse the history</span> to <var>newEntry</var> with
8739587425
<var data-x="traverse-history-hh">historyHandling</var> set to "<code
87396-
data-x="hh-replace">replace</code>".</p></li>
87426+
data-x="hh-replace">replace</code>", and <span
87427+
data-x="traverse-history-navigationid">navigation id</span> set to <var>navigationId</var>.
87428+
</p></li>
8739787429
</ol>
8739887430
</dd>
8739987431

@@ -87422,7 +87454,9 @@ new PaymentRequest(&hellip;); // Allowed to use
8742287454
<li><p><span data-x="list append">Append</span> <var>newEntry</var> to
8742387455
<var>sessionHistory</var>.</p></li>
8742487456

87425-
<li><p><span>Traverse the history</span> to <var>newEntry</var>.</p></li>
87457+
<li><p><span>Traverse the history</span> to <var>newEntry</var> with <span
87458+
data-x="traverse-history-navigationid">navigation id</span> set to <var>navigationId</var>.
87459+
</p></li>
8742687460
</ol>
8742787461
</dd>
8742887462
</dl>
@@ -87816,18 +87850,11 @@ new PaymentRequest(&hellip;); // Allowed to use
8781687850
mode</span>.</p></li>
8781787851

8781887852
<li><p><span>Traverse the history</span> to the new entry, with <var
87819-
data-x="traverse-history-hh">historyHandling</var> set to <var>historyHandling</var> and with
87820-
<var><span>nonBlockingEvents</span></var> set to true. This will <span>scroll to the
87821-
fragment</span> given in what is now the document's <span
87853+
data-x="traverse-history-hh">historyHandling</var> set to <var>historyHandling</var>,
87854+
<var><span>nonBlockingEvents</span></var> set to true, and <span
87855+
data-x="traverse-history-navigationid">navigation id</span> set to <var>navigationId</var>.
87856+
This will <span>scroll to the fragment</span> given in what is now the document's <span
8782287857
data-x="concept-document-url">URL</span>.</p></li>
87823-
87824-
<li><p><p>Invoke <span>WebDriver BiDi fragment navigated</span> with <var>browsingContext</var>,
87825-
and a new <span>WebDriver BiDi navigation status</span> whose <span
87826-
data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
87827-
data-x="navigation-status-url">url</span> is <var>resource</var>'s <span
87828-
data-x="concept-request-url">url</span>, and <span
87829-
data-x="navigation-status-status">status</span> is "<code
87830-
data-x="navigation-status-complete">complete</code>".</p></li>
8783187858
</ol>
8783287859

8783387860
<p class="note">If the scrolling fails because the relevant <span data-x="concept-id">ID</span> has
@@ -87956,8 +87983,9 @@ new PaymentRequest(&hellip;); // Allowed to use
8795687983
with an optional <span>history handling behavior</span> <dfn
8795787984
data-x="traverse-history-hh"><var>historyHandling</var></dfn> (default "<code
8795887985
data-x="hh-default">default</code>"), an optional boolean <dfn><var>nonBlockingEvents</var></dfn>
87959-
(default false), and an optional boolean <dfn><var>explicitHistoryNavigation</var></dfn> (default
87960-
false):</p>
87986+
(default false), an optional boolean <dfn><var>explicitHistoryNavigation</var></dfn> (default
87987+
false), optional <span data-x="navigation-id">navigation id</span>
87988+
<dfn data-x="traverse-history-navigationid"><var>navigationId</var></dfn> (default null):</p>
8796187989

8796287990
<p class="note">This algorithm is not just invoked when <span data-x="traverse the history by a
8796387991
delta">explicitly going back or forwards in the session history</span> &mdash; it is also invoked
@@ -87983,11 +88011,12 @@ new PaymentRequest(&hellip;); // Allowed to use
8798388011
<li>
8798488012
<p><span>Navigate</span><!--DONAV history traversal after eviction--> the <span>browsing
8798588013
context</span> to <var>request</var> with <var data-x="navigation-hh">historyHandling</var>
87986-
set to "<code data-x="hh-entry-update">entry update</code>" and with <var
88014+
set to "<code data-x="hh-entry-update">entry update</code>", with <var
8798788015
data-x="navigation-historypolicycontainer">historyPolicyContainer</var> set to
87988-
<var>entry</var>'s <span data-x="she-policy-container">policy container</span>. The navigation
87989-
must be done using the same <span>source browsing context</span> as was used the first time
87990-
<var>entry</var> was created.</p>
88016+
<var>entry</var>'s <span data-x="she-policy-container">policy container</span>, and with
88017+
<span data-x="navigation-navigationid">navigation id</span> set to <var>navigationId</var>.
88018+
The navigation must be done using the same <span>source browsing context</span> as was
88019+
used the first time <var>entry</var> was created.</p>
8799188020

8799288021
<p class="note">The "<span>navigate</span>" algorithm reinvokes this "traverse" algorithm to
8799388022
complete the traversal, at which point <var>entry</var>'s <span
@@ -88009,6 +88038,20 @@ new PaymentRequest(&hellip;); // Allowed to use
8800988038
<li><p>Let <var>newDocument</var> be <var>entry</var>'s <span
8801088039
data-x="she-document">document</span>.</p></li>
8801188040

88041+
<li><p>If <var>navigationId</var> is null:</p>
88042+
<!-- In practice I think the only case that we use the navigation id in subsequent steps is
88043+
when we have a page loaded from the bfcache, in which case document's navigation id is always null.
88044+
We could just use null as the navigation id in that case, but it would mean a difference between
88045+
a WebDriver-initiated history traversal from the bfcache and a UA initated history traversal. -->
88046+
<ol>
88047+
<li><p>If <var>newDocument</var>'s <span data-x="concept-document-navigation-id">navigation
88048+
id</span> is not null, let <var>navigationId</var> be <var>newDocument</var>'s <span
88049+
data-x="concept-document-navigation-id">navigation id</span>. Otherwise let
88050+
<var>navigationId</var> be the result of <span>generating a random UUID</span>.
88051+
<ref spec=UUID></p></li>
88052+
</ol>
88053+
</li>
88054+
8801288055
<li><p>If <var>newDocument</var> is different than the <span>current entry</span>'s <span
8801388056
data-x="she-document">document</span>, or <var>historyHandling</var> is "<code
8801488057
data-x="hh-entry-update">entry update</code>" or "<code data-x="hh-reload">reload</code>",
@@ -88098,6 +88141,14 @@ new PaymentRequest(&hellip;); // Allowed to use
8809888141
<li><p><span>Fire a page transition event</span> named <code
8809988142
data-x="event-pageshow">pageshow</code> at <var>newDocument</var>'s <span>relevant global
8810088143
object</span> with true.</p></li>
88144+
88145+
<li><p>Invoke <span>WebDriver BiDi page show</span> with <var>newDocument</var>'s
88146+
<span data-x="concept-document-bc">browsing context</span>, and a new <span>WebDriver BiDi
88147+
navigation status</span> whose <span data-x="navigation-status-id">id</span> is the
88148+
<var>navigationId</var>, <span data-x="navigation-status-status">status</span> is
88149+
"<code data-x="navigation-status-complete">complete</code>", and <span
88150+
data-x="navigation-status-url">url</span> is the <var>newDocument</var>'s <span
88151+
data-x="concept-document-url">URL</span>.</p></li>
8810188152
</ol>
8810288153

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

8817288223
<ol>
88173-
<li><p>If <var>stateChanged</var> is true, then <span data-x="concept-event-fire">fire an
88174-
event</span> named <code data-x="event-popstate">popstate</code> at <var>newDocument</var>'s
88175-
<span>relevant global object</span>, using <code>PopStateEvent</code>, with the <code
88176-
data-x="dom-PopStateEvent-state">state</code> attribute initialized to <var>state</var>.</p></li>
88224+
<li><p>If <var>stateChanged</var> is true:</p>
88225+
<ol>
88226+
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
88227+
data-x="event-popstate">popstate</code> at <var>newDocument</var>'s
88228+
<span>relevant global object</span>, using <code>PopStateEvent</code>, with the <code
88229+
data-x="dom-PopStateEvent-state">state</code> attribute initialized to <var>state</var>.
88230+
</p></li>
88231+
88232+
<li><p>Invoke <span>WebDriver BiDi pop state</span> with with <var>newDocument</var>'s
88233+
<span data-x="concept-document-bc">browsing context</span>, and a new <span>WebDriver
88234+
BiDi navigation status</span> whose <span data-x="navigation-status-id">id</span> is
88235+
<var>navigationId</var>, <span data-x="navigation-status-url">url</span> is
88236+
<var>resource</var>'s <span data-x="concept-request-url">url</span>, and <span
88237+
data-x="navigation-status-status">status</span> is "<code
88238+
data-x="navigation-status-complete">complete</code>".</p></li>
88239+
</ol>
88240+
</li>
8817788241

8817888242
<li><p><span>Restore persisted state</span> from <var>entry</var>.</p></li>
8817988243

88180-
<li><p>If <var>hashChanged</var> is true, then <span data-x="concept-event-fire">fire an
88181-
event</span> named <code data-x="event-hashchange">hashchange</code> at the <span>browsing
88182-
context</span>'s <span>active window</span>, using <code>HashChangeEvent</code>, with the <code
88183-
data-x="dom-HashChangeEvent-oldURL">oldURL</code> attribute initialized to <var>oldURL</var>
88184-
and the <code data-x="dom-HashChangeEvent-newURL">newURL</code> attribute initialized to
88185-
<var>newURL</var>.</p></li>
88244+
<li><p>If <var>hashChanged</var> is true:</p>
88245+
<ol>
88246+
<li><p><span data-x="concept-event-fire">Fire an event</span> named
88247+
<code data-x="event-hashchange">hashchange</code> at the <span>browsing context</span>'s
88248+
<span>active window</span>, using <code>HashChangeEvent</code>, with the <code
88249+
data-x="dom-HashChangeEvent-oldURL">oldURL</code> attribute initialized to <var>oldURL</var>
88250+
and the <code data-x="dom-HashChangeEvent-newURL">newURL</code> attribute initialized to
88251+
<var>newURL</var>.</p></li>
88252+
88253+
<li><p>Invoke <span>WebDriver BiDi fragment navigated</span> with <var>newDocument</var>'s
88254+
<span data-x="concept-document-bc">browsing context</span>, and a new <span>WebDriver
88255+
BiDi navigation status</span> whose <span data-x="navigation-status-id">id</span> is
88256+
<var>navigationId</var>, <span data-x="navigation-status-url">url</span> is
88257+
<var>resource</var>'s <span data-x="concept-request-url">url</span>, and <span
88258+
data-x="navigation-status-status">status</span> is "<code
88259+
data-x="navigation-status-complete">complete</code>".</p></li>
88260+
</ol>
88261+
</li>
8818688262
</ol>
8818788263
</li>
8818888264
</ol>

0 commit comments

Comments
 (0)