I have just modify a snippet from this page: https://developer.mozilla.org/en/Code_snippets/Progress_Listeners
But with this code only STATE_START and STATE_STOP were fired. The rest did not fire at all
var target = this;
const STATE_START = Components.interfaces.nsIWebProgressListener.STATE_START;
const STATE_REDIRECTING = Components.interfaces.nsIWebProgressListener.STATE_REDIRECTING;
const STATE_TRANSFERRING = Components.interfaces.nsIWebProgressListener.STATE_TRANSFERRING;
const STATE_NEGOTIATING = Components.interfaces.nsIWebProgressListener.STATE_NEGOTIATING;
const STATE_STOP = Components.interfaces.nsIWebProgressListener.STATE_STOP;
var myListener =
{
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 you use myListener for more than one tab/window, use
// aWebProgress.DOMWindow to obtain the tab/window which triggers the state change
if(aFlag & STATE_START)
{
target.log("start")
// This fires when the load event is initiated
}
if(aFlag & STATE_REDIRECTING)
{
target.log("redirecting");
}
if(aFlag & STATE_TRANSFERRING)
{
target.log("transferring");
}
if(aFlag & STATE_NEGOTIATING)
{
target.log("negotiating");
}
if(aFlag & STATE_STOP)
{
target.log("stop");
// This fires when the load finishes
}
},
onLocationChange: function(aProgress, aRequest, aURI)
{
// This fires when the location bar changes; i.e load event is confirmed
// or when the user switches tabs. If you use myListener for more than one tab/window,
// use aProgress.DOMWindow to obtain the tab/window which triggered the change.
},
// For definitions of the remaining functions see related documentation
onProgressChange: function(aWebProgress, aRequest, curSelf, maxSelf, curTot, maxTot) { },
onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage) { },
onSecurityChange: function(aWebProgress, aRequest, aState) { }
}
gBrowser.addProgressListener(myListener);