Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 410
OshoParth Avatar asked Dec 06 '25 17:12

OshoParth


1 Answers

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.

like image 81
Tim Nguyen Avatar answered Dec 08 '25 07:12

Tim Nguyen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!