Search code examples
google-chrome-extensioncrossrider

Listen when extension popup page closes in Crossrider


I need to know when the crossrider's extension closes so I can throw some message in the background. It was easy on the other way around

appAPI.ready(function() {

}

This is what I'm using on popup.html to determine if the extension is opened. So what I need is something like appAPI.close(function() {}) but I can't find it on the Crossrider's doc http://docs.crossrider.com/


Solution

  • So if you want to monitor "popup page close" event, just listen to unload event for popup page.

    window.addEventListener("unload", function() {
        // Your logic here
    }, false);
    

    Please be aware you can't use console.log in the function, since by the time the unload event fires it is already too late. See this post for more details.