Skip to content

Commit 05d75bf

Browse files
jgrahamfoolip
andauthored
Initial support for handling user prompts (#195)
Add two events for user prompts: one when a prompt is opened and one when it's closed. Also a command to respond to an existing user prompt. Co-authored-by: Philip Jägenstedt <[email protected]>
1 parent 7e81a9e commit 05d75bf

File tree

1 file changed

+163
-1
lines changed

1 file changed

+163
-1
lines changed

index.bs

Lines changed: 163 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ spec: WEBDRIVER; urlPrefix: https://w3c.github.io/webdriver/
5353
text: local end; url: dfn-local-ends
5454
text: matched capability serialization algorithm; url: dfn-matched-capability-serialization-algorithm
5555
text: maximum active sessions; url: dfn-maximum-active-sessions
56+
text: no such alert; url: dfn-no-such-alert
5657
text: no such element; url: dfn-no-such-element
5758
text: no such frame; url: dfn-no-such-frame
5859
text: process capabilities; url: dfn-processing-capabilities
@@ -130,14 +131,18 @@ spec: GEOMETRY; urlPrefix: https://drafts.fxtf.org/geometry/
130131
spec: HTML; urlPrefix: https://html.spec.whatwg.org/multipage/
131132
type: dfn
132133
text: a browsing context is discarded; url: window-object.html#a-browsing-context-is-discarded
134+
text: alert; url: timers-and-user-prompts.html#dom-alert
133135
text: close; url: window-object.html#close-a-browsing-context
134136
text: create a classic script; url: webappapis.html#creating-a-classic-script
135137
text: create a new browsing context; url: browsers.html#creating-a-new-browsing-context
138+
text: confirm; url: timers-and-user-prompts.html#dom-confirm
136139
text: default classic script fetch options; url: webappapis.html#default-classic-script-fetch-options
137140
text: environment settings object's Realm; url: webappapis.html#environment-settings-object's-realm
138141
text: handled; url: webappapis.html#concept-error-handled
139142
text: history handling behavior; url: browsing-the-web.html#history-handling-behavior
140143
text: navigation id; url: browsing-the-web.html#navigation-id
144+
text: prompt; url: timers-and-user-prompts.html#dom-prompt
145+
text: prompt to unload; url: browsing-the-web.html#prompt-to-unload-a-document
141146
text: report an error; url: webappapis.html#report-the-error
142147
text: remove a browsing context; url: browsers.html#bcg-remove
143148
text: run the animation frame callbacks; url: imagebitmap-and-animations.html#run-the-animation-frame-callbacks
@@ -2460,6 +2465,7 @@ BrowsingContextCommand = (
24602465
BrowsingContextCloseCommand //
24612466
BrowsingContextCreateCommand //
24622467
BrowsingContextGetTreeCommand //
2468+
BrowsingContextHandleUserPromptCommand //
24632469
BrowsingContextNavigateCommand //
24642470
BrowsingContextReloadCommand
24652471
)
@@ -2485,7 +2491,9 @@ BrowsingContextEvent = (
24852491
BrowsingContextLoadEvent //
24862492
BrowsingContextDownloadWillBegin //
24872493
BrowsingContextNavigationAbortedEvent //
2488-
BrowsingContextNavigationFailedEvent
2494+
BrowsingContextNavigationFailedEvent //
2495+
BrowsingContextUserPromptClosedEvent //
2496+
BrowsingContextUserPromptOpenedEvent
24892497
)
24902498

24912499
</pre>
@@ -2953,6 +2961,70 @@ The [=remote end steps=] with <var ignore>session</var> and |command parameters|
29532961

29542962
</div>
29552963

2964+
#### The browsingContext.handleUserPrompt Command #### {#command-browsingContext-handleUserPrompt}
2965+
2966+
The <dfn export for=commands>browsingContext.handleUserPrompt</dfn>
2967+
command allows closing an open prompt
2968+
2969+
<dl>
2970+
<dt>Command Type</dt>
2971+
<dd>
2972+
<pre class="cddl remote-cddl">
2973+
BrowsingContextHandleUserPromptCommand = {
2974+
method: "browsingContext.handleUserPrompt",
2975+
params: BrowsingContextHandleUserPromptParameters
2976+
}
2977+
2978+
BrowsingContextHandleUserPromptParameters = {
2979+
context: BrowsingContext,
2980+
? accept: bool,
2981+
? userText: text,
2982+
}
2983+
</pre>
2984+
</dd>
2985+
<dt>Return Type</dt>
2986+
<dd>
2987+
<pre class="cddl local-cddl">
2988+
EmptyResult
2989+
</pre>
2990+
</dd>
2991+
</dl>
2992+
2993+
<div algorithm="remote end steps for browsingContext.handleUserPrompt">
2994+
2995+
1. Let |context id| be the value of the <code>context</code> field of
2996+
|command parameters|.
2997+
2998+
1. Let |context| be the result of [=trying=] to [=get a browsing context=]
2999+
with |context id|.
3000+
3001+
1. Let |accept| be the value of the <code>accept</code> field of |command
3002+
parameters| if present, or true otherwise.
3003+
3004+
1. Let |text| be the value of the <code>text</code> field of |command
3005+
parameters| if present, or the empty string otherwise.
3006+
3007+
1. If |context| is currently showing a simple dialog from a call to [=alert=] then
3008+
acknowledge the prompt.
3009+
3010+
Otherwise if |context| is currently showing a simple dialog from a call to
3011+
[=confirm=], then respond positively if |accept| is true, or respond
3012+
negatively if |accept| is false.
3013+
3014+
Otherwise if |context| is currently showing a simple dialog from a call to
3015+
[=prompt=], then respond with the string value |text| if |accept| is
3016+
true, or abort if |accept| is false.
3017+
3018+
Otherwise, if |context| is currently showing a prompt as part of the [=prompt
3019+
to unload=] steps, then confirm the navigation if |accept| is true, otherwise
3020+
refuse the navigation.
3021+
3022+
Otherwise return [=error=] with [=error code=] [=no such alert=].
3023+
3024+
1. Return [=success=] with data null.
3025+
3026+
</div>
3027+
29563028
#### The browsingContext.navigate Command #### {#command-browsingContext-navigate}
29573029

29583030
The <dfn export for=commands>browsingContext.navigate</dfn> command navigates a
@@ -3461,6 +3533,96 @@ failed</dfn> steps given |context| and |navigation status|:
34613533

34623534
</div>
34633535

3536+
#### The browsingContext.userPromptClosed Event #### {#event-browsingContext-userPromptClosed}
3537+
3538+
<dl>
3539+
<dt>Event Type</dt>
3540+
<dd>
3541+
<pre class="cddl local-cddl">
3542+
BrowsingContextUserPromptClosedEvent = {
3543+
method: "browsingContext.userPromptClosed",
3544+
params: UserPromptInfo
3545+
}
3546+
UserPromptResult = {
3547+
context: BrowsingContext,
3548+
accepted: bool,
3549+
? userText: text
3550+
}
3551+
</pre>
3552+
</dd>
3553+
</dl>
3554+
3555+
<div algorithm>
3556+
The [=remote end event trigger=] is the <dfn export>WebDriver BiDi user prompt
3557+
closed</dfn> steps given |window|, |accepted| and optional |user text|
3558+
(default: null).
3559+
3560+
1. Let |context| be |window|'s [=browsing context=].
3561+
3562+
1. Let |context id| be the [=browsing context id=] for |context|.
3563+
3564+
1. Let |params| be a [=map=] matching the <code>UserPromptResult</code>
3565+
production with the <code>context</code> field set to |context id|, the
3566+
<code>accepted</code> field set to |accepted|, and the <code>userText</code> field set
3567+
to |user text| if |user text| is not null or omitted otherwise.
3568+
3569+
1. Let |body| be a [=map=] matching the
3570+
<code>BrowsingContextUserPromptClosed</code> production, with the
3571+
<code>params</code> field set to |params|.
3572+
3573+
1. Let |related browsing contexts| be a [=set=] containing |context|.
3574+
3575+
1. For each |session| in the [=set of sessions for which an event is enabled=]
3576+
given "<code>browsingContext.userPromptClosed</code>" and |related browsing contexts|:
3577+
3578+
1. [=Emit an event=] with |session| and |body|.
3579+
3580+
</div>
3581+
3582+
#### The browsingContext.userPromptOpened Event #### {#event-browsingContext-userPromptOpened}
3583+
3584+
<dl>
3585+
<dt>Event Type</dt>
3586+
<dd>
3587+
<pre class="cddl local-cddl">
3588+
BrowsingContextUserPromptOpenedEvent = {
3589+
method: "browsingContext.userPromptOpened",
3590+
params: UserPromptInfo
3591+
}
3592+
UserPromptInfo = {
3593+
context: BrowsingContext,
3594+
type: "alert" / "confirm" / "prompt" / "beforeunload",
3595+
message: text
3596+
}
3597+
</pre>
3598+
</dd>
3599+
</dl>
3600+
3601+
<div algorithm>
3602+
The [=remote end event trigger=] is the <dfn export>WebDriver BiDi user prompt
3603+
opened</dfn> steps given |window|, |type| and |message|.
3604+
3605+
1. Let |context| be |window|'s [=browsing context=].
3606+
3607+
1. Let |context id| be the [=browsing context id=] for |context|.
3608+
3609+
1. Let |params| be a [=map=] matching the <code>UserPromptInfo</code>
3610+
production with the <code>context</code> field set to |context id|, the
3611+
<code>type</code> field set to |type|, and the <code>message</code> field set
3612+
to |message|.
3613+
3614+
1. Let |body| be a [=map=] matching the
3615+
<code>BrowsingContextUserPromptOpened</code> production, with the
3616+
<code>params</code> field set to |params|.
3617+
3618+
1. Let |related browsing contexts| be a [=set=] containing |context|.
3619+
3620+
1. For each |session| in the [=set of sessions for which an event is enabled=]
3621+
given "<code>browsingContext.userPromptOpened</code>" and |related browsing contexts|:
3622+
3623+
1. [=Emit an event=] with |session| and |body|.
3624+
3625+
</div>
34643626

34653627
## The script Module ## {#module-script}
34663628

0 commit comments

Comments
 (0)