Closed Bug 1390813 Opened 2 years ago Closed 2 years ago

port.disconnect() not triggered on window unload

Categories

(WebExtensions :: Compatibility, defect, P3)

defect

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1392067

People

(Reporter: thomas, Unassigned)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36

Steps to reproduce:

- FF56.0b2
- open new browser window with browser.windows.create with moz.extensions URL
- in the new browser window connect to background script with browser.runtime.connect
- in the background script register onDisconnect handler with:
browser.runtime.onConnect.addListener(port => port.onDisconnect.addListener(() => console.log('port.onDisconnect'));
- close new browser window with close button


Actual results:

- onDisconnect listener is not triggered in the background script

Additional incompatibilities to Chrome:
- a beforeunload event handler in the new browser window can't be used to send port messages to the background script (port.postMessage). Also port.disconnect() called at beforeunload will not trigger onDisconnect in the background script.


Expected results:

https://developer.chrome.com/extensions/messaging#port-lifetime
Priority: -- → P3
Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 1223425
port.onDisconnect does work as expected for closing windows.

Your steps-to-reproduce has a syntax error (missing ")") and a logical error (trying to connect before an onConnect listener was registered). If I fix these errors, then the onDisconnect listener is fired when I run your STR:

- FF57.0a1
- open new browser window browser.windows.create with moz.extensions URL
- in the background script register onDisconnect handler with:
browser.runtime.onConnect.addListener(port => port.onDisconnect.addListener(() => console.log('port.onDisconnect')));
- in the new browser window connect to background script with browser.runtime.connect
- close new browser window with close button


I know of two situations where onDisconnect does not fire for an open port.
1. When an extension is uninstalled - in content scripts (bug 1223425).
2. When the content process containing the port crashes.

None of these apply to your scenario. Thomas, can you confirm that the bug report is invalid (or falling in one of the two categories that I mentioned), or provide a STR that shows the bug?
Flags: needinfo?(thomas)
When I ran the steps in comment 2 above, I used the browser console to add listeners.
When I use extension files without console, however, I can reproduce the bug, as seen in bug 1392067.
Flags: needinfo?(thomas)
Duplicate of bug: 1392067
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.