Digital Me

Random contributions to digital noise

Using JavaScript Modules - A Catch

Thursday January 13, 2011 @ 12:44 PM (PST)

I’m sure I saw somewhere an example how to use JavaScript modules in Firefox extensions and I just used that snippet. Anyway, I was recently caught by a conflict between New Tab Jumpstart extension and NetVideoHunter Basically they could not work together and whichever was loaded first was working properly, second loaded wasn’t.

It turns out that conflict was due to both extensions registering modules folder with the same alias modules. Both extensions would thus import their files with a similar uri: Components.utils.import(“resource://modules/some_module.js”);

The reason why this was failing is resource://modules will be registered for the first loaded extension so for one of the extensions some_module.js file will not be found in the registered location (or even worse it will be found but would be completely wrong).

It was simply fixed by changing registration in chrome.manifest to: resource jumpstart content/modules/ and replacing resource://modules to resource://jumpstart in all files.

Now when I look at it it’s completely logical but you do it once, don’t think about it at the time and you forget about it but it comes back to bite you later. All in all, if you plan on using modules in your extension do not register your modules folder with modules alias or similar, use your extension’s alias.

Comments

New comment

required, won't be displayed

optional

Don't type anything here unless you're an evil robot:


And especially don't type anything here:

Basic XHTML (including links) is allowed, just don't try anything fishy. Your comment will be auto-formatted unless you use your own <p> tags for formatting. You're also welcome to use Textile.

Copyright © 2012 Mihailo Lalevic. All rights reserved.
Powered by Thoth.