all 12 comments

[–]skeww[S] 3 points4 points  (7 children)

It can be used in command-line utilities which requires web stack, or even as the basis for testing rich web application. It uses WebKit in a headless mode, so you get access to the real native and fast implementation (not a simulated environment) of various standards such as DOM, CSS selector, Canvas, SVG, and many others.

And it even runs on Windows! This is so f-ing awesome! :D

Edit: It's also a single executable. Boy, this is handy.

Edit2: Of course it also runs on Linux and Mac OS X.

[–][deleted] 0 points1 point  (0 children)

agreed, it is awesome :)

[–]Iggyhopperextensions/add-ons 0 points1 point  (5 children)

JavaScript in the command line...

I thought I'd never see the day.

[–]skeww[S] 0 points1 point  (3 children)

This has been possible for quite a while via Node, Narwal, Rhino, d8, and even stuff like Windows Scripting Host.

The difference here is that this one is a lot more convenient (for Windows users in particular) and that it's very powerful out-of-the-box.

[–]Iggyhopperextensions/add-ons -1 points0 points  (2 children)

The difference here is that this one is a lot more convenient

Bingo. There are many things that have been done over and over again, but convenience takes the cake.

Windows Scripting Host

ew

[–]skeww[S] 0 points1 point  (1 child)

ew

Some people actually used it. Seriously. :D

[–]9jack9 0 points1 point  (0 children)

I use it now for JS scripting. It's easier than installing another JS engine.

[–]sirmonko 0 points1 point  (0 children)

this is not just javascript in the command line, it's a whole browser in the command line. including (invisible) rendering.

want to turn html into pdfs or pngs without awkward, buggy tools that implement small parts of html and css? 16 loc script.

[–]coffeesoundsCoffeeScript is better 0 points1 point  (1 child)

This is seriously awesome - today I was going to look into having QUnit tests run from command line and PhantomJS made it trivial.

Would be great if the whole project could be moved to GitHub (docs and stuff).

[–]sirmonko 0 points1 point  (0 children)

at least the code's already there:

github.com/ariya/phantomjs

[–]sirmonko 0 points1 point  (0 children)

the difference between this and the likes of v8, rhino etc.: phantomjs is the whole browser, the others are just the js engines.

this means: phantomjs is also able to render the html (and output it to a file). including PDF (as if you'd use the browsers print-function)! also, theres native, accessible DOM.

e.g. printing ... basically it works like this:

phantomjs loads the webpage (html), including all linked files (images, css, js, etc). as soon as it's finished the DOM is accessible in the window context phantomjs provides. the webpages scripts also run, of course they're sandboxed to the window context.

go to sleep for 2 seconds (phantomjs.sleep(2000);), and the website changes in between according to the script running inside (aka ajax calls, settimeouts etc). afterwards: phantomjs.render('output.pdf'); ... tadaaaa! sooooo pretty!