tags:

views:

1016

answers:

4

I had an idea for a client-side language other than JavaScript, and I'd like to look into developing a Firefox plugin that would treat includes of this new language in a page, like <script type="newscript" src="path/script.ns" />, just as if it were a natively supported language. The plugin would do all of the language parsing and ideally be able to perform every operation on the browser and the html and css within the web page just as JavaScript can.

I've done a bunch of Googling and have found some articles on writing basic Firefox plugins, but nothing as complicated as this.

Is this even possible?

A: 

Do you really want to tie your pages to your own custom scripting language? Or are you just looking to write your client-side code in something that's not javascript? If the latter try MileScript, haXe, or Google Web Toolkit

rpetrich
This is more of a theoretical project. A "can it be done?", "ok, let's do it" kind of thing. I'm not looking to develop anything that's supposed to put food on the table in a language you need a plugin to render.
wbowers
Ah, cool idea then :) It might be a good project to learn the Plugin API and XPCOM
rpetrich
+2  A: 

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:

Nathan de Vries
Fantastic! I don't want to go through JavaScript at all, but I do want to be able to manipulate the DOM. For things like alert boxes, once again, I'd want to go straight to Firefox and whatever API they provide for stuff like that.
wbowers
+2  A: 

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.

Daniel Spiewak
This is a helpful insight and a good option for this project.
wbowers
+2  A: 

@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.

Nickolay