Phantomjs Tutorial


(this is my learning notes)

console.log("hi there");

save the above code in a file, and run it like this: phantomjs filename.

// create a screenshot of a webpage
var page = require('webpage').create();'', function() {

the following script tests a web page load speed.

// test a webpage loading speed
var page = require('webpage').create();
var system = require('system');
var timeStamp;
var myURL;

if (system.args.length === 1) {
  console.log('Usage: loadspeed.js <some URL>');

timeStamp =;
myURL = system.args[1]; myURL, function(status) {
  if (status !== 'success') {
    console.log('FAIL to load page');
  } else {
    timeStamp = - timeStamp;
    console.log('Loading time ' + timeStamp + ' milisecond');

run it like this phantomjs loadspeed.js

Like what you read? Please tell friends, share link, or Buy JavaScript in Depth. Thanks.
blog comments powered by Disqus