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

Dispatch untrusted "submit" event in "submit" helper on the window instead of the form itself #6361

Closed
whimboo opened this issue Sep 4, 2018 · 7 comments

Comments

@whimboo
Copy link
Contributor

whimboo commented Sep 4, 2018

The HTML spec says the following for untrusted events as created with createEvent():

Most untrusted events will not trigger default actions, with the exception of the click event. This event always triggers the default action, even if the isTrusted attribute is false (this behavior is retained for backward-compatibility). All other untrusted events behave as if the preventDefault() method had been called on that event.

Also the submit event is included here.

Selenium creates and fires such an event for the submit() helper:

https://github.com/SeleniumHQ/selenium/search?q=e.initEvent%28%27submit%27&unscoped_q=e.initEvent%28%27submit%27

From the point of submitting a form it is totally enough to just call:

HTMLFormElement.prototype.submit.call(form)

Note that in Firefox this untrusted event is causing a double submission of the form data! This is about to get fixed, but relies on some external code (eg. Jenkins) to be updated first.

As long as this behavior stays in Selenium we are blocked with improving the WebDriver conformance in geckodriver / Marionette. See bug 1487705.

@whimboo
Copy link
Contributor Author

whimboo commented Sep 4, 2018

Also please note that all other browsers beside Firefox simply ignore this untrusted event, so there will be no change for those at all.

@whimboo
Copy link
Contributor Author

whimboo commented Sep 4, 2018

As I noticed the extra event dispatching might happen because calling submit() directly won't dispatch a submit event. To really don't cause a regression, and I assume users of Selenium might rely on the event, we should simply change the dispatching of the submit event from the form to the window itself. That is because onsubmit is a global event, and as such to be registered on the window.

Once that is clear I will try to create some PRs for different bindings.

@whimboo
Copy link
Contributor Author

whimboo commented Sep 4, 2018

Here the example code: https://codepen.io/anon/pen/BOZjWJ?editors=1010

@whimboo whimboo changed the title Remove firing of non-trusted "submit" event from "submit" Dispatch untrusted "submit" event in "submit" helper on the window instead of the form itself Sep 5, 2018
@whimboo
Copy link
Contributor Author

whimboo commented Sep 5, 2018

As mentioned above removing the submit event dispatching completely is a bad idea. As such it should be emitted on the Window instead of the form element, which will stop the two submissions actually happening.

@whimboo
Copy link
Contributor Author

whimboo commented Sep 6, 2018

Note that the Java fix already landed as bbd0774.

Further I cannot find such code for the node.js binding. As it looks like it only supports submitting the form directly?

@whimboo
Copy link
Contributor Author

whimboo commented Sep 7, 2018

@barancev would you mind to backout the already landed changes for the Java, Python, and Ruby bindings? Thanks.

barancev added a commit that referenced this issue Sep 7, 2018
@whimboo
Copy link
Contributor Author

whimboo commented Sep 7, 2018

It got all reverted: 946b7a2...df28b11

I'm going to close this as invalid. Sorry for the noise.

@whimboo whimboo closed this as completed Sep 7, 2018
grigaman pushed a commit to grigaman/selenium that referenced this issue Sep 20, 2018
grigaman pushed a commit to grigaman/selenium that referenced this issue Sep 20, 2018
grigaman pushed a commit to grigaman/selenium that referenced this issue Sep 20, 2018
@lock lock bot locked and limited conversation to collaborators Aug 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants