PhantomJS: Headless WebKit with JavaScript API

PhantomJS is a headless WebKit with JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.

var page = require('webpage').create();
console.log('The default user agent is ' + page.settings.userAgent);
page.settings.userAgent = 'SpecialAgent';
page.open('http://www.httpuseragent.org', function (status) {
    if (status !== 'success') {
        console.log('Unable to access network');
    } else {
        var ua = page.evaluate(function () {
            return document.getElementById('myagent').innerText;
        });
        console.log(ua);
    }
    phantom.exit();
});

Next to page automation, it also allows screengrabbing. A good use-case (as mentioned by Stephen Hay in his Fronteers ’12 talk) is including screenshots in generated style guides: change the CSS and automagically update the screenshots that go in the style guide by running Phantom

phantomjs rasterize.js http://www.bram.us/ bramus.pdf letter

PhantomJS →

Elsewhere , , , ,

2 Responses to PhantomJS: Headless WebKit with JavaScript API

  1. Pingback: CasperJS: a navigation scripting & testing utility for PhantomJS | Bram.us

  2. Pingback: SlimerJS — A scriptable browser for Web developers | Bram.us

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>