Awesome FOSS Logo
Discover awesome open source software
Launched 🚀🧑‍🚀

Small fix to the R2D2B2G extension

Categories

I recently ran into a problem with (I thought) mozRepl, which turned out to be a problem with a completely unrelated extension, r2d2b2g that was on my system.

So, for some reason, mozRepl wasn’t working and I couldn’t telnet into it (`telnet localhost 4242` should be all it takes). I was wondering why that could possibly be, stopping it, restarting, restarting firefox, trying again.

After I couldn’t figure out what I was doing wrong, I figured it might be Firefox that was going wrong, so I started firefox from a shell, and watched the output. Was pleased that the output I usually find annoying/useless was actually serving it’s perfectly, allowing me to get to the root of the problem, the errors posed by r2d2b2g:

console.error: r2d2b2g: 
  Message: TypeError: gcli.addCommand is not a function
  Stack:
    addCommand@resource://r2d2b2g-at-mozilla-dot-org/gcli/lib/gcli.js:19:3
@resource://r2d2b2g-at-mozilla-dot-org/r2d2b2g/lib/main.js:163:1
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
run@resource://gre/modules/commonjs/sdk/addon/runner.js:138:19
startup/</<@resource://gre/modules/commonjs/sdk/addon/runner.js:81:7
Handler.prototype.process@resource://gre/modules/Promise-backend.js:865:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:744:7

*************************
A coding exception was thrown in a Promise resolution callback.
See https://developer.mozilla.org/Mozilla/JavaScript_code_modules/Promise.jsm/Promise

Full message: TypeError: gcli.addCommand is not a function
Full stack: addCommand@resource://r2d2b2g-at-mozilla-dot-org/gcli/lib/gcli.js:19:3
@resource://r2d2b2g-at-mozilla-dot-org/r2d2b2g/lib/main.js:163:1
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
run@resource://gre/modules/commonjs/sdk/addon/runner.js:138:19
startup/</<@resource://gre/modules/commonjs/sdk/addon/runner.js:81:7
Handler.prototype.process@resource://gre/modules/Promise-backend.js:865:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:744:7

*************************
console.error: r2d2b2g: 
  Message: TypeError: gcli.addCommand is not a function
  Stack:
    addCommand@resource://r2d2b2g-at-mozilla-dot-org/gcli/lib/gcli.js:19:3
@resource://r2d2b2g-at-mozilla-dot-org/r2d2b2g/lib/main.js:163:1
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
run@resource://gre/modules/commonjs/sdk/addon/runner.js:138:19
startup/</<@resource://gre/modules/commonjs/sdk/addon/runner.js:81:7
Handler.prototype.process@resource://gre/modules/Promise-backend.js:865:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:744:7

When I saw that combination of errors, I thought that mabye that error (while in an unrelated extension) was bringing down mozRepl. While Firefox probably shouldn’t be letting failures in one extension affect another, I don’t know that I’m ready to open that can of worms just yet.

After a little searching around (`cd ~/.mozilla && find . -name “gcli.js”`), I found the offending file:

~/.mozilla/firefox/.default/extensions/r2d2b2g@mozilla.org/resources/gcli/lib/gcli.js

'use strict';

const { Cu } = require('chrome');
const { when: unload } = require('unload');

try {
  // Starting with FF 23, gcli.jsm moved to another location
  Cu.import("resource://gre/modules/devtools/gcli.jsm");
} catch(e) {
  try {
    Cu.import("resource:///modules/devtools/gcli.jsm");
  } catch(e) {
    console.error("Unable to load gcli.jsm");
  }
}

function addCommand(cmd) {
  let name = cmd.name;
  //gcli.addCommand(cmd);
  gcli.commands.add(cmd);
  //unload(gcli.removeCommand.bind(gcli, name));
  unload(gcli.commands.remove.bind(gcli, name));
}
exports.addCommand = addCommand;
exports.removeCommand = gcli.removeCommand;

The offending lines are commented out, and the lines I added (based on a quick internet search for the change to that interface) are below their respective lines, and working properly.

Just wanted to post this in case anyone else runs into it… I am running Firefox 34.0 and from what I know, the latest version of the FirefoxOS simulator and all other add-ons.