Javascript framework (RightJS) as content-script in a page-mod

877 views Asked by At

I'm new to the jetpack world (and firefox extension for that matter) and while doing some research on the possibility of jetpack, I found something strange. I did a simple test project that included a javascript framework (RightJS) in a pagemod (the tutorial used jQuery and that seemed to works fine) and I got the following error :

error: An exception occurred.
Traceback (most recent call last):
File "/home/nic/Aptgeek/TestProjects/ff-extension/data/external/libs/right-src.js", line 5979, in
File "/home/nic/Aptgeek/TestProjects/ff-extension/data/external/libs/right-src.js", line 990, in
TypeError: Array.include is not a function

My main.js script is fairly simple :

var pageMod = require("page-mod"); 
var self = require("self"); 
exports.main = function() { 
        pageMod.PageMod({ 
                include: "*", 
                contentScriptWhen: 'ready', 
                contentScriptFile: [self.data.url('external/libs/right-src.js'), 
                                    self.data.url('test.js')], 
                onAttach: function onAttach(worker) { 
                        worker.on('message', function(message) { 
                                console.log(message); 
                        }); 
                } 
        }); 
} 

After seeing that discussion : http://groups.google.com/group/mozilla-labs-jetpack/browse_thread/thr..., I began to wonder about the jetpack javascript framework support. Am I using page-mod incorrectly ? Or should that work ? Is there any limitations concerning the use of javascript framework as content-script in a page-mod ?

2

There are 2 answers

0
nicon On BEST ANSWER

Firefox Add-on runs in an environnement where natives type are sandboxed. The way that those natives types were extended in RightJS conflicted with the sandboxed environnement. Some change have been made to RightJS to make it work with Firefox Add-on SDK (JetPack).

0
3demax On

Try using "safe mode" feature from rightjs

http://rightjs.org/tutorials/safe-mode#safe

In this safe-mode, RightJS does not extend anything and does not put its functions and classes into the global scope (except the RightJS object itself).