Monthly Archives: October 2008

Metabrowsing! (Or, custom interactors for MozRepl)

First guy: “So how would an object inspector look like in MozRepl?”

(Flashback: MozRepl is an interactive shell for Firefox and other Mozilla apps. You connect to Firefox with telnet or similar, type some JavaScript code, and it gets executed on the fly.)

I patiently explained how a command line inspector would look like. More or less like:

First guy: “Well, and how do you get this in MozRepl?”

I (im)pantietly explained that there was no inspector yet.

First guy: “Why not?”

I (im)patiently…

Second guy, out of nowhere: “Yeah, why not?”

You know that you’re in trouble when even the nicest guy in the place teams up to nag you.

Then I spent some time not to write an inspector, but to make it possible (and easy) for third parties to write new interaction modes for MozRepl, so that the onus of writing the damn inspector would be on the above guys. :) (The best thing you can do with challenges isn’t winning them, it’s turning them upside down.)

However things quickly got fancier while I explored, because the same request/response pattern interactive interpreters are built around is common to a lot of applications. Object inspectors, sure. Even text adventures (“You’re in a dimly-lit browser, surrounded by menacing angled brackets and curly braces”).

But also HTTP.

One custom interactor later, there it was: Firefox understanding HTTP and browsing itself. :)

Where to go from here? Once there’s a halfway decent implementation of HTTP (hint: mine isn’t), you may be able to drive Firefox with XML-RPC, JSON-RPC, REST-style manipulation of resources, and who knows what else. (Oh, yeah, I guess server-side long-timers in the audience will know what-else very well.)

Support is available in the new stand-alone MozRepl package. To try out the http-inspect mode, just go to about:config and set the “extensions.mozrepl.defaultInteractor” pref to “http-inspect”, then point the browser to http://localhost:4242. Documentation on how to write custom interactors is on the wiki.

Credits to Sergi for coming up with the “metabrowsing” title!