From 404977d38905c7000afdf5cfc4a4ed0dd587d704 Mon Sep 17 00:00:00 2001 From: James Graham Date: Mon, 7 Jun 2021 17:13:54 +0100 Subject: [PATCH] Support automatic user prompt handing in WebDriver BiDi This reads the return value from the WebDriver BiDi user prompt opened algorithm and uses it to decide whether to show the prompt, or skip showing it but act as if it had been accepted or canceled. At present the prompt opened function can return three values: "none", which causes the prompt to be displayed, "accept", which acts as if the prompt was accepted, and "dismiss" which acts as if the prompt was rejected. The WebDriver side is responsible for ensuring that only valid responses are sent for each prompt type (e.g. for an alert there isn't a "dismiss" option). --- source | 100 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 33 deletions(-) diff --git a/source b/source index 809aeb97590..8a964867f11 100644 --- a/source +++ b/source @@ -100056,24 +100056,32 @@ location.href = '#foo';
  1. Set unloadPromptShown to true.

  2. -
  3. Invoke WebDriver BiDi user prompt opened with document's - relevant global object, "beforeunload", and "".

  4. +
  5. Let userPromptHandler be the result of WebDriver BiDi user prompt + opened with document's relevant global object, + "beforeunload", and "".

  6. -
  7. -

    Ask the user to confirm that they wish to unload the document, and pause while - waiting for the user's response.

    +
  8. If userPromptHandler is "dismiss", set + unloadPromptCanceled to true. -

    The message shown to the user is not customizable, but instead determined by - the user agent. In particular, the actual value of the returnValue attribute is ignored.

    -
  9. +
  10. If userPromptHandler is "none":

    -
  11. If the user did not confirm the page navigation, set unloadPromptCanceled to - true.

  12. +
  13. Invoke WebDriver BiDi user prompt closed with document's - relevant global object and true if unloadPromptCanceled is false or - false otherwise.

  14. + relevant global object, "beforeunload", and true + if unloadPromptCanceled is false or false otherwise.

@@ -114034,16 +114042,20 @@ function sendData(data) {
  • Set message to the result of optionally truncating message.

  • -
  • Show message to the user, treating U+000A LF as a line break.

  • +
  • Let userPromptHandler be WebDriver BiDi user prompt opened with + this, "alert", and message.

  • -
  • Invoke WebDriver BiDi user prompt opened with this, - "alert", and message.

  • +
  • If userPromptHandler is "none":

    +
      +
    1. Show message to the user, treating U+000A LF as a line break.

    2. -
    3. Optionally, pause while waiting for the user to acknowledge the - message.

    4. +
    5. Optionally, pause while waiting for the user to acknowledge the + message.

    6. +
    +
  • -
  • Invoke WebDriver BiDi user prompt closed with this - and true.

  • +
  • Invoke WebDriver BiDi user prompt closed with this, + "alert", and true.

  • This method is defined using two overloads, instead of using an @@ -114068,16 +114080,27 @@ function sendData(data) {

  • Show message to the user, treating U+000A LF as a line break, and ask the user to respond with a positive or negative response.

  • -
  • Invoke WebDriver BiDi user prompt opened with this, - "confirm", and message.

  • +
  • Let userPromptHandler be WebDriver BiDi user prompt opened with + this, "confirm", and message.

  • -
  • Pause until the user responds either positively or negatively.

  • +
  • Let accepted be false.

  • + +
  • If userPromptHandler is "none":

    + +
      +
    1. Pause until the user responds either positively or negatively.

    2. + +
    3. If the user responded positively set accepted to true

    4. +
    +
  • + +
  • If userPromptHandler is "accept" set accepted to + true.

  • Invoke WebDriver BiDi user prompt closed with this, - and true if the user responded positively or false otherwise.

  • + "confirm", and accepted.

    -
  • If the user responded positively, return true; otherwise, the user responded negatively: - return false.

  • +
  • Return accepted.

  • The prompt(message, @@ -114100,18 +114123,29 @@ function sendData(data) { to either respond with a string value or abort. The response must be defaulted to the value given by default.

    -
  • Invoke WebDriver BiDi user prompt opened with this, - "prompt", message, and default.

  • +
  • Let userPromptHandler be WebDriver BiDi user prompt opened with + this, "prompt" and message.

  • -
  • Pause while waiting for the user's response.

  • +
  • Let result be null.

  • -
  • Let result be null if the user aborts, or otherwise the string that the user - responded with.

  • +
  • If userPromptHandler is "none":

    + +
      +
    1. Pause while waiting for the user's response.

    2. + +
    3. If the user did not abort, set result to the string that the user + responded with.

    4. +
    +
  • + +
  • Otherwise if userPromptHandler is "accept", set result + to the emtpy string.

  • Invoke WebDriver BiDi user prompt closed with this, - false if result is null or true otherwise, and result.

  • + "prompt", false if result is null or true otherwise, + and result.

    -
  • Return result.

  • +
  • Return result.

  • To optionally truncate a simple dialog string s, return either