PhantomJS REPL: it's ready for a taste

  • personal • source • REPL • opensource • phantomjs
  • 305 words

After 2 months of on-off working on this, I finally managed to make something I’m happy with: a REPL for PhantomJS.

The last post I wrote about this was in November 2011 (!!!). But I started putting code together only in Jan 2012. So, overall, from the first commit until today is almost 2 months.

First thing first: how do you get to try it? Well, you can get my fork, switch to the dev-repl branch and try it out:

$ git clone git://
$ cd phantomjs
$ git checkout -b dev-repl origin/dev-repl
$ qmake && make

You can download this tarball. Or you just can come up with your own way to checkout my branch.

To launch it, just type:

$ ./bin/phantomjs

You will be welcomed by a prompt, waiting for your JavaScript code to be evaluated on the spot. Line by line. Like a proper REPL. The ideal companion for your quick-and-dirty phantomjs-hack-sessions or live-coding keynotes.

The REPL is packed with some good features that I’m sure will please command-line junkies:

  • Context-sensitive auto-completions (i.e. push on TAB to cycle through suggestions)
  • Arrow navigation through the history of what you type
  • Permanent history (yes, like any “modern” CLI)
  • Editable command line (use Left and Right to insert characters where you need them)
  • Pretty-print of expression result (great to quickly recall the name of a method)

It’s not part of the latest PhantomJS, but I plan to file a pull request very soon.

Please, help yourself to it and share your view and feedback. I did this work specifically to make PhantomJS users happy: so, help me make you happy :)

Happy REPL-coding!

P.S.: This whole branch would have not made it without the great linenoise library. In the specific case, I’m using this fork because it has more maintenance. Kudos to everyone involved.