2

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.

sakhunzai
  • 13,900
  • 23
  • 98
  • 159

1 Answers1

2

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

Xan
  • 74,770
  • 16
  • 179
  • 206
  • 1
    This is the method that FireBreath 2 uses – taxilian Nov 06 '17 at 18:28
  • @Xan, do you suggest any resources to get started with ? – sakhunzai Nov 07 '17 at 05:49
  • @sakhunzai It's a problem with multiple unrelated skill sets required and I don't know your general level of knowledge in them. It's hard to recommend anything given this. Which parts do you need help with, and what's your level with them? – Xan Nov 07 '17 at 09:41
  • @Xan please check my related question I tired to use FireBreath as suggested by taxilian my build fails after long shot https://stackoverflow.com/questions/47157225/firebreath-fbtestplugin-build-fails-on-mac-osx-10-10-5 – sakhunzai Nov 07 '17 at 11:50
  • I am currently on Mac OS X so I would like to definitely try to go through all the steps you listed above. The first obvious step is to start with `"Native Host wrapper"` as you suggested. Therefore I am starting with a example project from FireBreath. As far as I know Mac OSx dosen't support `dll`, that is the puzzle point for me – sakhunzai Nov 07 '17 at 11:56
  • My C/C++ skills are rusty if that is what you mean, I ll appreciate any stuff related to steps you listed above,thanks – sakhunzai Nov 07 '17 at 12:01