0

This is my pretty straight forward firefox plugin main.js. I run it and get 'loadContextGoodies is not defined', what is going wrong here?

const {Cc, Ci, Cu, Cr} = require("chrome");
var events = require("sdk/system/events");
var utils = require("sdk/window/utils");
var { MatchPattern } = require("sdk/util/match-pattern");
var pattern = new MatchPattern(/^https?:\/\/example\.com.*/);

function listener(event) {
    var channel = event.subject.QueryInterface(Ci.nsIHttpChannel);
    var url = event.subject.URI.spec;
    if (isToBeRedirected(url)) {
        channel.cancel(Cr.NS_BINDING_ABORTED);
            var goodies = loadContextGoodies(channel);
            var domWin = goodies.aDOMWindow;
            var gBrowser = goodies.gBrowser; 
            var browser = goodies.browser;
            var htmlWindow = goodies.contentWindow;
        browser.loadURI("about:blank");
    }
}

exports.main = function() {
    events.on("http-on-modify-request", listener);
}

function isToBeRedirected(url) {
    return pattern.test(url)
}

edit: I was totally overlooking the part of the source I used for the redirecting bit which contained the declaration of the function. I didnt notice it was a scrollbox.. Thanks for the answer though.

yspreen
  • 1,759
  • 2
  • 20
  • 44
  • This implemention of `loadContextGoodies` is better https://gist.github.com/Noitidart/644494bdc26f996739ef the one linked in solution runs into an error if `gBrowser` is null. And a `loadContext` can have a `DOMWindow` but no `gBrowser`, `browser`, or `tab`. This is true for popup windows. – Blagoh Jul 22 '14 at 16:23

1 Answers1

3

According to that answer : https://stackoverflow.com/a/22429478/1170900

You need to declare loadContextGoodies

Community
  • 1
  • 1
dievardump
  • 2,484
  • 17
  • 21