0

I have a backend software that needs to be able to communicate with a gecko-based web browser (and vice-versa). What is the best way to realize this? Since HTTP is rather one-way (with the exception of e.g. reverse AJAX which I consider to be quite "hacky") I am wondering how to do this.

Would creating an NPAPI-based plugin be an option? Based on the data exchanged between the browser and backend, the browser needs to manipulate the DOM of a webpage. The manipulations need to be quite dynamic and communication speed is an important requirement.

I am glad for any help pointing me in the right direction or providing useful resources that might be worth reading!

Simon
  • 1,643
  • 2
  • 17
  • 23
  • Why do you consider AJAX hacky? It really is the industry standard solution for this and is a quite mature technology. – Ben Lee Nov 05 '10 at 21:52
  • Sorry, I didn't mean AJAX itself being hacky. You are right, AJAX itself is mature and impressive! I rather think solutions such as Comet or long polling as being a hack to create "duplex" communication over HTTP. – Simon Nov 05 '10 at 22:44

1 Answers1

1

Writing browser plugins isn't quite trivial, if you can use alternatives like WebSockets (or their emulations like web-socket-js, see here and here for more details).

Only if such alternatives don't give you enough control because of special requirements should you consider writing a browser plugin.
With it you would get the full benefits of native code (high control over whatever API you choose) but also the problems that come with it:

  • you have to start to worry about privileges
  • bugs can crash the whole browser
  • you might have to handle behavioral differences between platforms and browsers
  • you have to worry about distribution on multiple platforms
  • ...

If you need the higher level of control for some reason you could

  • implement the connection handling of your choice in the plugin
  • let the JavaScript initiate connections and send data
  • let the JavaScript register handlers for incoming data etc.
  • on incoming data call those handlers and pass them the data

To get started with NPAPI plugins see here, to support IE too you'd have to write a content extension. Finally i would advise to take a look at FireBreath that already does much of the heavy lifting for you (hides the different APIs for IE and NPAPI, gives you a higher level API, fixes for browser bugs included, ...).

Community
  • 1
  • 1
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236