What I finally implemented, in case it can be of some interest to other people...
var { Cc, Ci, Cr } = require('chrome'),
regex = '/example|example2/gi';
var ApplyBlocking = {
observe: function(subject, topic) {
if (topic === 'http-on-modify-request') {
var channel = subject.QueryInterface(Ci.nsIHttpChannel);
if ( channel.originalURI.spec.match('example.com/') && channel.originalURI.spec.split('://').pop().match(regex) ) {
channel.cancel(Cr.NS_BINDING_ABORTED);
}
}
},
get observerService() {
return Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService);
},
register: function() {
this.observerService.addObserver(this, 'http-on-modify-request', false);
},
unregister: function() {
this.observerService.removeObserver(this, 'http-on-modify-request');
}
};
// Block
function blockTracking(a) {
if(a) {
try { ApplyBlocking.register(); } catch(e) {}
} else {
try { ApplyBlocking.unregister(); } catch(e) {}
}
}