Creating low level JavaScript API extensions for Firefox

I need to create a low level addon for FireFox, one that is accessible from a loaded page via JS code in the page, but is a Native extension to the browser.

As I understand it, NPAPI is now no longer an option, and the PPAPI (Google) will be deprecated next year in 2021.

The extension I’m tasked with cannot be provided by a browser extension like the ones in the mozilla store as it needs to provide additional API’s that will be called from JavaScript code running in loaded pages, not under the control of myself, but all confirming to the same standard API calls.

I’ve been trying a few proof of concepts using CEF (Embedded chromium) and have hit too many road blocks, so now I’m exploring a solution that will use Embedded Gecko and/or extensions to a running version of firefox.

I’ve read a lot of the MDN content, but this either discusses HTML level topics (Which are of no use) or NPAPI (Which is now deprecated)

Can you provide any pointers as to which technologies I should be exploring in order to accomplish my goal.

For reference, the extensions I’ve been tasked with are to implement the OIPF HbbTV specifications into a standard browser to aid other developers in testing and developing standard HbbTV applications.

Many thanks in advance.

PS: Sorry about the title, I had to find a way to shorten it due to the text box length restriction :slight_smile:

You can expose APIs that page scripts can use from extensions. You can not provide APIs to workers however.
See

Hi Martin, thanks for that, but the API’s & techniques in there are of no use.

What I’m trying to do I don’t believe can be done in a “Web Extension”.

For example, one of the main API’s I’m trying to implement is the “oipfObjectFactory()”

This has several methods on it, such as these 2:

A smart TV Application when loaded into the browser for example will typically do something like, checking to see if “window.oipfObjectFactory” exists, if the object is missing, then it will usually assume it’s not running on a smart TV.

If the object is not missing, it will then typically do something like call “oipfObjectFactory.isObjectSupported(‘video/broadcast’)”, which returns a true/false, and if true will call “oipfObjectFactory.createVideoBroadcast()” which typically would then return an “HTMLObjectElement” class that the application can then inject into it’s dom.

From everything I’ve read so far, this kind of operation is not available from regular web-extensions.

On top of that, in the case of the “video/broadcast” object, it is one of the “visual” objects, that will actually need to grab frames from a video tuner device in the system, and render those frames in it’s tag, this frame grabbing and device access will have to be performed in C/C++ or another compiled language, that the JS object can then access from within the loaded html application.

If I’m reading the link you provided wrong, then please do correct me, but it looks to me like those JS API’s cannot perform the kind of work I need them to do.

So exposing an API like the one you describe is definitely possible. But as you mentioned yourself, piping the video data through without falling back to standard web technologies like a video stream that you somehow generate in a native part of your solution (you would certainly need a native part to accompany the extension, likely including interactions via native messaging), is the hard part.

Thanks, I’ll go back and have another read, and a read of the new link.

Is their any sample code anywhere from other plugins/extensions that your aware of, that I might be able to study?

There are many sample extensions, and MDN will often link to some, however I’m not aware of one that would cover exactly the problems you’d have to solve. Especially since all samples with native interactions are kept pretty simple.

Thanks Martin, all things to read.

I’m currently experimenting with GeckoFX in a C# app, with a handwritten Polyfill loaded in front of every navigation the embedded browser makes :slight_smile: