Created
January 19, 2010 13:20
-
-
Save rpl/280925 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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