Last active
September 10, 2015 17:40
-
-
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.
This file contains hidden or 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
| 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); |
Author
rename this to _snippet or _scratchpad
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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