简体   繁体   中英

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

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 ?

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).

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM