Skip to content

Instantly share code, notes, and snippets.

@Noitidart
Last active September 10, 2015 17:40
Show Gist options
  • Select an option

  • Save Noitidart/9225527 to your computer and use it in GitHub Desktop.

Select an option

Save Noitidart/9225527 to your computer and use it in GitHub Desktop.
_ff-addon-snippet-RedirectChannel: This snippet uses observer service and http-on-modify-request to listen to if google.com is loaded and it redirects to bing.com. A Firefox addon snippet that must be run from privelaged scope.
Cu.import('resource://gre/modules/Services.jsm');
var httpRequestObserver =
{
observe: function(subject, topic, data)
{
var httpChannel, requestURL;
if (topic == 'http-on-modify-request') {
httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
requestURL = httpChannel.URI.spec;
if (/google\.com/.test(requestURL)) {
httpChannel.redirectTo(Services.io.newURI('http://www.bing.com/', undefined, undefined)); //redirectTo requires at least Firefox 20
}
return;
}
}
};
Services.obs.addObserver(httpRequestObserver, 'http-on-modify-request', false);
//Services.obs.removeObserver(httpRequestObserver, "http-on-modify-request", false);
@Noitidart
Copy link
Copy Markdown
Author

README

Rev1

This method requires minimum Firefox version of 20

Rev2

I have not created this yet but I'm thinking of a version that works even below Firefox 20, we can cancel the current channel (httpChannel.cancel(Cr.NS_BINDING_ABORTED);) and/or replace it with another channel.

Rev3

  • Renamed file name to snippet from demo

@yajd
Copy link
Copy Markdown

yajd commented Feb 28, 2014

rename this to _snippet or _scratchpad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment