I figured that, because Firefox doesn't have a "onbeforeload" event listener (this is what I've used in Google Chrome), I need to redirect the HTTP requests to certain urls before they load.
This has been driving me crazy for 3 days now. The best I have come up with is this:
Code: Select all
var observe = function(aSubject, aTopic, aData)
{
if(aTopic == "http-on-modify-request") {
try {
var httpChannel = aSubject.QueryInterface(Components.interfaces.nsIHttpChannel);
if(isBadUrl(aSubject.URI.asciiSpec)) {
aSubject.cancel(Components.results.NS_ERROR_NO_CONTENT);
}
}
catch(e) {
}
}
}
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.addObserver(observe, "http-on-modify-request", false);
The problem is, it can only stop the request: it can't redirect it as the target has already been set.
I have looked at similar addons but I am yet to find a solution. I'm pretty sure HTTPS Everywhere must use some kind of redirect of requests before they load but it is too complicated for me to understand how it does it!
This page looks like a useful resource but I don't know how to use any of the code to redirect requests:
https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads
I'd be most grateful if you can offer any piece of help!
Thanks in advance,
Colin