Skip to content

Commit 905b721

Browse files
[WebDriver BiDi] enable and disable scripting via BiDi
* Emulate disabled script via WebDriver BiDi. Required for WebDriver BiDi command [`emulation.setScriptingEnabled`](w3c/webdriver-bidi#946). * Allow `bypassDisabledScripting` to force-run scripts even if the scripting was disabled. Required for some automation scenarios like WebDriver BiDi command [`script.evaluate`](https://www.w3.org/TR/webdriver-bidi/#commands-scriptevaluate). * Moved check "if scripting is disabled" from ["get the current value of the event handler"](https://html.spec.whatwg.org/multipage/webappapis.html#getting-the-current-value-of-the-event-handler) to ["the event handler processing algorithm"](https://html.spec.whatwg.org/multipage/webappapis.html#the-event-handler-processing-algorithm), so the ["get the current value of the event handler"](https://html.spec.whatwg.org/multipage/webappapis.html#getting-the-current-value-of-the-event-handler) and ["event handler IDL attribute"](https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-idl-attributes) will always return the actual handler, but they will not be processed. * Removed the step "Check if we can run script" from ["8.1.6.6.2 HostEnqueueFinalizationRegistryCleanupJob(finalizationRegistry)"](https://html.spec.whatwg.org/multipage/webappapis.html#hostenqueuefinalizationregistrycleanupjob) to prevent memory leak. * Removed the step "Check if we can run script" from ["8.1.6.6.4 HostEnqueuePromiseJob(job, realm)"](https://html.spec.whatwg.org/multipage/webappapis.html#hostenqueuepromisejob) to allow for Promise processing. * Added the step "if [scripting is disabled](#11441 (comment))" to [timer initialisation steps](https://html.spec.whatwg.org/#timer-initialisation-steps) to prevent from scripts running . Observable effects: 1. `on...` IDL properties return functions instead of null even if the scripting is off. 2. `FinalizationRegistry` is triggered even when the JS is turned off. 3. `.then` works even if the scripting is off. 4. `setTimeout` and `setInterval` tasks stop working when the JS is turned off. Tests for effects: web-platform-tests/wpt#55479
1 parent 8aed1e9 commit 905b721

File tree

1 file changed

+64
-26
lines changed

1 file changed

+64
-26
lines changed

source

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4701,6 +4701,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
47014701
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-user-prompt-opened">WebDriver BiDi user prompt opened</dfn></li>
47024702
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-file-dialog-opened">WebDriver BiDi file dialog opened</dfn></li>
47034703
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-emulated-language">WebDriver BiDi emulated language</dfn></li>
4704+
<li><dfn data-x-href="https://w3c.github.io/webdriver-bidi/#webdriver-bidi-scripting-is-enabled">WebDriver BiDi scripting is enabled</dfn></li>
47044705
</ul>
47054706
</dd>
47064707

@@ -116167,6 +116168,9 @@ document.querySelector("button").addEventListener("click", bound);
116167116168
<span data-x="concept-document-window">associated <code>Document</code></span>'s <span>active
116168116169
sandboxing flag set</span> does not have its <span>sandboxed scripts browsing context flag</span>
116169116170
set.</li>
116171+
116172+
<li id="WebDriverBiDiScriptingIsEnabled">The result of <span>WebDriver BiDi scripting is
116173+
enabled</span> with <var>settings</var> is true.</li>
116170116174
</ul>
116171116175
</div>
116172116176

@@ -116180,17 +116184,27 @@ document.querySelector("button").addEventListener("click", bound);
116180116184
<hr>
116181116185

116182116186
<div algorithm>
116183-
<p><dfn data-x="concept-n-script">Scripting is enabled</dfn> for a node <var>node</var> if
116184-
<var>node</var>'s <span>node document</span>'s <span data-x="concept-document-bc">browsing
116185-
context</span> is non-null, and <span data-x="concept-environment-script">scripting is
116186-
enabled</span> for <var>node</var>'s <span>relevant settings object</span>.</p>
116187+
<p><dfn data-x="concept-n-noscript">Scripting is disabled</dfn> for a <span>platform
116188+
object</span> <var>object</var> if any of the following are true:</p>
116189+
116190+
<ul>
116191+
<li><p><span data-x="concept-environment-noscript">Scripting is disabled</span> for
116192+
<var>object</var>'s <span>relevant settings object</span>.</p></li>
116193+
116194+
<li><p>The <var>object</var> implements <code>Node</code>, and <var>object</var>'s <span>node
116195+
document</span>'s <span data-x="concept-document-bc">browsing context</span> is null.</p></li>
116196+
116197+
<li><p>The <var>object</var> implements <code>Window</code> and <var>object</var>'s <span
116198+
data-x="concept-document-window">associated <code>Document</code></span>'s <span
116199+
data-x="concept-document-bc">browsing context</span> is null.</p></li>
116200+
</ul>
116187116201
</div>
116188116202

116189-
<p><dfn data-x="concept-n-noscript">Scripting is disabled</dfn> for a node when scripting is not
116190-
<span data-x="concept-n-script">enabled</span>, i.e., when its <span>node document</span>'s <span
116191-
data-x="concept-document-bc">browsing context</span> is null or when <span
116192-
data-x="concept-environment-noscript">scripting is disabled</span> for its <span>relevant settings
116193-
object</span>.</p>
116203+
<div algorithm>
116204+
<p><dfn data-x="concept-n-script">Scripting is enabled</dfn> for a <span>platform object</span>
116205+
<var>object</var>, when <var>object</var>'s scripting is not <span
116206+
data-x="concept-n-noscript">disabled</span>.</p>
116207+
</div>
116194116208

116195116209
<h5>Secure contexts</h5>
116196116210

@@ -117404,12 +117418,36 @@ document.querySelector("button").addEventListener("click", bound);
117404117418

117405117419
<h5 id="creating-scripts">Creating scripts</h5>
117406117420

117421+
<p>This standard refers to the following concepts defined there:</p>
117422+
117423+
<ul class="brief">
117424+
<li><dfn data-x="webdriver-bidi-command-script-evaluate"
117425+
data-x-href="https://w3c.github.io/webdriver-bidi/#command-script-evaluate">WebDriver BiDi
117426+
command "script.evaluate"</dfn></li>
117427+
</ul>
117428+
117407117429
<div algorithm>
117408117430
<p>To <dfn data-x="creating a classic script">create a classic script</dfn>, given a
117409117431
<span>string</span> <var>source</var>, an <span>environment settings object</span>
117410117432
<var>settings</var>, a <span>URL</span> <var>baseURL</var>, a <span>script fetch options</span>
117411-
<var>options</var>, an optional boolean <var>mutedErrors</var> (default false), and an optional
117412-
<span>URL</span>-or-null <var>sourceURLForWindowScripts</var> (default null):</p>
117433+
<var>options</var>, an optional boolean <var>mutedErrors</var> (default false), an optional
117434+
<span>URL</span>-or-null <var>sourceURLForWindowScripts</var> (default null) and an optional
117435+
boolean <var>bypassDisabledScripting</var> (default false):</p>
117436+
117437+
<p class="note">The <var>bypassDisabledScripting</var> parameter is intended to be used for
117438+
running scripts even if <span data-x="concept-environment-noscript">scripting is disabled</span>.
117439+
This is required for some automation scenarios, e.g. for WebDriver BiDi command <a
117440+
href="https://w3c.github.io/webdriver-bidi/#commands-scriptevaluate">"script.evaluate"</a>.</p>
117441+
117442+
<p class="note">The <var>bypassDisabledScripting</var> parameter is intended to be used for
117443+
running scripts even if scripting is disabled. This is required for some automation scenarios,
117444+
e.g. for <span data-x="webdriver-bidi-command-script-evaluate">WebDriver BiDi command
117445+
"script.evaluate"</span>. When the scripting process (e.g., executing a script via a WebDriver
117446+
BiDi command) is invoked with <var>bypassDisabledScripting</var> set to true, the event loop is
117447+
allowed to run to resolve thenables (from promises) and weakmap finalizations created by that
117448+
script, even if <span data-x="concept-environment-noscript">scripting is disabled</span>. This is
117449+
necessary to ensure the proper functioning of testing scripts, which often rely on asynchronous
117450+
operations.</p>
117413117451

117414117452
<ol>
117415117453
<li>
@@ -117423,7 +117461,8 @@ document.querySelector("button").addEventListener("click", bound);
117423117461
</li>
117424117462

117425117463
<li><p>If <span data-x="concept-environment-noscript">scripting is disabled</span> for
117426-
<var>settings</var>, then set <var>source</var> to the empty string.</p></li>
117464+
<var>settings</var> and <var>bypassDisabledScripting</var> is false, then set <var>source</var>
117465+
to the empty string.</p></li>
117427117466

117428117467
<li><p>Let <var>script</var> be a new <span>classic script</span> that this algorithm will
117429117468
subsequently initialize.</p></li>
@@ -119991,9 +120030,6 @@ dictionary <dfn dictionary>PromiseRejectionEventInit</dfn> : <span>EventInit</sp
119991120030
<var>finalizationRegistry</var>.[[CleanupCallback]].[[Callback]].[[Realm]]'s <span
119992120031
data-x="concept-realm-settings-object">environment settings object</span>.</p></li>
119993120032

119994-
<li><p><span>Check if we can run script</span> with <var>entry</var>. If this returns "do not
119995-
run", then return.</p></li>
119996-
119997120033
<li>
119998120034
<p><span>Prepare to run script</span> with <var>entry</var>.</p>
119999120035

@@ -120075,9 +120111,6 @@ dictionary <dfn dictionary>PromiseRejectionEventInit</dfn> : <span>EventInit</sp
120075120111
<p><span>Queue a microtask</span> to perform the following steps:</p>
120076120112

120077120113
<ol>
120078-
<li><p>If <var>job settings</var> is not null, then <span>check if we can run script</span>
120079-
with <var>job settings</var>. If this returns "do not run" then return.</p></li>
120080-
120081120114
<li>
120082120115
<p>If <var>job settings</var> is not null, then <span>prepare to run script</span> with
120083120116
<var>job settings</var>.</p>
@@ -122441,6 +122474,9 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
122441122474
<code>Event</code> object <var>event</var> is as follows:</p>
122442122475

122443122476
<ol>
122477+
<li><p>If <span data-x="concept-n-noscript">scripting is disabled</span> for
122478+
<var>eventTarget</var>, then return.</p></li>
122479+
122444122480
<li><p>Let <var>callback</var> be the result of <span>getting the current value of the event
122445122481
handler</span> given <var>eventTarget</var> and <var>name</var>.</p></li>
122446122482

@@ -122635,8 +122671,8 @@ typedef <span>OnBeforeUnloadEventHandlerNonNull</span>? <dfn typedef>OnBeforeUnl
122635122671
<var>element</var> be null, and <var>document</var> be <var>eventTarget</var>'s <span
122636122672
data-x="concept-document-window">associated <code>Document</code></span>.</p></li>
122637122673

122638-
<li><p>If <span data-x="concept-n-noscript">scripting is disabled</span> for
122639-
<var>document</var>, then return null.</p></li>
122674+
<li><p>If <var>document</var>'s <span>active sandboxing flag set</span> has its
122675+
<span>sandboxed scripts browsing context flag</span> set, then return null.</p></li>
122640122676

122641122677
<li><p>Let <var>body</var> be the uncompiled script body in <var>eventHandler</var>'s <span
122642122678
data-x="event handler value">value</span>.</p></li>
@@ -124798,14 +124834,19 @@ interface <dfn interface>XMLSerializer</dfn> {
124798124834
data-x="dom-setInterval">setInterval()</code> call.</p>
124799124835
</li>
124800124836

124837+
<li><p>Let <var>settings object</var> be <var>global</var>'s <span>relevant settings
124838+
object</span>.</p></li>
124839+
124840+
<li><p>If <span data-x="concept-environment-noscript">scripting is disabled</span> for
124841+
<var>settings object</var>, then abort these steps.</p></li>
124842+
124801124843
<li><p><span>Record timing info for timer handler</span> given <var>handler</var>,
124802-
<var>global</var>'s <span>relevant settings object</span>, and <var>repeat</var>.</p></li>
124844+
<var>settings object</var>, and <var>repeat</var>.</p></li>
124803124845

124804124846
<li><p>If <var>handler</var> is a <code data-x="idl-Function">Function</code>, then <span
124805124847
data-x="es-invoking-callback-functions">invoke</span> <var>handler</var> given
124806124848
<var>arguments</var> and "<code data-x="">report</code>", and with <i
124807-
data-x="dfn-callback-this-value">callback this value</i> set to <var>thisArg</var>.</p>
124808-
</li>
124849+
data-x="dfn-callback-this-value">callback this value</i> set to <var>thisArg</var>.</p></li>
124809124850

124810124851
<li>
124811124852
<p>Otherwise:</p>
@@ -124841,9 +124882,6 @@ interface <dfn interface>XMLSerializer</dfn> {
124841124882
<var>global</var>, and abort these steps.</p></li>
124842124883
<!-- timer is an enum value. -->
124843124884

124844-
<li><p>Let <var>settings object</var> be <var>global</var>'s <span>relevant settings
124845-
object</span>.</p></li>
124846-
124847124885
<li><p>Let <var>fetch options</var> be the <span>default script fetch
124848124886
options</span>.</p></li>
124849124887

0 commit comments

Comments
 (0)