Safari Web Extension - Port Communication via Popup

Hi, I've run into an issue when using runtime ports to communicate between the popup and the background of an extension. Specifically, there seems to be an inconsistency between Chrome and Safari as to when the disconnect event on a port is fired. My expectation is that a disconnect event is fired when the extension popup is closed, but this does not seem to be the case in the Safari browser. The only way I can see this event being fired is to call the port.disconnect() event manually. Is it possible to ensure the disconnect event is called when the popup is closed by any means? 

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/Port

port.onDisconnect.addListener(function() {
  console.log("Extension disconnected");
});

I've also opened a case via the feedback assistant.

Post not yet marked as solved Up vote post of ljs62 Down vote post of ljs62
695 views

Replies

I've just noticed the same behavior. In fact-- instead of getting the disconnect, I'm getting an additional connection request from browser action (even though it's not open). Almost like some phantom instance has been opened.