Skip to content
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

Ability to disable JavaScript for a browsing context #746

Open
OrKoN opened this issue Jul 16, 2024 · 8 comments
Open

Ability to disable JavaScript for a browsing context #746

OrKoN opened this issue Jul 16, 2024 · 8 comments
Labels
enhancement New feature or request module-browsingContext Browsing Context module needs-discussion Issues to be discussed by the working group

Comments

@OrKoN
Copy link
Contributor

OrKoN commented Jul 16, 2024

Chrome allows disabling JavaScript for a specific page: https://pptr.dev/api/puppeteer.page.setjavascriptenabled/

Does it make sense to have this functionality in WebDriver BiDi?

@OrKoN OrKoN added the needs-discussion Issues to be discussed by the working group label Jul 16, 2024
@jgraham
Copy link
Member

jgraham commented Jul 16, 2024

Yes, I think this makes sense. I'm not 100% sure if Gecko can disable it per (top level) navigable, but in any case it would make sense to have a command that either allowed disabling globally or for certain top-level navigables.

@whimboo
Copy link
Contributor

whimboo commented Jul 16, 2024

I'm not 100% sure if Gecko can disable it per (top level) navigable

The BrowsingContext webidl has a allowJavascript flag which would exactly allow us to do that on a per top-level browsing context level.

@whimboo whimboo added enhancement New feature or request module-browsingContext Browsing Context module labels Jul 16, 2024
@shs96c
Copy link

shs96c commented Jul 16, 2024

What should happen when JS is disabled yet a session wants to evaluate some JS? I believe that should still work, but it's best to confirm

@OrKoN
Copy link
Contributor Author

OrKoN commented Jul 16, 2024

@shs96c yeah, that should still work: only the scripts coming from the page should not be executed as if JS is not supported.

@juliandescottes
Copy link
Contributor

The BrowsingContext webidl has a allowJavascript flag which would exactly allow us to do that on a per top-level browsing context level.

For info that's what we use for FF DevTools' "Disable JavaScript" feature

image

@sadym-chromium
Copy link
Contributor

The CDP method is Emulation.setScriptExecutionDisabled.

@css-meeting-bot
Copy link
Member

The Browser Testing and Tools Working Group just discussed Ability to disable JavaScript.

The full IRC log of that discussion <simonstewart> Topic: Ability to disable JavaScript
<simonstewart> github: https://github.com//issues/746
<simonstewart> jgraham: Apparently people want to test without JS enabled. The idea would be to disable JS for a specific top-level traversable, or perhaps navigable (though the former makes more sense than the latter)
<simonstewart> jgraham: Seems to be very easy to implement in Gecko. Is already implemented in CDP.
<simonstewart> jgraham: What should happen if the session wants to evaluate some JS.
<simonstewart> gsnedders: the WebKit answer is that you can't
<simonstewart> jgraham: In gecko, you can execute in a sandbox, but not in content
<gsnedders> s/you can't/you can't I think/
<simonstewart> simonstewart: people will disable JS, and then the next thing they'll do is try to evaluate some JS (either directly or through a library function)
<simonstewart> jgraham: this feature only really makes sense if you can continue to execute other scripts.
<simonstewart> jgraham: without that, every other command you try and execute, everything else would fall apart
<simonstewart> jgraham: allowing scripts in a sandbox would be implementable.
<simonstewart> simonstewart: for interop between selenium and pages under test, people tend to want to operate on the content
<simonstewart> jimevans: the thing about running with JS disabled is that the people who want to run with JS disabled, really don't want JS at all
<simonstewart> jimevans: they want to ensure that the pages under test continue to work without JS at all
<simonstewart> jimevans: you can still do a lot with HTML and CSS, eg. using forms to send data to a backend.
<simonstewart> jgraham: having a command that sets a flag (as shown in the issue) seems like a quick thing to implement. The question about what to do once JS is disabled is a hard one to answer.
<simonstewart> jgraham: implementations may choose to pre-emptively fail the execute script command if JS is disabled, or want to return unsupported command if the browser doesn't support disabling JS

@OrKoN
Copy link
Contributor Author

OrKoN commented Sep 27, 2024

Note that Chrome still allows script evaluation via CDP if JS is disabled for the page and clients like Puppeteer expect this (test).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request module-browsingContext Browsing Context module needs-discussion Issues to be discussed by the working group
Projects
None yet
Development

No branches or pull requests

7 participants