printingnpapifirefox-addon-webextensions

Porting an NPAPI plugin to WebExtension


I have a NPAPI plugin to integrate a web application with printer. I am looking for some resources on how to port existing NPAPI plugin to new WebExtension standard.

First question is, what are WebExtension limitations so I ll evaluate if it's even possible ?

My current plugin is loaded through:

<embed id="myprinter" type="application/mozilla-printer-scriptable-plugin" width=200 height=200>

Then we can interact with the plugin using methods exposed by the object e.g

myprinter.print(), myprinter.clear(), myprinter.render(imageurl)

And properties

myprinter.status, myprinter.retcode

The plugin interacts with an old version of zebra printer to print a image.

My knowledge of how current NPAPI works internally is also limited as the current extension is written by some other developer.


Solution

  • NPAPI model was a DLL that could be loaded and expose code directly.

    This is no longer possible in WebExtension model. The closest alternative is Native Messaging - instead of loading a DLL the browser starts a Native Host process and relays formatted messages to it through STDIO.

    So in theory, an architecture would be something like this:

    1. You write a Native Host "wrapper", that loads the DLL and calls its methods, and is ready to talk to Chrome using the Native Messaging protocol.

    2. You write an extension with a background page that talks to the Native Host.

    3. You write a content script that injects a myprinter object into the page's namespace with the same exposed methods, and relays the requests to the background page.

    So:

    Page → Injected myprinter → Content script → Background script → Native Host "wrapper" → DLL → Printer