June 27, 2012
Recently, PhantomJS 1.6 has released. PhantomJS has a flower name for each releases, this version has "Lavender". This version is minor update, but it's has some new features in view of the release note, I tried a few points.
You can now pass the variable to the callback function of page.evaluate.
var prefix = 'Title:',
result;
result = page.evaluate(function (p) {
return p + document.title;
}, prefix);
console.log(result);
onConfirm, onPrompt of JavaScript callbacks has been added.
var result;
page.onConfirm = function(msg) {
console.log(msg);
};
result = page.evaluate(function() {
return window.confirm('Hello Confirm!');
});
Cookie data has been supported. Until now was not only pass in the options of the command of PhantomJS, but you can now be specified in the page object.
page.cookies = [{
'name': 'Cookie-Name',
'value': 'Cookie-Value',
'domain': 'localhost'
}];
The 'os' object has been added into system module.
var os = require('system').os;
for (var p in os) {
console.log(p + ': ' + os[p]);
}
The result is like this:
architecture: 32bit
name: mac
version: 10.7 (Lion)
You can now asynchronously evaluation of the page. This is useful if you don't need the results of evaluation.
page.evaluateAsync(function () {
// do something
});
Complete changes to release note since it is written, please check it out.
All contents by Ryuichi Okumura. You can subscribe to the feed of this site. Unless otherwise noted, this site is licensed under a Creative Commons License.