From af080a673854a9f0288f0f291cc3f7120754ebac Mon Sep 17 00:00:00 2001 From: James Graham Date: Fri, 8 Mar 2024 15:22:22 +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 | 55 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/index.bs b/index.bs index cbf8c140e..33369f520 100644 --- a/index.bs +++ b/index.bs @@ -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 @@ -408,7 +411,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.
@@ -1410,6 +1413,7 @@ session.CapabilityRequest = { ? socksProxy: text, ? socksVersion: 0..255, }, + ? userPromptHandler: session.UserPromptHandler, Extensible }; @@ -1417,6 +1421,28 @@ session.CapabilityRequest = { The session.CapabilityRequest type represents a specific set of requested capabilities. +#### 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}
@@ -1525,6 +1551,7 @@ This is a [=static command=].
             ? socksVersion: 0..255,
           },
           setWindowRect: bool,
+          ? userPromptHandler: session.UserPromptHandler,
           Extensible
         }
       }
@@ -1543,9 +1570,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|.
 
@@ -3598,8 +3628,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
         }
       
@@ -3615,12 +3646,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 @@ -3633,13 +3670,9 @@ opened steps given |window|, |type|, |message|, and optional |default valu 1. [=Emit an event=] with |session| and |body|. -1. If |type| is "beforeUnload": - - 1. For each |session| in [=active sessions=]: +1. If |handler| is "ignore", set handler to "none". - 1. If |session|'s [=http flag=] is true, return "accept". - -1. Return null. +1. Return |handler|