Skip to content

Commit 1fa8df3

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 92a152c commit 1fa8df3

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
@@ -4143,6 +4143,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
41434143
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-fragment-navigated">WebDriver BiDi fragment navigated</dfn></li>
41444144
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-dom-content-loaded">WebDriver BiDi DOM content loaded</dfn></li>
41454145
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-load-complete">WebDriver BiDi load complete</dfn></li>
4146+
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-page-show">WebDriver BiDi page show</dfn></li>
4147+
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-pop-state">WebDriver BiDi pop state</dfn></li>
41464148
</ul>
41474149
</dd>
41484150

@@ -84893,16 +84895,23 @@ interface <dfn interface>History</dfn> {
8489384895

8489484896
<hr>
8489584897

84896-
<p>To <dfn>traverse the history by a delta</dfn> given <var>delta</var> and <span>browsing
84897-
context</span> <var>source browsing context</var>, the user agent must append a <span
84898-
data-x="concept-task">task</span> to this <span>top-level browsing context</span>'s <span>session
84899-
history traversal queue</span>, the <span data-x="concept-task">task</span> consisting of running
84900-
the following steps:</p>
84898+
<p>To <dfn>traverse the history by a delta</dfn> given <var>delta</var>, <span>browsing
84899+
context</span> <var>source browsing context</var>, and an optional <span
84900+
data-x="navigation-id">navigation id</span> <var>navigationId</var> (default null),
84901+
the user agent must append a <span data-x="concept-task">task</span> to this <span>top-level
84902+
browsing context</span>'s <span>session history traversal queue</span>, the <span
84903+
data-x="concept-task">task</span> consisting of running the following steps:</p>
8490184904

8490284905
<ol>
8490384906
<li><p>If the index of the <span>current entry of the joint session history</span> plus
8490484907
<var>delta</var> is less than zero or greater than or equal to the number of items in the
84905-
<span>joint session history</span>, then return.</p>
84908+
<span>joint session history</span>, invoke <span>WebDriver BiDi navigation failed</span>
84909+
with <var>source browsing context</var>, and a <span>WebDriver BiDi navigation status</span> whose <span
84910+
data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
84911+
data-x="navigation-status-status">status</span> is "<code
84912+
data-x="navigation-status-canceled">canceled</code>", and <span
84913+
data-x="navigation-status-url">url</span> is <var>resource</var>'s <span
84914+
data-x="concept-request-url">url</span>, then return.</p></li>
8490684915

8490784916
<li><p>Let <var>specified entry</var> be the entry in the <span>joint session
8490884917
history</span> whose index is the sum of <var>delta</var> and the index of the
@@ -84912,17 +84921,32 @@ interface <dfn interface>History</dfn> {
8491284921
the <var>specified entry</var>.</p></li>
8491384922

8491484923
<li><p>If <var>source browsing context</var> is not <span>allowed to navigate</span>
84915-
<var>specified browsing context</var>, then return.</p></li>
84924+
<var>specified browsing context</var>, then invoke <span>WebDriver BiDi navigation failed</span> with
84925+
with <var>source browsing context</var>, and a <span>WebDriver BiDi navigation status</span> whose <span
84926+
data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
84927+
data-x="navigation-status-status">status</span> is "<code
84928+
data-x="navigation-status-canceled">canceled</code>", and <span
84929+
data-x="navigation-status-url">url</span> is <var>resource</var>'s <span
84930+
data-x="concept-request-url">url</span>, then return.</p></li>
8491684931

8491784932
<li><p>If the <var>specified browsing context</var>'s <span>active document</span>'s <span>unload
84918-
counter</span> is greater than 0, then return.</p></li>
84933+
counter</span> is greater than 0, then invoke <span>WebDriver BiDi navigation failed</span> with
84934+
with <var>source browsing context</var>, and a <span>WebDriver BiDi navigation status</span> whose <span
84935+
data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
84936+
data-x="navigation-status-status">status</span> is "<code
84937+
data-x="navigation-status-canceled">canceled</code>", and <span
84938+
data-x="navigation-status-url">url</span> is <var>resource</var>'s <span
84939+
data-x="concept-request-url">url</span>, then return.</p></li>
8491984940

8492084941
<li>
8492184942
<p><span>Queue a global task</span> on the <span>history traversal task source</span> given
8492284943
<var>specified browsing context</var>'s <span>active window</span> to perform the following
8492384944
steps:</p>
8492484945

8492584946
<ol>
84947+
<li><p>If <var>navigationId</var> is null, let <var>navigation id</var> be the result of
84948+
<span>generating a random UUID</span>. <ref spec=UUID></p></li>
84949+
8492684950
<li><p>If there is an ongoing attempt to navigate <var>specified browsing context</var>
8492784951
that has not yet <span data-x="concept-navigate-mature">matured</span> (i.e. it has not passed the
8492884952
point of making its <code>Document</code> the <span>active document</span>), then cancel that
@@ -84936,7 +84960,13 @@ interface <dfn interface>History</dfn> {
8493684960
<ol>
8493784961
<li><p><span>Prompt to unload</span> the <span>active document</span> of the <var>specified
8493884962
browsing context</var>. If the user <span>refused to allow the document to be
84939-
unloaded</span>, then return.</p></li>
84963+
unloaded</span>, then invoke <span>WebDriver BiDi navigation failed</span> with
84964+
with <var>source browsing context</var>, and a <span>WebDriver BiDi navigation status</span>
84965+
whose <span data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
84966+
data-x="navigation-status-status">status</span> is "<code
84967+
data-x="navigation-status-canceled">canceled</code>", and <span
84968+
data-x="navigation-status-url">url</span> is <var>resource</var>'s <span
84969+
data-x="concept-request-url">url</span>, then return.</p></li>
8494084970

8494184971
<li><p><span data-x="unload a document">Unload</span> the <span>active document</span> of the
8494284972
<var>specified browsing context</var>.</p></li>
@@ -84945,7 +84975,8 @@ interface <dfn interface>History</dfn> {
8494584975

8494684976
<li><p><span>Traverse the history</span> of the <var>specified browsing context</var> to
8494784977
the <var>specified entry</var> with <var><span>explicitHistoryNavigation</span></var> set to
84948-
true.</p>
84978+
true, and <span data-x="traverse-history-navigationid">navigation id</span> set to
84979+
<var>navigationId</var>.</p>
8494984980
</ol>
8495084981
</li>
8495184982
</ol>
@@ -86524,8 +86555,6 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
8652486555
context</span>'s <span>active window</span> has <span>transient activation</span>; otherwise
8652586556
false.</p></li>
8652686557

86527-
<li><p>Let <var>navigationStatus</var> be </li>
86528-
8652986558
<li><p>Invoke <span>WebDriver BiDi navigation started</span> with <var>browsingContext</var>, and
8653086559
a new <span>WebDriver BiDi navigation status</span> whose <span
8653186560
data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
@@ -87642,7 +87671,8 @@ new PaymentRequest(&hellip;); // Allowed to use
8764287671
<li><p><span>Traverse the history</span> to <var>sessionHistory</var>'s <span>current
8764387672
entry</span> with <var data-x="traverse-history-hh">historyHandling</var> set to
8764487673
<var>navigationParams</var>'s <span data-x="navigation-params-hh">history
87645-
handling</span>.</p></li>
87674+
handling</span>, and <span data-x="traverse-history-navigationid">navigation id</span>
87675+
set to <var>navigationId</var>.</p></li>
8764687676
</ol>
8764787677
</dd>
8764887678

@@ -87672,7 +87702,9 @@ new PaymentRequest(&hellip;); // Allowed to use
8767287702

8767387703
<li><p><span>Traverse the history</span> to <var>newEntry</var> with
8767487704
<var data-x="traverse-history-hh">historyHandling</var> set to "<code
87675-
data-x="hh-replace">replace</code>".</p></li>
87705+
data-x="hh-replace">replace</code>", and <span
87706+
data-x="traverse-history-navigationid">navigation id</span> set to <var>navigationId</var>.
87707+
</p></li>
8767687708
</ol>
8767787709
</dd>
8767887710

@@ -87701,7 +87733,9 @@ new PaymentRequest(&hellip;); // Allowed to use
8770187733
<li><p><span data-x="list append">Append</span> <var>newEntry</var> to
8770287734
<var>sessionHistory</var>.</p></li>
8770387735

87704-
<li><p><span>Traverse the history</span> to <var>newEntry</var>.</p></li>
87736+
<li><p><span>Traverse the history</span> to <var>newEntry</var> with <span
87737+
data-x="traverse-history-navigationid">navigation id</span> set to <var>navigationId</var>.
87738+
</p></li>
8770587739
</ol>
8770687740
</dd>
8770787741
</dl>
@@ -88094,18 +88128,11 @@ new PaymentRequest(&hellip;); // Allowed to use
8809488128
mode</span>.</p></li>
8809588129

8809688130
<li><p><span>Traverse the history</span> to the new entry, with <var
88097-
data-x="traverse-history-hh">historyHandling</var> set to <var>historyHandling</var> and with
88098-
<var><span>nonBlockingEvents</span></var> set to true. This will <span>scroll to the
88099-
fragment</span> given in what is now the document's <span
88131+
data-x="traverse-history-hh">historyHandling</var> set to <var>historyHandling</var>,
88132+
<var><span>nonBlockingEvents</span></var> set to true, and <span
88133+
data-x="traverse-history-navigationid">navigation id</span> set to <var>navigationId</var>.
88134+
This will <span>scroll to the fragment</span> given in what is now the document's <span
8810088135
data-x="concept-document-url">URL</span>.</p></li>
88101-
88102-
<li><p><p>Invoke <span>WebDriver BiDi fragment navigated</span> with <var>browsingContext</var>,
88103-
and a new <span>WebDriver BiDi navigation status</span> whose <span
88104-
data-x="navigation-status-id">id</span> is <var>navigationId</var>, <span
88105-
data-x="navigation-status-url">url</span> is <var>resource</var>'s <span
88106-
data-x="concept-request-url">url</span>, and <span
88107-
data-x="navigation-status-status">status</span> is "<code
88108-
data-x="navigation-status-complete">complete</code>".</p></li>
8810988136
</ol>
8811088137

8811188138
<p class="note">If the scrolling fails because the relevant <span data-x="concept-id">ID</span> has
@@ -88236,8 +88263,9 @@ new PaymentRequest(&hellip;); // Allowed to use
8823688263
with an optional <span>history handling behavior</span> <dfn
8823788264
data-x="traverse-history-hh"><var>historyHandling</var></dfn> (default "<code
8823888265
data-x="hh-default">default</code>"), an optional boolean <dfn><var>nonBlockingEvents</var></dfn>
88239-
(default false), and an optional boolean <dfn><var>explicitHistoryNavigation</var></dfn> (default
88240-
false):</p>
88266+
(default false), an optional boolean <dfn><var>explicitHistoryNavigation</var></dfn> (default
88267+
false), optional <span data-x="navigation-id">navigation id</span>
88268+
<dfn data-x="traverse-history-navigationid"><var>navigationId</var></dfn> (default null):</p>
8824188269

8824288270
<p class="note">This algorithm is not just invoked when <span data-x="traverse the history by a
8824388271
delta">explicitly going back or forwards in the session history</span> &mdash; it is also invoked
@@ -88263,11 +88291,12 @@ new PaymentRequest(&hellip;); // Allowed to use
8826388291
<li>
8826488292
<p><span>Navigate</span><!--DONAV history traversal after eviction--> the <span>browsing
8826588293
context</span> to <var>request</var> with <var data-x="navigation-hh">historyHandling</var>
88266-
set to "<code data-x="hh-entry-update">entry update</code>" and with <var
88294+
set to "<code data-x="hh-entry-update">entry update</code>", with <var
8826788295
data-x="navigation-historypolicycontainer">historyPolicyContainer</var> set to
88268-
<var>entry</var>'s <span data-x="she-policy-container">policy container</span>. The navigation
88269-
must be done using the same <span>source browsing context</span> as was used the first time
88270-
<var>entry</var> was created.</p>
88296+
<var>entry</var>'s <span data-x="she-policy-container">policy container</span>, and with
88297+
<span data-x="navigation-navigationid">navigation id</span> set to <var>navigationId</var>.
88298+
The navigation must be done using the same <span>source browsing context</span> as was
88299+
used the first time <var>entry</var> was created.</p>
8827188300

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

88321+
<li><p>If <var>navigationId</var> is null:</p>
88322+
<!-- In practice I think the only case that we use the navigation id in subsequent steps is
88323+
when we have a page loaded from the bfcache, in which case document's navigation id is always null.
88324+
We could just use null as the navigation id in that case, but it would mean a difference between
88325+
a WebDriver-initiated history traversal from the bfcache and a UA initated history traversal. -->
88326+
<ol>
88327+
<li><p>If <var>newDocument</var>'s <span data-x="concept-document-navigation-id">navigation
88328+
id</span> is not null, let <var>navigationId</var> be <var>newDocument</var>'s <span
88329+
data-x="concept-document-navigation-id">navigation id</span>. Otherwise let
88330+
<var>navigationId</var> be the result of <span>generating a random UUID</span>.
88331+
<ref spec=UUID></p></li>
88332+
</ol>
88333+
</li>
88334+
8829288335
<li><p>If <var>newDocument</var> is different than the <span>current entry</span>'s <span
8829388336
data-x="she-document">document</span>, or <var>historyHandling</var> is "<code
8829488337
data-x="hh-entry-update">entry update</code>" or "<code data-x="hh-reload">reload</code>",
@@ -88378,6 +88421,14 @@ new PaymentRequest(&hellip;); // Allowed to use
8837888421
<li><p><span>Fire a page transition event</span> named <code
8837988422
data-x="event-pageshow">pageshow</code> at <var>newDocument</var>'s <span>relevant global
8838088423
object</span> with true.</p></li>
88424+
88425+
<li><p>Invoke <span>WebDriver BiDi page show</span> with <var>newDocument</var>'s
88426+
<span data-x="concept-document-bc">browsing context</span>, and a new <span>WebDriver BiDi
88427+
navigation status</span> whose <span data-x="navigation-status-id">id</span> is the
88428+
<var>navigationId</var>, <span data-x="navigation-status-status">status</span> is
88429+
"<code data-x="navigation-status-complete">complete</code>", and <span
88430+
data-x="navigation-status-url">url</span> is the <var>newDocument</var>'s <span
88431+
data-x="concept-document-url">URL</span>.</p></li>
8838188432
</ol>
8838288433

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

8845288503
<ol>
88453-
<li><p>If <var>stateChanged</var> is true, then <span data-x="concept-event-fire">fire an
88454-
event</span> named <code data-x="event-popstate">popstate</code> at <var>newDocument</var>'s
88455-
<span>relevant global object</span>, using <code>PopStateEvent</code>, with the <code
88456-
data-x="dom-PopStateEvent-state">state</code> attribute initialized to <var>state</var>.</p></li>
88504+
<li><p>If <var>stateChanged</var> is true:</p>
88505+
<ol>
88506+
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
88507+
data-x="event-popstate">popstate</code> at <var>newDocument</var>'s
88508+
<span>relevant global object</span>, using <code>PopStateEvent</code>, with the <code
88509+
data-x="dom-PopStateEvent-state">state</code> attribute initialized to <var>state</var>.
88510+
</p></li>
88511+
88512+
<li><p>Invoke <span>WebDriver BiDi pop state</span> with with <var>newDocument</var>'s
88513+
<span data-x="concept-document-bc">browsing context</span>, and a new <span>WebDriver
88514+
BiDi navigation status</span> whose <span data-x="navigation-status-id">id</span> is
88515+
<var>navigationId</var>, <span data-x="navigation-status-url">url</span> is
88516+
<var>resource</var>'s <span data-x="concept-request-url">url</span>, and <span
88517+
data-x="navigation-status-status">status</span> is "<code
88518+
data-x="navigation-status-complete">complete</code>".</p></li>
88519+
</ol>
88520+
</li>
8845788521

8845888522
<li><p><span>Restore persisted state</span> from <var>entry</var>.</p></li>
8845988523

88460-
<li><p>If <var>hashChanged</var> is true, then <span data-x="concept-event-fire">fire an
88461-
event</span> named <code data-x="event-hashchange">hashchange</code> at the <span>browsing
88462-
context</span>'s <span>active window</span>, using <code>HashChangeEvent</code>, with the <code
88463-
data-x="dom-HashChangeEvent-oldURL">oldURL</code> attribute initialized to <var>oldURL</var>
88464-
and the <code data-x="dom-HashChangeEvent-newURL">newURL</code> attribute initialized to
88465-
<var>newURL</var>.</p></li>
88524+
<li><p>If <var>hashChanged</var> is true:</p>
88525+
<ol>
88526+
<li><p><span data-x="concept-event-fire">Fire an event</span> named
88527+
<code data-x="event-hashchange">hashchange</code> at the <span>browsing context</span>'s
88528+
<span>active window</span>, using <code>HashChangeEvent</code>, with the <code
88529+
data-x="dom-HashChangeEvent-oldURL">oldURL</code> attribute initialized to <var>oldURL</var>
88530+
and the <code data-x="dom-HashChangeEvent-newURL">newURL</code> attribute initialized to
88531+
<var>newURL</var>.</p></li>
88532+
88533+
<li><p>Invoke <span>WebDriver BiDi fragment navigated</span> with <var>newDocument</var>'s
88534+
<span data-x="concept-document-bc">browsing context</span>, and a new <span>WebDriver
88535+
BiDi navigation status</span> whose <span data-x="navigation-status-id">id</span> is
88536+
<var>navigationId</var>, <span data-x="navigation-status-url">url</span> is
88537+
<var>resource</var>'s <span data-x="concept-request-url">url</span>, and <span
88538+
data-x="navigation-status-status">status</span> is "<code
88539+
data-x="navigation-status-complete">complete</code>".</p></li>
88540+
</ol>
88541+
</li>
8846688542
</ol>
8846788543
</li>
8846888544
</ol>

0 commit comments

Comments
 (0)