PhantomJS 1.6 Release Notes

PhantomJS 1.6, Lavender, was released on June 20, 2012. It is a minor update, mostly bug fixes and some new API.

This version is backward compatible with version 1.5. Existing scripts should work without any modification.

Improved support for rendering

While it is always possible to capture the web page and render it as an image, it involves creating an external file to hold that image. With this version, the captured content can be retrieved as a string, base64-encoded using the new renderBase64(format) function.

The example will dump the base64-encoded rendering of the web page in PNG format (the default if no format is specified) to the terminal:

var page = require('webpage').create();
page.open('http://m.bing.com', function (status) {
    console.log(page.renderBase64());
    phantom.exit();
});

To facilitate creating thumbnail preview, scaling the screen capture is now possible via the new zoomFactor property. In this example, the BBC site is captured to an image at 25% zoom.

var page = require('webpage').create();
page.open('http://news.bbc.co.uk', function (status) {
    page.zoomFactor = 0.25;
    page.render('bbc.png');
    phantom.exit();
});

Better script evaluation

Arguments can be passed to evaluate() function to run a script in the context of the web page.

In the following example, the text value of a DOM element is extracted. The element is chosen based on the selector which is passed to evaluate.

var page = require('webpage').create();
page.open('http://m.bing.com', function (status) {
    var title = page.evaluate(function (s) {
        return document.querySelector(s).innerText;
    }, 'title');
    console.log(title);
    phantom.exit();
});

Evaluating a script asynchronously is now possible via the new evaluateAsync function. Unlike the standard evaluate, the function returns immediately and does not wait until the script execution finishes. Consequently there is no return value from this function.

New features

Improvements

Back to all releases.