In my Firefox extension I want to intercept the url that the browser is requesting and block the request entirely if some condition matches
How can I intercept URL b
An other possible solution :
Here is an other implementation as modules example from HTTPS-Everywhere
Init function :
init: function() {
// start observing all http requests
Services.obs.addObserver(httpNowhere, "http-on-modify-request", false);
},
Observer function :
observe: function(subject, topic, data) {
var request = subject.QueryInterface(Ci.nsIHttpChannel);
if (topic == "http-on-modify-request") {
if (request.URI.spec == "xxx.example.com") {
request.redirectTo("yyy.example.com");
}
else {
request.cancel(Components.results.NS_ERROR_ABORT);
}
}
},
Example addons :
HTTPS-Nowhere - https://github.com/cwilper/http-nowhere
HTTPS-Everywhere - https://github.com/EFForg/https-everywhere
Migrating your extension to chrome :
i answered your question for chrome in this page : Chrome Extension : How to intercept requested urls?