Skip to content

Commit 56f8f96

Browse files
authored
Add session.end and browser.close commands (#286)
The session.end command shuts down the current WebDriver session without otherwise affecting the browser. browser.close ends the current session and also performs cleanup steps including at least closing browser windows that were under automation.
1 parent 5136b19 commit 56f8f96

File tree

1 file changed

+189
-0
lines changed

1 file changed

+189
-0
lines changed

index.bs

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ spec: RFC6455; urlPrefix: https://tools.ietf.org/html/rfc6455
2424
text: %x1 denotes a text frame; url: section-5.2
2525
text: Send a WebSocket Message; url: section-6.1
2626
text: A WebSocket Message Has Been Received; url: section-6.2
27+
text: Start The WebSocket Closing Handshake; url: section-7.1.2
2728
text: The WebSocket Closing Handshake is Started; url: section-7.1.3
2829
text: The WebSocket Connection is Closed; url: section-7.1.4
2930
text: Fail the WebSocket Connection; url: section-7.1.7
@@ -40,6 +41,7 @@ spec: WEBDRIVER; urlPrefix: https://w3c.github.io/webdriver/
4041
text: additional WebDriver capability; url: dfn-additional-webdriver-capability
4142
text: additional capability deserialization algorithm; url: dfn-additional-capability-deserialization-algorithm
4243
text: capability name; url: dfn-capability-name
44+
text: close the session; url: dfn-close-the-session
4345
text: create a session; url: dfn-create-a-session
4446
text: dispatch actions; url: dfn-dispatch-actions
4547
text: dispatch tick actions; url: dfn-dispatch-tick-actions
@@ -287,6 +289,7 @@ Command = {
287289
}
288290

289291
CommandData = (
292+
BrowserCommand //
290293
BrowsingContextCommand //
291294
InputCommand //
292295
NetworkCommand //
@@ -470,6 +473,12 @@ with the following additional codes:
470473
<dd>Tried to deserialize an unknown <code>SharedReference</code>.
471474
</dl>
472475

476+
<dl>
477+
<dt><dfn>unable to close browser</dfn>
478+
<dd>Tried to close the browser, but failed to do so.
479+
</dl>
480+
481+
473482
<pre class="cddl local-cddl">
474483
ErrorCode = ("invalid argument" /
475484
"invalid session id" /
@@ -479,6 +488,7 @@ ErrorCode = ("invalid argument" /
479488
"no such node" /
480489
"no such script" /
481490
"session not created" /
491+
"unable to close browser" /
482492
"unknown command" /
483493
"unknown error" /
484494
"unsupported operation")
@@ -827,6 +837,8 @@ To <dfn>handle an incoming message</dfn> given a [=WebSocket connection=]
827837
an error response=] given |connection|, null, and [=invalid argument=], and
828838
finally return.
829839

840+
1. If |session| is not null and not in [=active sessions=] then return.
841+
830842
1. Match |parsed| against the [=remote end definition=]. If this results in a
831843
match:
832844

@@ -977,6 +989,23 @@ Note: This does not end any [=/session=].
977989
Issue: Need to hook in to the session ending to allow the UA to close
978990
the listener if it wants.
979991

992+
</div>
993+
994+
<div algorithm>
995+
996+
To <dfn>close the WebSocket connections</dfn> given |session|:
997+
998+
1. For each |connection| in |session|'s[=session WebSocket
999+
connections=]:
1000+
1001+
1. [=Start the WebSocket closing handshake=] with |connection|.
1002+
1003+
Note: this will result in the steps in [=handle a connection closing=]
1004+
being run for |connection|, which will clean up resources associated with
1005+
|connection|.
1006+
1007+
</div>
1008+
9801009
## Establishing a Connection ## {#establishing}
9811010

9821011
WebDriver clients opt in to a bidirectional connection by requesting a
@@ -1172,6 +1201,7 @@ events for monitoring the status of the remote end.
11721201

11731202
<pre class="cddl remote-cddl">
11741203
SessionCommand = (
1204+
session.End //
11751205
session.New //
11761206
session.Status //
11771207
session.Subscribe //
@@ -1186,7 +1216,26 @@ SessionResult = (session.StatusResult)
11861216
</pre>
11871217

11881218
<div algorithm>
1219+
To <dfn>end the session</dfn> given |session|:
1220+
1221+
1. Remove |session| from [=active sessions=].
1222+
1223+
1. If [=active sessions=] is [=list/empty=], set the [=webdriver-active flag=]
1224+
to false.
1225+
1226+
</div>
1227+
1228+
<div algorithm>
1229+
1230+
To <dfn>cleanup the session</dfn> given |session|:
1231+
1232+
1. [=Close the WebSocket connections=] with |session|.
1233+
1234+
1. Perform any implementation-specific cleanup steps.
1235+
1236+
</div>
11891237

1238+
<div algorithm>
11901239
To <dfn>update the event map</dfn>, given
11911240
|session|, |requested event names|, |browsing contexts|, and |enabled|:
11921241

@@ -1479,6 +1528,50 @@ The [=remote end steps=] given |session| and |command parameters| are:
14791528

14801529
</div>
14811530

1531+
#### The session.end Command #### {#command-session-end}
1532+
1533+
The <dfn export for=commands>session.end</dfn> command ends the current
1534+
[=/session=].
1535+
1536+
<dl>
1537+
<dt>Command Type</dt>
1538+
<dd>
1539+
<pre class="cddl remote-cddl">
1540+
session.End = {
1541+
method: "session.end",
1542+
params: EmptyParams
1543+
}
1544+
1545+
</pre>
1546+
</dd>
1547+
<dt>Result Type</dt>
1548+
<dd>
1549+
<pre class="cddl">
1550+
EmptyResult
1551+
</pre>
1552+
</dd>
1553+
</dl>
1554+
1555+
<div algorithm="remote end steps for session.end">
1556+
1557+
The [=remote end steps=] given |session| and <var ignore>command parameters</var> are:
1558+
1559+
1. [=End the session=] with |session|.
1560+
1561+
1. Return [=success=] with data null, and in parallel run the following steps:
1562+
1563+
1. Wait until the [=Send a WebSocket message=] steps have been called with the
1564+
response to this command.
1565+
1566+
Issue: this is rather imprecise language, but hopefully it's clear that the
1567+
intent is that we send the response to the command before starting shutdown
1568+
of the connections.
1569+
1570+
1. [=Cleanup the session=] with |session|.
1571+
1572+
</div>
1573+
1574+
14821575
#### The session.subscribe Command #### {#command-session-subscribe}
14831576

14841577
The <dfn export for=commands>session.subscribe</dfn> command enables certain events
@@ -1588,6 +1681,102 @@ The [=remote end steps=] with |session| and |command parameters| are:
15881681

15891682
</div>
15901683

1684+
## The browser Module ## {#module-browser}
1685+
1686+
The <dfn export for=modules>browser</dfn> module contains commands for
1687+
managing the remote end browser process.
1688+
1689+
### Definition ### {#module-browser-definition}
1690+
1691+
[=remote end definition=]
1692+
1693+
<pre class="cddl remote-cddl">
1694+
BrowserCommand = (
1695+
browser.Close
1696+
)
1697+
</pre>
1698+
1699+
[=local end definition=]
1700+
1701+
<!-- Nothing yet -->
1702+
<pre class="cddl local-cddl">
1703+
</pre>
1704+
1705+
1706+
### Commands ### {#module-browser-commands}
1707+
1708+
#### The browser.close Command #### {#command-browser-close}
1709+
1710+
The <dfn export for=commands>browser.close</dfn> command terminates all
1711+
WebDriver sessions and cleans up automation state in the remote browser instance.
1712+
1713+
<dl>
1714+
<dt>Command Type</dt>
1715+
<dd>
1716+
<pre class="cddl remote-cddl">
1717+
browser.Close = {
1718+
method: "browser.close",
1719+
params: EmptyParams,
1720+
}
1721+
</pre>
1722+
</dd>
1723+
<dt>Return Type</dt>
1724+
<dd>
1725+
<pre class="cddl">
1726+
EmptyResult
1727+
</pre>
1728+
</dd>
1729+
</dl>
1730+
1731+
<div algorithm="remote end steps for browser.close">
1732+
The [=remote end steps=] with |session| and <var ignore>command parameters</var> are:
1733+
1734+
1. [=End the session=] with |session|.
1735+
1736+
1. If [=active sessions=] is not [=list/empty=] an implementation may
1737+
return [=error=] with [=error code=] [=unable to close browser=], and then
1738+
run the following steps [=in parallel=]:
1739+
1740+
1. Wait until the [=Send a WebSocket message=] steps have been called with the
1741+
response to this command.
1742+
1743+
1. [=Cleanup the session=] with |session|.
1744+
1745+
Note: The behaviour in cases where the browser has multiple automation
1746+
sessions is currently unspecified. It might be that any session can close the
1747+
browser, or that only the final open session can actually close the browser,
1748+
or only the first session started can. This behaviour might be fully
1749+
specified in a future version of this specification.
1750+
1751+
1. For each |active session| in [=active sessions=]:
1752+
1753+
1. [=End the session=] |active session|.
1754+
1755+
1. [=Cleanup the session=] with |active session|
1756+
1757+
1. Return [=success=] with data null, and run the following steps [=in parallel=].
1758+
1759+
1. Wait until the [=Send a WebSocket message=] steps have been called with the
1760+
response to this command.
1761+
1762+
1. [=Cleanup the session=] with |session|.
1763+
1764+
1. [=Close=] any [=top-level browsing contexts=] without [=prompting to unload=].
1765+
1766+
Note: This implicitly only affects browsing contexts that were under
1767+
automation in the first place.
1768+
1769+
1. Perform implementation defined steps to clean up resources associated with
1770+
the [=remote end=] under automation.
1771+
1772+
Note: For example this might include cleanly shutting down any OS-level
1773+
processes associated with the browser under automation, removing temporary
1774+
state, such as user profile data, created by the [=remote end=] while under
1775+
automation, or shutting down the [=WebSocket Listener=]. Because of
1776+
differences between browsers and operating systems it is not possible to
1777+
specify in detail precise invariants [=local ends=] can depend on here.
1778+
1779+
</div>
15911780

15921781
## The browsingContext Module ## {#module-browsingContext}
15931782

0 commit comments

Comments
 (0)