OshoParth
OshoParth

Reputation: 1552

importScripts() function not working in Firefox addon code

I am building an add-on that has multiple .js files that are associated with it many of which need the access to the require() function but when i use the require function in them i get the error that require is not defined.used importScripts() to include the require.js file but the import scrips also generates error.

importScripts('resource://gre/modules/workers/require.js');

Also Used

self.importScripts('resource://gre/modules/workers/require.js');

The error generated is

JPM undefined   Message: ReferenceError: importScripts is not defined

And

JPM undefined   Message: ReferenceError: importScripts is not defined

Need help to include multiple files that can have the access to the require() or importScripts() function.

Upvotes: 4

Views: 5001

Answers (2)

Tim Nguyen
Tim Nguyen

Reputation: 1213

Looks like you're using the add-on SDK.

You can't use privileged code with all JS files, that includes require(). You can only use privileged code from your main.js script. Then use a content script/worker to communicate between the main script and the other script.

Upvotes: 1

Noitidart
Noitidart

Reputation: 37228

What about:

let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
               .getService(Ci.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://marionette/content/simpletest.js");

Upvotes: 0

Related Questions