From e47f74434a0cc640fcbfd450f735a2d1949d6279 Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 17 Jan 2024 13:23:39 +0000 Subject: [PATCH] Support user prompt handlers for BiDi sessions 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). --- index.bs | 68 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/index.bs b/index.bs index b09d29a5..4116ac51 100644 --- a/index.bs +++ b/index.bs @@ -228,6 +228,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 @@ -480,7 +483,7 @@ WebDriver BiDi extends the [=/session=] concept from [[WEBDRIVER|WebDriver]]. A [=/session=] has a BiDi flag, which is false unless otherwise stated. -A BiDi session is a [=/session=] which has the [=BiDi flag=] +A BiDi session is a [=/session=] which has the [=BiDi flag=] set to true.
@@ -1549,8 +1552,17 @@ session.CapabilityRequest = { ? browserName: text, ? browserVersion: text, ? platformName: text, - ? proxy: session.ProxyConfiguration, - ? webSocketUrl: bool, + ? proxy: { + ? proxyType: "pac" / "direct" / "autodetect" / "system" / "manual", + ? proxyAutoconfigUrl: text, + ? ftpProxy: text, + ? httpProxy: text, + ? noProxy: [*text], + ? sslProxy: text, + ? socksProxy: text, + ? socksVersion: 0..255, + }, + ? userPromptHandler: session.UserPromptHandler, Extensible }; @@ -1591,10 +1603,6 @@ with parameter |value| is:
#### The session.ProxyConfiguration Type #### {#type-session-ProxyConfiguration} - -[=remote end definition=] and [=local end definition=] - -
 session.ProxyConfiguration = {
    session.AutodetectProxyConfiguration //
    session.DirectProxyConfiguration //
@@ -1641,6 +1649,28 @@ session.SystemProxyConfiguration = (
 
 
+#### The session.UserPromptHandler Type #### {#type-session-UserPromptHandler} + +[=Remote end definition=] and [=local end definition=] + +
+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,
+};
+
+ +The session.UserPromptHandler type represents the configuration of +the user prompt handler. + #### The session.SubscriptionRequest Type #### {#type-session-SubscriptionRequest}
@@ -1741,6 +1771,7 @@ This is a [=static command=].
           setWindowRect: bool,
           userAgent: text,
           ? proxy: session.ProxyConfiguration,
+          ? userPromptHandler: session.UserPromptHandler,
           ? webSocketUrl: text,
           Extensible
         }
@@ -1760,9 +1791,12 @@ The [=remote end steps=] given |session| and |command parameters| are:
 
 1. Let |flags| be a [=/set=] containing "bidi".
 
-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|.
 
@@ -4436,8 +4470,9 @@ closed 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
         }
       
@@ -4453,12 +4488,18 @@ opened 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 browsingContext.UserPromptOpenedParameters production with the context field set to |context id|, the type field - set to |type|, the message field set to |message|, and the + set to |type|, the message field set to |message|, the defaultValue field set to |default value| if |default value| is - not null or omitted otherwise. + not null or omitted otherwise, and the handler field set to + |handler|. 1. Let |body| be a [=/map=] matching the browsingContext.UserPromptOpened production, with the @@ -4471,6 +4512,10 @@ opened steps given |window|, |type|, |message|, and optional |default valu 1. [=Emit an event=] with |session| and |body|. +1. If |handler| is "ignore", set handler to "none". + +1. Return |handler| + ## The network Module ## {#module-network} @@ -10538,6 +10583,7 @@ The [=remote end steps=] given |session| and |command parameters| are: + # Patches to Other Specifications # {#patches} This specification requires some changes to external specifications to provide the necessary