Search code examples
javascriptxmlhttprequestfirefox-addondom-events

Send out XMLHttpRequest on closing Firefox


I have a problem. I would like to send out an XML HTTP Request (XHR) from my Firefox extension so that my server will know when Firefox has been closed.

Now the problems I found are these:

onunload: the xmlhttprequest is aborted when Firefox is closed, preventing it from receiving any request

onbeforeunload: it seems to only be initiated when Firefox is restarted, and not closed!

onclose: the same problem as onunload.

So what should I do?


Solution

  • Like Neil said, a synchronous XHR request would allow the request to complete fully. However if you plan to publish your addon to official Mozilla repository, synchronous XHR requests are grounds for rejection (source).

    You may also want to check out some of the Observer Notification, specifically the ones dealing with application shutdown. Also, if you're trying to develop a model of the browser, you may like the user-interaction-inactive observer notification as well. ;)