Skip to content

Commit

Permalink
Support automatic user prompt handing in WebDriver BiDi
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
jgraham committed Jun 12, 2024
1 parent b8f0b4b commit bb7b60e
Showing 1 changed file with 66 additions and 32 deletions.
98 changes: 66 additions & 32 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -90720,26 +90720,34 @@ location.href = '#foo';</code></pre>
<p>then:</p>

<ol>
<li><p>Set <var>unloadPromptShown</var> to true.</p></li>

<li><p>Invoke <span>WebDriver BiDi user prompt opened</span> with <var>document</var>'s
<li><p>Let <var>userPromptHandler</var> be the result of
<span>WebDriver BiDi user prompt opened</span> with <var>document</var>'s
<span>relevant global object</span>, "<code data-x="">beforeunload</code>", and "".</p></li>

<li>
<p>Ask the user to confirm that they wish to unload the document, and <span>pause</span>
while waiting for the user's response.</p>
<p>If <var>userPromptHandler</var> is "<code data-x="">none</code>":</p>

<ol>
<li>
<p>Ask the user to confirm that they wish to unload the document, and <span>pause</span>
while waiting for the user's response.</p>

<p class="note">The message shown to the user is not customizable, but instead determined
by the user agent. In particular, the actual value of the <code
data-x="dom-BeforeUnloadEvent-returnValue">returnValue</code> attribute is ignored.</p>
<p class="note">The message shown to the user is not customizable, but instead determined
by the user agent. In particular, the actual value of the <code
data-x="dom-BeforeUnloadEvent-returnValue">returnValue</code> attribute is ignored.</p>
</li>

<li><p>If the user did not confirm the page navigation, set <var>unloadPromptCanceled</var>
to true.</p></li>
</ol>
</li>

<li><p>If the user did not confirm the page navigation, set <var>unloadPromptCanceled</var>
to true.</p></li>
<li><p>If <var>userPromptHandler</var> is "<code data-x="">accept</code>", set
<var>unloadPromptCanceled</var> to false.</p></li>

<li><p>Invoke <span>WebDriver BiDi user prompt closed</span> with <var>document</var>'s
<span>relevant global object</span> and true if <var>unloadPromptCanceled</var> is false or
false otherwise.</p></li>
<span>relevant global object</span>, "<code data-x="">beforeunload</code>", and true
if <var>unloadPromptCanceled</var> is false, or false otherwise.</p></li>
</ol>
</li>

Expand Down Expand Up @@ -102492,16 +102500,20 @@ function sendData(data) {
<li><p>Set <var>message</var> to the result of <span data-x="optionally truncate a simple dialog
string">optionally truncating</span> <var>message</var>.</p></li>

<li><p>Show <var>message</var> to the user, treating U+000A LF as a line break.</p></li>
<li><p>Let <var>userPromptHandler</var> be <span>WebDriver BiDi user prompt opened</span> with
<span>this</span>, "<code data-x="">alert</code>", and <var>message</var>.</p></li>

<li><p>Invoke <span>WebDriver BiDi user prompt opened</span> with <span>this</span>,
"<code data-x="">alert</code>", and <var>message</var>.</p></li>
<li><p>If <var>userPromptHandler</var> is "<code data-x="">none</code>":</p>
<ol>
<li><p>Show <var>message</var> to the user, treating U+000A LF as a line break.</p></li>

<li><p>Optionally, <span>pause</span> while waiting for the user to acknowledge the
message.</p></li>
<li><p>Optionally, <span>pause</span> while waiting for the user to acknowledge the
message.</p></li>
</ol>
</li>

<li><p>Invoke <span>WebDriver BiDi user prompt closed</span> with <span>this</span>
and true.</p></li>
<li><p>Invoke <span>WebDriver BiDi user prompt closed</span> with <span>this</span>,
"<code data-x="">alert</code>", and true.</p></li>
</ol>

<p class="note">This method is defined using two overloads, instead of using an
Expand All @@ -102526,16 +102538,27 @@ function sendData(data) {
<li><p>Show <var>message</var> to the user, treating U+000A LF as a line break, and ask the user
to respond with a positive or negative response.</p></li>

<li><p>Invoke <span>WebDriver BiDi user prompt opened</span> with <span>this</span>,
"<code data-x="">confirm</code>", and <var>message</var>.</p></li>
<li><p>Let <var>userPromptHandler</var> be <span>WebDriver BiDi user prompt opened</span> with
<span>this</span>, "<code data-x="">confirm</code>", and <var>message</var>.</p></li>

<li><p>Let <var>accepted</var> be false.</p></li>

<li><p>If <var>userPromptHandler</var> is "<code data-x="">none</code>":</p>

<ol>
<li><p><span>Pause</span> until the user responds either positively or negatively.</p></li>

<li><p><span>Pause</span> until the user responds either positively or negatively.</p></li>
<li><p>If the user responded positively set <var>accepted</var> to true</p></li>
</ol>
</li>

<li><p>If <var>userPromptHandler</var> is "<code data-x="">accept</code>" set <var>accepted</var> to
true.</p></li>

<li><p>Invoke <span>WebDriver BiDi user prompt closed</span> with <span>this</span>,
and true if the user responded positively or false otherwise.</p></li>
"<code data-x="">confirm</code>", and <var>accepted</var>.</p></li>

<li><p>If the user responded positively, return true; otherwise, the user responded negatively:
return false.</p></li>
<li><p>Return <var>accepted</var>.</p></li>
</ol>

<p>The <dfn method for="Window"><code data-x="dom-prompt">prompt(<var>message</var>,
Expand All @@ -102558,18 +102581,29 @@ function sendData(data) {
to either respond with a string value or abort. The response must be defaulted to the value given
by <var>default</var>.</p></li>

<li><p>Invoke <span>WebDriver BiDi user prompt opened</span> with <span>this</span>,
"<code data-x="">prompt</code>" and <var>message</var>.</p></li>
<li><p>Let <var>userPromptHandler</var> be <span>WebDriver BiDi user prompt opened</span> with
<span>this</span>, "<code data-x="">prompt</code>" and <var>message</var>.</p></li>

<li><p>Let <var>result</var> be null.</p></li>

<li><p><span>Pause</span> while waiting for the user's response.</p></li>
<li><p>If <var>userPromptHandler</var> is "<code data-x="">none</code>":</p>

<li><p>Let <var>result</var> be null if the user aborts, or otherwise the string that the user
responded with.</p></li>
<ol>
<li><p><span>Pause</span> while waiting for the user's response.</p></li>

<li><p>If the user did not abort, set <var>result</var> to the string that the user
responded with.</p></li>
</ol>
</li>

<li><p>Otherwise if <var>userPromptHandler</var> is "<code data-x="">accept</code>", set <var>result</var>
to the emtpy string.</p></li>

<li><p>Invoke <span>WebDriver BiDi user prompt closed</span> with <span>this</span>,
false if <var>result</var> is null or true otherwise, and <var>result</var>.</p></li>
"<code data-x="">prompt</code>", false if <var>result</var> is null or true otherwise,
and <var>result</var>.</p></li>

<li><p>Return <var>result</var>.</li>
<li><p>Return <var>result</var>.</p></li>
</ol>

<p>To <dfn>optionally truncate a simple dialog string</dfn> <var>s</var>, return either
Expand Down

0 comments on commit bb7b60e

Please sign in to comment.