Skip to content

Commit 297039e

Browse files
committed
Add a browsingContext.traverseHistory command
This traverses the history by a specified `delta` (e.g. +1 for forward, or -1 for back). Like other navigation commands the `wait` parameter controls whether to return as soon as the history traversal starts, or wait for a specified level of completeness. Mush like other navigation commands, history traversal is tracked with a unique navigation id. Typically history traversal results in a navigation, but in the case of the history entry being in the bfcache, no navigation is necessary. In this case any non-"none" value for wait will return once the `pageshow` event is fired, and the `persisted` attribute of the return value is set to `true`. This model differs somewhat from the CDP model where one navigates to an explicit history entry and failure is only possible if the entry id is invalid. But back/forwward only seems closer to the use cases we have, and allowing events to be traced to a specific traversal seems consistent with the way we handle other navigation-related events.
1 parent 5812fae commit 297039e

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

index.bs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,116 @@ The [=remote end steps=] with |command parameters| are:
19931993

19941994
</div>
19951995

1996+
#### The browsingContext.traverseHistory Command #### {#command-browsingContext-traverseHistory}
1997+
1998+
The <dfn export for=commands>browsingContext.traverseHistory</dfn> command
1999+
traverses the history of a given context by a delta.
2000+
2001+
<dl>
2002+
<dt>Command Type</dt>
2003+
<dd>
2004+
<pre class="cddl remote-cddl">
2005+
BrowsingContextTraverseHistoryCommand = {
2006+
method: "browsingContext.traverseHistory",
2007+
params: BrowsingContextTraverseHistoryParameters
2008+
}
2009+
2010+
BrowsingContextReloadParameters = {
2011+
context: BrowsingContext,
2012+
delta: int,
2013+
?wait: ReadinessState,
2014+
}
2015+
</pre>
2016+
</dd>
2017+
<dt>Return Type</dt>
2018+
<dd>
2019+
<pre class="cddl local-cddl">
2020+
BrowsingContextTraverseHistoryResult = {
2021+
navigation: Navigation / null,
2022+
?persisted: bool
2023+
url: text,
2024+
}
2025+
</pre>
2026+
</dd>
2027+
</dl>
2028+
2029+
<div algorithm="remote end steps for browsingContext.traverseHistory">
2030+
The [=remote end steps=] with |command parameters| are:
2031+
2032+
1. Let |context id| be the value of the <code>context</code> field of
2033+
|command parameters|.
2034+
2035+
1. Let |context| be the result of [=trying=] to [=get a browsing context=]
2036+
with |context id|.
2037+
2038+
1. Assert: |context| is not null.
2039+
2040+
1. Let |delta| be the value of the <code>delta</code> field of |command
2041+
parameters|.
2042+
2043+
1. Let |wait condition| be the value of the <code>wait</code> field of |command
2044+
parameters| if present, or "<code>none</code>" otherwise.
2045+
2046+
1. Let |navigate status| be the result of running the [=traverse the history
2047+
by a delta steps=] given |delta|, and |context|.
2048+
2049+
1. If |navigate status|'s status is "<code>canceled</code>" return [=error=]
2050+
with [=error code=] [=unknown error=].
2051+
2052+
1. Assert: |navigate status|'s status is "<code>pending</code>" and
2053+
|navigation id| is not null.
2054+
2055+
1. If |wait condition| is "<code>none</code>":
2056+
2057+
1. Let |body| be a [=map=] matching the
2058+
<code>BrowsingContextNavigateResult</code> production, with the
2059+
<code>navigation</code> field set to |navigation id|, and the
2060+
<code>url</code> field set to the result of the [=URL serializer=] given
2061+
|navigate status|'s url.
2062+
2063+
1. If |wait condition| is "<code>interactive</code>", let |event name| be
2064+
"<code>domContentLoaded</code>", otherwise let |event name| be
2065+
"<code>load</code>".
2066+
2067+
1. Let (|event received|, |status|) be [=await=] given «|event name|,
2068+
"<code>download started</code>", "<code>navigation failed</code>",
2069+
"<code>page show</code>"» and |navigation id|.
2070+
2071+
1. If |event received| is "<code>navigation failed</code>"
2072+
return [=error=] with [=error code=] [=unknown error=].
2073+
2074+
1. If |event received| is "<code>page show</code>", let |persisted| be true,
2075+
otherwise let |persisted| be false.
2076+
2077+
1. Let |body| be a [=map=] matching the
2078+
<code>BrowsingContextTraverseHistoryResult</code> production, with the
2079+
<code>navigation</code> field set to |status|'s id, the
2080+
<code>persisted</code> field set to |persisted|, and the <code>url</code>
2081+
field set to the result of the [=URL serializer=] given |status|'s url.
2082+
2083+
1. Return [=success=] with data |body|.
2084+
2085+
</div>
2086+
2087+
<div algorithm>
2088+
2089+
The <dfn export>WebDriver-BiDi page show</dfn> steps given <var
2090+
ignore>context</var> and |navigation status| are:
2091+
2092+
Issue: Do we want to expose a `browsingContext.pageShow event? In that case we'd
2093+
need to call this whenever `pageshow` is going to be emitted, not just on
2094+
bfcache restore, and also add the persisted status to the data.
2095+
2096+
1. If the [=current session=] is null, return.
2097+
2098+
1. Let |navigation id| be |navigation status|'s id.
2099+
2100+
1. [=Resume=] with "<code>page show</code>", |navigation id|, and
2101+
|navigation status|.
2102+
2103+
</div>
2104+
2105+
19962106
### Events ### {#module-contexts-events}
19972107

19982108
#### The browsingContext.contextCreated Event #### {#event-browsingContext-contextCreated}

0 commit comments

Comments
 (0)