Closed Bug 1687182 Opened 3 years ago Closed 1 year ago

beforeunload event handler not called on extension page in a popup window

Categories

(Thunderbird :: Add-Ons: Extensions API, defect)

defect

Tracking

(thunderbird_esr102 wontfix, thunderbird110 wontfix)

RESOLVED FIXED
111 Branch
Tracking Status
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.

Attached file bug1687182.xpi (obsolete) —

Reproduction add-on.

Attached file bug1687182.xpi

Updated reproducer add-on.

Attachment #9276594 - Attachment is obsolete: true
Assignee: nobody → john
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true

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

Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/75a97fb193fb
Fix missing onBeforeUnload event. r=darktrojan

Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 111 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: