javascript - Use http-on-modify-request to redirect URL - Firefox Add-on -


I am creating an addon for Firefox which redirects the request to a new URL if the URL I have tried to do this, and it does not work.

If the URL matches my status, then I register a supervisor on http-on-modify-request to act on the URL, I have a new URL

Here's my code:

  var CC = Component category; Var ci = Components.interfaces; Var Cr = Component result; Var newUrl = "https://google.com"; Function isInlacklist (url) {// here will be somemore condition, I am just testing to use youtube.com if (url.indexOf ('youtube.com')! = -1) {true; } return false; } Export.main = function (options, callbacks) {// Create inspector httpRequestObserver = {Observe: function (subject, subject, data) {if (subject == "http-on-modify-request") {var httpChannel = topic .QueryInterface (Ci.nsIHttpChannel); Var uri = httpChannel.URI; Var domainLoc = uri.host; If (isInlacklist (domainLoc) === true) {httpChannel.cancel (Cr.NS_BINDING_ABORTED); Var gBrowser = utils.getMostRecentBrowserWindow () Gbrouzor; Var domWin = channel.notificationCallbacks.getInterface (Ci.nsIDOMWindow); Var browser = gbrouzzer.jetbrowserfordcourt (domWin.top.document); Browser.loadURI (NEWURL); }}}, Register: function () {var observerService = cc ["@ mozilla.org/observer-service;1"].getService(Ci.nsIObserverService); ObserverService.addObserver (this, "http-on-modify-request", incorrect); }, Unregistered: function () {var observerService = cc ["@ mozilla.org/observer-service;1"].getService(Ci.nsIObserverService); Supervisor service Riv Observer (this, "http-on-modify-request"); }}; // Register Supervisor httpRequestObserver.register (); }; Export.onUnload = function (cause) {httpRequestObserver.unregister (); };   

I'm new to Firefox Eden Development, I do not know where I went wrong, please help ...

You can redirect to a channel by calling. This is not possible after opening the channel, but it will work in http-on-modify-request .

Then in your code, you can do something like this:

  cubic meter ("resource: //gre/modules/Services.jsm"); // ... if (condition) {httpChannel.redirectTo (Services.io.newURI ("http://example.org/", tap, tap)); }   

It seems that you are using add-ons SDK. In that case, read on.

Comments

Popular posts from this blog

c# - Textbox not clickable but editable -

Matlab transpose a table vector -

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -