Embedding node.js in a Firefox extension and launching the server in a browser

I am trying to figure out how to embed node.js in a Firefox extension so that I can run a permanent server process (in particular PeerServer ) from within a browser if the user has the extension. The only thing I managed to find on the Internet was this guide ... but I could not get these instructions to work, and you need to find a few more resources.

1) Does anyone have other resources besides the article I related to above about how to embed node.js in Firefox extensions? Any code examples?

2) Is there any reason that it would be impossible to start a permanent server process, such as PeerServer, from the Firefox extension? Are there any restrictions on the extensions that prevent me from doing this?

+7
javascript firefox firefox-addon
source share
1 answer

You can simply have an executable file in your extensionโ€™s folder and have JS code in the extension executable. Running an external executable is described in the resource you linked to or here in MDN .

Example copied from MDN:

var file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsIFile); file.initWithPath("myapp.exe"); var process = Components.classes["@mozilla.org/process/util;1"] .createInstance(Components.interfaces.nsIProcess); process.init(file); var args = ["argument1", "argument2"]; process.run(false, args, args.length); 

It takes a little more logic to find the absolute path of the user profile in order to determine the path to launch the application, but it is doable.

Now, if you want to interact with node with the extension, you can use HTTP requests as a means of communication.

In Firefox, it's a little weird to embed node, although Firefox itself has a JS engine. A more elegant approach would be to try to get PeerJS to work directly in the context of the Firefox add-on without node. It might be harder, but it should be possible. See For example, this browser server addon.

+2
source share

All Articles