Monthly Archives: February 2009

Turning Firefox into a screenshot server with MozRepl

In October I introduced custom interactors and someone asked what can be done with them other than application inspection.

Here‘s a practical application that turns Firefox into a screenshot server. It lets you request e.g. http://localhost:4242/screenshot/ and receive a PNG screenshot of Wikipedia homepage. (Instructions to run it are at the bottom.)

Features and things to note:

  • Every page is loaded in a new tab, meaning that multiple screenshots can be requested concurrently.
  • You can have MozRepl listen to outside requests and thus have the server run on a machine (or machines) other than the one requesting screenshots.
  • Adding .../pdf/, .../postscript/, .../getmail/, and so on, shouldn’t be too hard.

This is no finished product but it should give a hint of the possibilities. Known issues: since it takes the screenshot upon DOM load event, pages that use the same event to build sizeable portions of the document (such as iGoogle) might turn out incomplete or just white. Also, Firefox 3.1 seems to hang when the same browser instance is both the requester and the receiver of the screenshot (ok, not the most useful scenario, but still).

To try it:

  1. Get MozRepl, whether devel or stable branch doesn’t matter.
  2. Copy the source of the screenshot server to a file (e.g. /home/foo/mozrepl-init.js)
  3. In about:config, set extensions.mozrepl.initUrl to the URL of that file, e.g. file:///home/foo/mozrepl-init.js. (This file gets read whenever a new MozRepl session is started.)
  4. In about:config, also set extensions.mozrepl.defaultInteractor to “screenshot”.
  5. Select Tools → MozRepl → Start from the menu to start MozRepl.
  6. Point wget (or curl, or another browser) to Firefox with:
     $ wget http://localhost:4242/screenshot/ 

Update 2009-06-16: Adam has an HTML-to-PNG server with an improved version of the interactor.