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 https://www.bram.us/ bramus.pdf letter
Leave a comment