Skip to content

Instantly share code, notes, and snippets.

@jaredhirsch
Last active August 29, 2015 14:22
Show Gist options
  • Save jaredhirsch/192084385deaa414fb40 to your computer and use it in GitHub Desktop.
Save jaredhirsch/192084385deaa414fb40 to your computer and use it in GitHub Desktop.
addons - tricks and weirdness

Just some snippets for now. I'll clean this up into an article later (maybe).

IndexedDB access: nsIIndexedDatabaseManager is dead

https://bugzilla.mozilla.org/show_bug.cgi?id=1019194

the proxy file

  • create a new profile for addon development
  • use the Developer Extension to set a bunch of prefs
  • go into the profile, then into the profile's "extensions" directory.
  • create a file with a name that matches the "em:id" in your install.rdf (the thing that looks like myaddon@some-company). I think you have something analogous in package.json, but this shit is all so confusing, still.
  • inside the file, put the full absolute path to the addon, with a trailing slash.

chrome.manifest: 'content' URLs are tricky

chrome.manifest maps "chrome" URLs to files inside your addon.

  • suppose the path to a file is "myaddon/chrome/libs/foo.js".
  • you specify a line in chrome manifest like this: "content myaddon chrome/libs/"
  • then the chrome URL will be: "chrome://myaddon/content/foo.js".
    • If you forget the 'content' slug, all is lost.
  • good news: you can test this by opening firefox with your (possibly broken) addon installed, then type the chrome URL into the address bar. if it resolves to a file, you're all set. if not, start debugging.

chrome.manifest: 'skin' entries won't run XBL scripts. you have to load XBL CSS as 'content'.

  • not much to say about this, except that it's mentioned somewhere on MDN and it sucks.

XML sucks. I wish I'd had an XBL validator.

I accidentally put the XBL <content> section inside the <implementation> section.

XBL, like all truly great programming environments, fails silently if anything is wrong. Is it a JS error? XML syntax problem? Did the CSS selector fail to attach the XBL binding to the XUL page? Who the fuck knows?!

the addon sdk is super confusing and a very leaky abstraction layer

I was never able to figure out how to construct a chrome URL using tools exposed by the addon sdk.

I wound up losing a week reading about it, then dropped down to "restartless non-overlay non-sdk addon" approach.

YMMV. Using XBL makes everything so weirdly difficult.

How to define a global in addon code (not content scripts), or access that global from the addon debugger:

var {Cc, Ci} = require('chrome');
var winMediator = Cc['@mozilla.org/appshell/window-mediator;1']
                  .getService(Ci.nsIWindowMediator);
var window = winMediator.getMostRecentWindow('navigator:browser');
// now you can set globals on window:
window.LOL = {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment