From 6e47d7830038b9b53d7c8e34a0af6bdd6fd766e0 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 | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/index.bs b/index.bs index d5e5e43e..b0112f0f 100644 --- a/index.bs +++ b/index.bs @@ -90,6 +90,7 @@ spec: WEBDRIVER; urlPrefix: https://w3c.github.io/webdriver/ text: no such element; url: dfn-no-such-element text: no such frame; url: dfn-no-such-frame text: parse a page range; url: dfn-parse-a-page-range + text: handler; for: prompt handler configuration; url: dfn-handler text: process capabilities; url: dfn-processing-capabilities text: readiness state; url: dfn-readiness-state text: remote end steps; url: dfn-remote-end-steps @@ -228,6 +229,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 @@ -1550,7 +1554,7 @@ session.CapabilityRequest = { ? browserVersion: text, ? platformName: text, ? proxy: session.ProxyConfiguration, - ? webSocketUrl: bool, + ? userPromptHandler: session.UserPromptHandler, Extensible }; @@ -1641,6 +1645,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 +1767,7 @@ This is a [=static command=].
           setWindowRect: bool,
           userAgent: text,
           ? proxy: session.ProxyConfiguration,
+          ? userPromptHandler: session.UserPromptHandler,
           ? webSocketUrl: text,
           Extensible
         }
@@ -1760,9 +1787,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|.
 
@@ -4422,8 +4452,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
         }
       
@@ -4439,12 +4470,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 @@ -4457,6 +4494,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} @@ -10535,6 +10576,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