Question

Chrome and Firefox have announced that they will be dropping support for NPAPI plugins soon.

See http://techcrunch.com/2013/09/23/say-goodbye-to-npapi/

For Chrome, I have a couple of options like moving to Native Client (NaCl) if I want to execute some C++ code from JavaScript.

But what are my options in Firefox?

So basically, I have a Firefox add-on built using the Add-on SDK and I want to invoke some C++ code from the add-on content script (JavaScript). I was using NPAPI before but now I want to move to something that is going to be supported more longer term.

Thanks in advance.

Was it helpful?

Solution

Installing an NPAPI plugin just to "invoke some C++ code" is actually not a good thing. NPAPI plugins will be available to all websites, not just your add-on... Did you make sure that the stuff won't break if random websites access it in ways you didn't expect?

Anyway, there are different mechanisms for running binaries code in Firefox today:

  1. js-ctypes is the least painful and recommended way. Basically, you would define a C API/ABI that you can import into and interact with in Javascript.
  2. XPCOM binary components. Basically the whole Firefox backend is written or glued together using binary XPCOM components. It is possible to implement them in add-ons as well, although it is a pretty steep learning curve to get started and the documentation is scattered around many places and pretty much "incomplete". Another huge drawback is that you need to recompile and re-test your modules for each new Firefox version (not the case with js-ctypes).

Using the Add-on SDK will complicate matters further, but you should be used to that already since you're using NPAPI plugins right now.

I'd recommend that you first determine if you really need binaries in your add-on, or if a JS implementation (with modern features, such as typed arrays, and maybe even asm.js via emscripten) and HTML5 (canvas, audio/video) would do as well. And if not, if at least light-weight js-ctypes would do.

Furthermore, NPAPI plugins in Firefox are not going away just now. For the time being they will be available, but a user will have to enable them (Click-to-play). Add-ons could probably work around this, enabling them as needed, for now. So there is no need to rush things.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top