I\'ve already tried window.unload, window.beforeunload, etc. I\'m looking for a way to notify my background page once the popup is closed.
There is currently no way to figure out when the browser action popup was
closed as window.unonload
is triggered immediately when the popup finished
loading, not when it's closed. There is a bug crbug.com/31262 for this.
Three work arounds available are well described here. They include the port.onDisconnect
trick and periodically polling chrome.extension.getViews()
from either the popup or a background page.
Probably a hacky way, but in the popup page you can listen to
window.onblur = function(){}
and send a message to active tab.
Finally found the solution. Put below code in background.js
/eventPage.js
:
chrome.windows.onFocusChanged.addListener(function(window) {
//handle close event
});
You can try this. Connect to your background page with chrome.runtime.connect (or chrome.extension.connect
before Chrome 26) and port.onDisconnect
will be fired in your background page when the popup is closed.