Book Image

PhantomJS Cookbook

By : Rob Friesel
Book Image

PhantomJS Cookbook

By: Rob Friesel

Overview of this book

Table of Contents (15 chapters)
PhantomJS Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Inspecting the version at runtime


This recipe will introduce the global phantom object in PhantomJS and discuss how we can inspect the version at runtime using the version property.

Getting ready

To run this recipe, we will need a script that accesses phantom.version. The script in this recipe is available in the downloadable code repository as recipe01.js under chapter02. If we run the provided example script, we must change to the root directory for the book's sample code.

How to do it…

Consider the following script:

console.log('PhantomJS');
console.log('  - major version: ' + phantom.version.major);
console.log('  - minor version: ' + phantom.version.minor);
console.log('  - patch version: ' + phantom.version.patch);
phantom.exit();

Given the preceding script, enter the following at the command line:

phantomjs chapter02/recipe01.js

Our output should look like the following:

PhantomJS
  - major version: 1
  - minor version: 9
  - patch version: 2

How it works…

Our script operates by accessing...