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
onbeforeunload return value handling is broken #2297
Comments
@bzbarsky Hey I'd like to contribute. Can you please guide me? |
That should probably be a question for someone who actually edits the HTML spec, not me. I just report bugs in it... @zcorpan you added the "good first bug" tag, so want to do the guiding? |
And just to be clear, this could use actual useful tests, not just the little bit in html/webappapis/scripting/events/event-handler-processing-algorithm.html... |
@bzbarsky I need to change the return value of both functions and test it according to Web Platform Tests description. Am I right ? |
You need to test what browsers actually do, then change the spec to reflect it, then change the tests to test the spec... |
My understanding from the OP was that the fix for the standard would be to change
to
But it seems this needs more investigation, so I'll remove the label again. @anu0012 you're still welcome to work on this of course! You can ask in https://wiki.whatwg.org/wiki/IRC for help. |
To be clear, I believe that is in fact the correct fix for the standard, and I have done some basic testing in some browsers, but I don't 100% remember whether I tested an explicit null return (as opposed to undefined, say) in Edge and whatnot. |
I found another interesting spec mismatch, which is that both Gecko and Blink do not allow |
There are two particular fixes: - null should *not* cancel the event; this was flipped - CustomEvents with type "beforeunload" should not get this special behavior (especially since they could be non-cancelable) This also modernizes the surrounding section, style-wise. Fixes #2297.
Right, see the "and also if the event is an actual BeforeUnloadEvent, for what it's worth" bit in the original issue description... |
There are two particular fixes: * null should *not* cancel the event. This has been flipped ever since it was introduced in 7612afe. It appears the mistake occurred between https://www.w3.org/Bugs/Public/show_bug.cgi?id=19713#c11 (includes "not") and https://www.w3.org/Bugs/Public/show_bug.cgi?id=19713#c12 (which elides it). * Only applies the special behavior to BeforeUnloadEvents, not to any Event with the name "beforeunload". This is especially important since such events could be non-cancelable, in which case the previous text could potentially cancel them anyway. This also modernizes the surrounding section, style-wise. Fixes #2297.
There are two particular fixes: * null should *not* cancel the event. This has been flipped ever since it was introduced in 7612afe. It appears the mistake occurred between https://www.w3.org/Bugs/Public/show_bug.cgi?id=19713#c11 (includes "not") and https://www.w3.org/Bugs/Public/show_bug.cgi?id=19713#c12 (which elides it). * Only applies the special behavior to BeforeUnloadEvents, not to any Event with the name "beforeunload". This is especially important since such events could be non-cancelable, in which case the previous text could potentially cancel them anyway. This also modernizes the surrounding section, style-wise. Fixes whatwg#2297.
https://html.spec.whatwg.org/multipage/webappapis.html#the-event-handler-processing-algorithm step 4 says:
which means that this testcase:
should cancel the event, and hence lead to a beforeunload prompt. That's not how browsers actually behave.
The way Gecko behaves, based on code inspection, is that the "cancel the event" steps happen only if the return vaue is NOT null (and also if the event is an actual BeforeUnloadEvent, for what it's worth).
When this is fixed, please fix the html/webappapis/scripting/events/event-handler-processing-algorithm.html test in web platform tests, which was written based on the current spec text and fails in every browser I've tried it in.
I should note, that based on the results of that test and the behavior of browsers on this testcase:
(which leads to a beforeunload prompt in Firefox, Chrome, and Safari) it sounds like the Gecko behavior of only doing special things here for actual BeforeUnloadEvent instances is not so Gecko-specific.
The text was updated successfully, but these errors were encountered: