beforeunload event handler not called on extension page in a popup window
Categories
(Thunderbird :: Add-Ons: Extensions API, defect)
Tracking
(thunderbird_esr102 wontfix, thunderbird110 wontfix)
People
(Reporter: aeng.aecreations, Assigned: TbSync)
Details
Attachments
(2 files, 1 obsolete file)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:84.0) Gecko/20100101 Firefox/84.0
Steps to reproduce:
I'm porting my Thunderbird extension to the new MailExtensions API, with parts of the UI borrowed from the Firefox WebExtension version.
My extension has a UI in an extension page that opens in a popup window using messenger.windows.create()
. This extension page has a beforeunload
event handler that does some cleanup (e.g., unloading observers) prior to the popup window being closed, and the code inside the event handler is the same as in the Firefox version.
When the extension is loaded in Thunderbird, I'm noticing that the beforeunload
event is not being invoked at all when the window is closing. But in the Firefox version, the beforeunload
event is invoked as expected.
The source code in question can be found here: https://github.com/aecreations/clippings-tb/blob/be4a3610cce73a4e42415055e3f453d28051fb1f/src/pages/clippingsMgr.js
Line 2142 is where the beforeunload
event handler is defined. Note that it is using jQuery syntax to define the event handler; I tried changing it to use window.addEventListener()
, but that made no difference.
To reproduce the issue, download the latest sources of my add-on from here: https://github.com/aecreations/clippings-tb/tree/branches/6.0, and install it in Thunderbird as a temporary add-on.
This issue is reproducible in Thunderbird 78.6.0 on Windows 10. I'm also able to reproduce the issue on macOS.
It was observed that the beforeunload
event handler is invoked when the window is closed by calling messenger.windows.remove()
- there is no script error, the beforeunload event is fired, and the window closes.
However, the issue is still occurring when the user tries to close the window by clicking the "x" in the window title bar.
Assignee | ||
Comment 2•2 years ago
|
||
Reproduction add-on.
Assignee | ||
Comment 3•2 years ago
|
||
Updated reproducer add-on.
Assignee | ||
Comment 4•1 year ago
|
||
Depends on D167045
Updated•1 year ago
|
Assignee | ||
Comment 5•1 year ago
|
||
Even with this patch onBeforeUnload is only called if there has been some user action in the window, like a click. This matches the behaviour described on MDN:
https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event#security
Assignee | ||
Updated•1 year ago
|
Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/75a97fb193fb
Fix missing onBeforeUnload event. r=darktrojan
Updated•1 year ago
|
Updated•1 year ago
|
Assignee | ||
Updated•11 months ago
|
Description
•