The `beforeunload` event is fired to late
Author: skyz1Created Mar 23, 2026Updated Sep 29, 2026
Summary
When a window is closed in ladybird, the beforeunload event is fired to late when compared to Chromium and Firefox.
Operating system
Linux
Steps to reproduce
- Allow popups
- Open the reduced test case
Expected behavior
The JS log should be
beforetoggle
beforeunload
toggleActual behavior
The JS log is
beforetoggle
toggle
beforeunloadURL for a reduced test case
N/A
HTML/SVG/etc. source for a reduced test case
<!doctype html>
<dialog id="dialog"></dialog>
<script>
const logEvent = e => console.log(e.type);
const dialog = document.getElementById("dialog");
dialog.addEventListener("beforetoggle", logEvent);
dialog.addEventListener("toggle", logEvent);
const button = document.createElement("button");
button.command = "show-modal";
button.commandForElement = dialog;
button.click();
const newWindow = window.open("about:blank", "_blank");
newWindow.addEventListener("beforeunload", logEvent);
newWindow.close();
</script>Log output and (if possible) backtrace
1069.648 WebContent(16711): (js log) "beforetoggle"
1069.666 WebContent(16711): (js log) "toggle"
1069.669 WebContent(16711): (js log) "beforeunload"
1069.671 WebContent(16711): TraversableNavigable::destroy_top_level_traversable: No browsing context?
1069.671 WebContent(16711): ConnectionFromClient::set_system_visibility_state: Did not find a page with ID 1
1069.680 Ladybird(16673): WebContentClient::did_paint: Did not find a page with ID 1
1072.667 Ladybird(16673): WebContentClient::did_allocate_backing_stores: Did not find a page with ID 1Screenshots or screen recordings
No response
Build flags or config settings
No response
Contribute a patch?
- I’ll contribute a patch for this myself.
Source: LadybirdBrowser/ladybird