One option is to use nsIWebProgressListener to track the progress of page load events. The onStateChange method onStateChange executed with the STATE_STOP status when the request is completed, even if the user has interrupted the page loading.
Here is a simple example:
const STATE_START = Components.interfaces.nsIWebProgressListener.STATE_START; const STATE_STOP = Components.interfaces.nsIWebProgressListener.STATE_STOP; window.addEventListener("load", function(e) { gBrowser.addProgressListener({ QueryInterface: function(aIID) { if (aIID.equals(Components.interfaces.nsIWebProgressListener) || aIID.equals(Components.interfaces.nsISupportsWeakReference) || aIID.equals(Components.interfaces.nsISupports)) return this; throw Components.results.NS_NOINTERFACE; }, onStateChange: function(aWebProgress, aRequest, aFlag, aStatus) { if (aFlag & STATE_STOP) {
This is an example of a toy, of course. Further reading of some implementation details:
source share