Skip to content

onbeforeunload return value handling is broken #2297

@bzbarsky

Description

@bzbarsky

https://html.spec.whatwg.org/multipage/webappapis.html#the-event-handler-processing-algorithm step 4 says:

If the event type is beforeunload
...
If the return value is null, then cancel the event.

which means that this testcase:

onbeforeunload = function() {};

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:

onbeforeunload = function() {
  return "";
}

(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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions