-
Notifications
You must be signed in to change notification settings - Fork 3k
[WebDriver BiDi] enable and disable scripting via BiDi #11441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[WebDriver BiDi] enable and disable scripting via BiDi #11441
Conversation
61b293b
to
dbd6338
Compare
`emulation. setScriptingEnabled` command. Related [HTML PR](whatwg/html#11441) should be landed after this one. * Store the state in `scripting enabled overrides map`. * Provide a hook "WebDriver BiDi scripting is enabled" to be called by HTML's ["Scripting is enabled"](https://html.spec.whatwg.org/multipage/webappapis.html#concept-environment-script) method. * Force scripting enabled for scripts initiated by BiDi protocol user via "bypassDisabledScripting" argument.
263cdc2
to
dc2ae87
Compare
@domenic could you please take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The edit to "scripting is disabled" makes sense, but I suspect the bypass is not thorough enough.
If you look at all the call sites for "scripting is disabled" or "scripting is enabled", the ones that worry me are:
#check-if-we-can-run-script
's check means that the script created inscript.evaluate()
will not actually run. If we ignore that, then the following are still broken:#getting-the-current-value-of-the-event-handler
's dependency means that inside any script run byscript.evaluate()
,element.onxyz === null
.- HostEnqueueFinalizationRegistryCleanupJob's dependency means that weak references created by scripts from
script.evaluate()
will leak forever. - HostEnqueuePromiseJob's dependency means that promise handlers / async functions spawned from
script.evaluate()
will never run.
I'm not sure what a good approach that avoids these problems might be.
Maybe, it'd be best to flip this and try to blocklist all the "bad" sources of script, while leaving scripting enabled???? You could try to censor "create a classic script", "create a JavaScript module script", and "create a WebAssembly module script" by having them use the empty string / empty wasm byte sequence. That might catch them all???
But of course, a blocklist approach is fragile in its own way.
I wonder what implementations do?
@domenic thanks a lot for the detailed analyses!
WebDriver BiDi spec invokes EcmaScript's
I think this is acceptable.
It looks like we can safely remove the "check if we can run script" step from
I assume the "check if we can run script"
I don't think the blocklist addresses the issue with the JavaScript disabling during some script execution.
From the implementation perspective, in Chromium we don't stop processing microtasks queue when the scripting was disabled. In order to address the mentioned concerns I would propose to:
WDYT? |
dc2ae87
to
88b10e4
Compare
It is a little bit scary that you are not using the encapsulation HTML provides. For example, it looks like you are not handling parse errors (stored in "error to rethrow"). Do you really need the full power of going directly to the ECMAScript spec layer?
Really? Is that what implementations do?
The issue is that this might run the web developer-registered handlers for WeakRefs. I don't know if this is a concrete problem, but it is a conceptual one. For example, let's suppose WebDriver BiDi lets you mutably toggle on and off scripting disabled vs. enabled. (I can't tell quickly whether that is true or not, but maybe it is?) Then, JS code could do const someObject = {};
const registry = new FinalizationRegistry(() => {
console.log("foo");
});
registry.register(someObject); while scripting is enabled. Then, WebDriver BiDi makes scripting disabled. Then, GC runs and collects I doubt that is what you want?
Or maybe, that is what you want? If you disable script during a realm's lifetime, you are OK with still running script that was registered in promise handlers and weakref finalizers? Why? Why make exceptions for those constructs, in particular? What about, e.g., normal event listeners? In particular, it seems bad that web APIs that use promises vs. web APIs that use events have completely different behavior when WebDriver BiDi "disables script". |
…stEnqueuePromiseJob` when the scripting is disabled" This reverts commit 88b10e4.
emulation.setScriptingEnabled
.bypassDisabledScripting
to force-run scripts. Required for some automation scenarios like WebDriver BiDi commandscript.evaluate
.emulation.setScriptingEnabled
web-platform-tests/wpt#54289emulation.setScriptingEnabled
command GoogleChromeLabs/chromium-bidi#3566(See WHATWG Working Mode: Changes for more details.)
/infrastructure.html ( diff )
/webappapis.html ( diff )