Skip to content

Instantly share code, notes, and snippets.

@rpl
Created January 19, 2010 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpl/280925 to your computer and use it in GitHub Desktop.
Save rpl/280925 to your computer and use it in GitHub Desktop.
const Ci = Components.interfaces;
const Cr = Components.results;
const STATE_START = Ci.nsIWebProgressListener.STATE_START;
const STATE_STOP = Ci.nsIWebProgressListener.STATE_STOP;
var myScreenshotListener =
{
QueryInterface: function(aIID) {
if (aIID.equals(Ci.nsIWebProgressListener) ||
aIID.equals(Ci.nsISupportsWeakReference) ||
aIID.equals(Ci.nsISupports))
return this;
throw Cr.NS_NOINTERFACE;
},
onStateChange: function(aWebProgress, aRequest, aFlag, aStatus) {
if(aFlag & STATE_STOP) {
Application.console.log("Request Name: "+ aRequest.name);
var reqname = aRequest.name
var isOk = false;
try {
chan = aRequest.QueryInterface(Ci.nsIHttpChannel);
Application.console.log("STOP with STATUS: "+chan.responseStatus);
if(chan.responseStatus === 200)
isOk = true;
} catch (e) {
Application.console.log("request is not a HTTP channel");
}
if(/^http/.test(reqname) && isOk)
Application.console.log("Screenshot NOW!!!");
}
},
onLocationChange: function(aProgress, aRequest, aURI) {},
onProgressChange: function(aWebProgress, aRequest, curSelf, maxSelf, curTot, maxTot) { },
onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage) { },
onSecurityChange: function(aWebProgress, aRequest, aState) { }
}
window.addEventListener("load", function(ev) {
gBrowser.addProgressListener(myScreenshotListener,
Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
},false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment