Using the same file in add-in and content

I have a script that I want to use on both sides, with an add-in and content. The problem is that the content and add scripts are in different folders (data and lib respectively).

How can I access script data from lib or vice versa?

+4
source share
2 answers

This is almost the same question asked in How to reference a JavaScript file in Lib from an HTML file in Data? so I just rephrase the answer I gave there.

Put the file in the /lib/ folder, then get the resouce url with:

 var url=require("sdk/self").data.url("../lib/shared-file.js"); 

Once you have this URL, you can attach it to a tab or popup menu using the contentScriptFile parameter.

Note. You will need to check what environment you are currently in to determine if you need to add links to the exports object to make them accessible from the addon.

 if(typeof(exports)!="undefined"){ exports.something=function(){...}; } 
+3
source

What you ask is most likely impossible. Even so, given the careful separation of the add-on and the content code, it will require downloading ugly hacks.

But depending on what your code is doing (number crunching?), Perhaps you could use Workers.

0
source

Source: https://habr.com/ru/post/1494660/


All Articles