Skip to content

Commit

Permalink
Support user prompt handlers for BiDi sessions
Browse files Browse the repository at this point in the history
The key part of this is that with BiDi HTML calls into the spec when
it's going to show a prompt. So at that point we can see if there's a
handler defined, and if so return the handler to HTML.

All the actual logic to handle the dialogs ends up in the HTML spec.

From the BiDi point of view, the intended lifecycle is that you always
get the session.userPromptOpened and session.userPromptClosed events,
even if the prompt is automatically handled. But the
session.UserPromptOpened event gets a new `handler` property that
tells you whether the prompt will be automatically handled; if this is
set to "none" the automation has to send a session.handleUserPrompt
command (or wait for the prompt to be dismissed by the user).
  • Loading branch information
jgraham committed Mar 8, 2024
1 parent 45ab9a2 commit af080a6
Showing 1 changed file with 44 additions and 11 deletions.
55 changes: 44 additions & 11 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ spec: HTML; urlPrefix: https://html.spec.whatwg.org/multipage/
text: window open steps; url: window-object.html#window-open-steps
text: worker event loop; url: webappapis.html#worker-event-loop-2
text: worklet global scopes; url:worklets.html#concept-document-worklet-global-scopes
spec: INFRA; urlPrefix: https://infra.spec.whatwg.org/
type: dfn
text: convert a JSON-derived JavaScript value to an Infra value; url: convert-a-json-derived-javascript-value-to-an-infra-value
spec: RESOURCE-TIMING; urlPrefix: https://w3c.github.io/resource-timing/
type: dfn
text: convert fetch timestamp; url: dfn-convert-fetch-timestamp
Expand Down Expand Up @@ -408,7 +411,7 @@ WebDriver BiDi extends the [=/session=] concept from [[WEBDRIVER|WebDriver]].
A [=/session=] has a <dfn>BiDi flag</dfn>, which is false unless otherwise
stated.

A <dfn>BiDi session</dfn> is a [=/session=] which has the [=BiDi flag=]
A <dfn export>BiDi session</dfn> is a [=/session=] which has the [=BiDi flag=]
set to true.

<div algorithm>
Expand Down Expand Up @@ -1410,13 +1413,36 @@ session.CapabilityRequest = {
? socksProxy: text,
? socksVersion: 0..255,
},
? userPromptHandler: session.UserPromptHandler,
Extensible
};
</pre>

The <code>session.CapabilityRequest</code> type represents a specific set of
requested capabilities.

#### The session.UserPromptHandler Type #### {#type-session-UserPromptHandler}

[=remote end definition=] and [=local end definition=]

<pre class="cddl remote-cddl local-cddl">
session.UserPromptHandler = session.UserPromptHandlerType /
session.UserPromptHandlerConfiguration;

session.UserPromptHandlerType = "accept" / "dismiss" / "ignore";

session.UserPromptHandlerConfiguration = {
? alert: session.UserPromptHandlerType,
? beforeUnload: session.UserPromptHandlerType,
? confirm: session.UserPromptHandlerType,
? default: session.UserPromptHandlerType,
? prompt: session.UserPromptHandlerType,
};
</pre>

The <code>session.UserPromptHandler</code> type represents the configuration of
the user prompt handler.

#### The session.SubscriptionRequest Type #### {#type-session-SubscriptionRequest}

<pre class="cddl remote-cddl">
Expand Down Expand Up @@ -1525,6 +1551,7 @@ This is a [=static command=].
? socksVersion: 0..255,
},
setWindowRect: bool,
? userPromptHandler: session.UserPromptHandler,
Extensible
}
}
Expand All @@ -1543,9 +1570,12 @@ The [=remote end steps=] given |session| and |command parameters| are:

1. Let |flags| be a [=/set=] containing "<code>bidi</code>".

1. Let |capabilities| be the result of [=trying=] to [=process capabilities=]
1. Let |capabilities json| be the result of [=trying=] to [=process capabilities=]
with |command parameters| and |flags|.

1. Let |capabilities| be [=convert a JSON-derived JavaScript value to an Infra
value=] with |capabilities json|.

1. Let |session| be the result of [=trying=] to [=create a session=] with
|capabilities| and |flags|.

Expand Down Expand Up @@ -3598,8 +3628,9 @@ closed</dfn> steps given |window|, |accepted| and optional |user text|

browsingContext.UserPromptOpenedParameters = {
context: browsingContext.BrowsingContext,
type: "alert" / "confirm" / "prompt" / "beforeunload",
handler: "accept" / "dismiss" / "ignore",
message: text,
type: "alert" / "confirm" / "prompt" / "beforeunload",
? defaultValue: text
}
</pre>
Expand All @@ -3615,12 +3646,18 @@ opened</dfn> steps given |window|, |type|, |message|, and optional |default valu

1. Let |context id| be the [=browsing context id=] for |context|.

1. Let |handler configuration| be [=get the prompt handler=] with |type|.

1. Let |handler| be |handler configuration|'s [=prompt handler
configuration/handler=].

1. Let |params| be a [=/map=] matching the
<code>browsingContext.UserPromptOpenedParameters</code> production with the
<code>context</code> field set to |context id|, the <code>type</code> field
set to |type|, the <code>message</code> field set to |message|, and the
set to |type|, the <code>message</code> field set to |message|, the
<code>defaultValue</code> field set to |default value| if |default value| is
not null or omitted otherwise.
not null or omitted otherwise, and the <code>handler</code> field set to
|handler|.

1. Let |body| be a [=/map=] matching the
<code>browsingContext.UserPromptOpened</code> production, with the
Expand All @@ -3633,13 +3670,9 @@ opened</dfn> steps given |window|, |type|, |message|, and optional |default valu

1. [=Emit an event=] with |session| and |body|.

1. If |type| is "<code>beforeUnload</code>":

1. For each |session| in [=active sessions=]:
1. If |handler| is "<code>ignore</code>", set handler to "<code>none</code>".

1. If |session|'s [=http flag=] is true, return "<code>accept</code>".

1. Return null.
1. Return |handler|

</div>

Expand Down

0 comments on commit af080a6

Please sign in to comment.