Skip to content

emulation.setNetworkConditions:offline #948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,20 @@ A [=BiDi session=] has a
A [=BiDi session=] has a <dfn>user context to proxy configuration map</dfn>, which is
a [=/map=] between [=user contexts=] and [=proxy configuration=].

An <dfn>emulated network conditions struct</dfn> is a [=struct=] with:
* [=struct/item=] named <dfn id="emulated-network-conditions-struct-offline"
for="emulated-network-conditions-struct">offline</dfn> which is a boolean or null.

A [=BiDi session=] has a <dfn for=session>emulated network conditions</dfn> which is
a [=struct=] with an [=struct/item=] named <dfn
for="emulated network conditions">default network conditions</dfn>, which is an
[=emulated network conditions struct=] or null, an [=struct/item=] named
<dfn for="emulated network conditions">user context network conditions</dfn>, which
is a weak map between [=user contexts=] and [=emulated network conditions struct=],
and a [=struct/item=] named
<dfn for="emulated network conditions">navigable network conditions</dfn>, which is a
weak map between [=navigables=] and [=emulated network conditions struct=].

When a [=user context=] is [=set/remove|removed=] from the
[=set of user contexts=], [=remove user context subscriptions=].

Expand Down Expand Up @@ -5825,6 +5839,7 @@ EmulationCommand = (
emulation.SetForcedColorsModeThemeOverride //
emulation.SetGeolocationOverride //
emulation.SetLocaleOverride //
emulation.SetNetworkConditions //
emulation.SetScreenOrientationOverride //
emulation.SetScriptingEnabled //
emulation.SetTimezoneOverride
Expand Down Expand Up @@ -6153,6 +6168,91 @@ The [=remote end steps=] with |command parameters| are:

</div>

#### The emulation.setNetworkConditions Command #### {#command-emulation-setNetworkConditions}

The <dfn export for=commands>emulation.setNetworkConditions</dfn> command
emulates specific network conditions for the given browsing context or for a user
context.

<dl>
<dt>Command Type</dt>
<dd>
<pre class="cddl" data-cddl-module="remote-cddl">
emulation.SetNetworkConditions = (
method: "emulation.setNetworkConditions",
params: emulation.setNetworkConditionsParameters
)

emulation.setNetworkConditionsParameters = {
networkConditions: emulation.NetworkConditions / null,
? contexts: [+browsingContext.BrowsingContext],
? userContexts: [+browser.UserContext],
}

emulation.NetworkConditions = emulation.NetworkConditionsOffline

emulation.NetworkConditionsOffline = {
type: "offline"
}
</pre>
</dd>
<dt>Result Type</dt>
<dd>
<code>
EmptyResult
</code>
</dd>
</dl>

<div algorithm="remote end steps for emulation.setNetworkConditions">

The [=remote end steps=] with |command parameters| and |session| are:

1. If |command parameters| [=map/contains=] "<code>userContexts</code>"
and |command parameters| [=map/contains=] "<code>context</code>",
return [=error=] with [=error code=] [=invalid argument=].

1. Let |emulated network conditions| be null.

1. If |command parameters|["<code>networkConditions</code>"] is not null and
|command parameters|["<code>networkConditions</code>"]["<code>type</code>"]
equals "<code>offline</code>", set |emulated network conditions| to a new
[=emulated network conditions struct=] with
[=emulated-network-conditions-struct/offline=] set to true.

1. If the <code>contexts</code> field of |command parameters| is present:

1. Let |navigables| be the result of [=trying=] to
[=get valid top-level traversables by ids=] with
|command parameters|["<code>contexts</code>"].

1. For each |navigable| of |navigables|:

1. [=map/Set=] |session|'s [=emulated network conditions=]'s
[=emulated network conditions/navigable network conditions=][|navigable|] to
|emulated network conditions|.

1. If the <code>userContexts</code> field of |command parameters| is present:

1. Let |user contexts| be the result of [=trying=] to [=get valid user contexts=]
with |command parameters|["<code>userContexts</code>"].

1. For each |user context| of |user contexts|:

1. [=map/Set=] |session|'s [=emulated network conditions=]'s
[=emulated network conditions/user context network conditions=][|user context|]
to |emulated network conditions|.

1. If |command parameters| doesn't [=map/contain=] "<code>userContexts</code>"
and |command parameters| doesn't [=map/contain=] "<code>context</code>",
[=map/set=] |session|'s [=emulated network conditions=]'s
[=emulated network conditions/default network conditions=][|user context|] to
|emulated network conditions|.

1. Return [=success=] with data null.

</div>

#### The emulation.setScreenOrientationOverride Command #### {#command-emulation-setScreenOrientationOverride}

The <dfn export for=commands>emulation.setScreenOrientationOverride</dfn> command
Expand Down Expand Up @@ -9383,6 +9483,56 @@ and |user context| are:

</div>

<div algorithm>
The steps to <dfn>get emulated network conditions</dfn> given |related navigables|
are:

1. For each |navigable| of |related navigables|:

1. Let |top-level traversable| be |navigable|’s [=navigable/top-level traversable=].

1. Let |user context| be |top-level traversable|'s [=associated user context=].

1. For each |session| in [=active BiDI sessions=]:

1. If |session|'s [=emulated network conditions=]'s
[=emulated network conditions/navigable network conditions=]
[=map/contains=] |top-level traversable|, return |session|'s
[=emulated network conditions=]'s
[=emulated network conditions/navigable network conditions=][|top-level traversable|].

1. If |session|'s [=emulated network conditions=]'s
[=emulated network conditions/user context network conditions=]
[=map/contains=] |user context|, return |session|'s
[=emulated network conditions=]'s
[=emulated network conditions/user context network conditions=][|user context|].

1. If |session|'s [=emulated network conditions=]'s
[=emulated network conditions/default network conditions=] is not null,
return |session|'s [=emulated network conditions=]'s
[=emulated network conditions/default network conditions=].

1. Return null.

</div>

<div algorithm>
The <dfn export>WebDriver BiDi network is offline</dfn> steps given
[=environment settings object=] |settings| are:

1. Let |navigable| be |settings|'s [=relevant global object=]'s
<a>associated <code>Document</code></a>'s [=/node navigable=].

1. Let |emulated network conditions| be the result of
[=get emulated network conditions=] with [|navigable|].

1. If |emulated network conditions| is not null and |emulated network conditions|'s
[=emulated-network-conditions-struct/offline=] is true, return true.

1. Return false.

</div>

<div algorithm>
The [=remote end event trigger=] is the <dfn export>WebDriver BiDi before
request sent</dfn> steps given |request|:
Expand Down Expand Up @@ -9490,8 +9640,17 @@ request sent</dfn> steps given |request|:

Note: While waiting, no further processing of the request occurs.

1. Let |emulated network conditions| be the result of
[=get emulated network conditions=] with |related navigables|.

1. If |emulated network conditions| is not null and
|emulated network conditions|'s [=emulated-network-conditions-struct/offline=] is
true, return ([=network error=], "<code>complete</code>").

1. Return (|response|, |response status|).

Issue: Respect return value in Fetch's "HTTP-network-or-cache fetch" algorithm.

</div>

#### The network.fetchError Event #### {#event-network-fetchError}
Expand Down