Phantomjs Tutorial

Want to master JavaScript in a month? Commit. Buy Xah JavaScript Tutorial. You also get Xah HTML Tutorial and Xah CSS 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

blog comments powered by Disqus