Writing a Firefox plugin for parsing a custom client-side language

If I've understood what you'd like to do, you'll need to write a Gecko plugin. Via a plugin, you will be able to register your own MIME type and then manipulate Javascript & the DOM.

This means you would need to include an <object /> or <embed /> tag on the page to load your plugin, but you could then look for <script type="application/x-yourtype" />, grab the innerText of that script tag and parse it using your plugin.

As Nickolay has suggested, the alternative is to use whatever the browser currently supports or create a custom build of the browser. Daniel Spiewak's suggestion to use a Java applet (or a Flash applet would also work) is also valid.

The information you're after is available on Mozilla's developer website:

  • Gecko Plugin API Reference
  • Plug-in Basics

An interesting idea. Note that you don't actually need to write a browser-specific plugin to do this. Some people have experimented with using JRuby in an Applet to execute code embedded within <script type="text/ruby">. Such a solution may be slower on startup (due to the overhead of loading an entire JVM instance), but it will be much more flexible in the long run (cross-browser). Besides, it's a bit easier to build a custom language interpreter in a JVM language than it is to try to shoe-horn it into Gecko.


@Nathan de Vries: no, actually, NPAPI plugins you suggested don't let one implement support for <script type=...>.

OP: this is not easy, but look for PyDOM and PyXPCOM - language bindings for Python. The former does exactly what you asked for - for Python, but I'm unsure about its current status. In any case, it's very likely that you need to create your own build of Firefox to support additional script types.

Tags:

Firefox