Introduction
As a command-line utility, PhantomJS is ideally situated to handle a variety of test automation tasks; as a web browser, PhantomJS' chief performance bottleneck is the same as every other web browser's: network latency. Taken together, and in light of the mechanisms that it exposes for monitoring network activity, this puts PhantomJS in an excellent position to carry out performance analysis tasks.
We were introduced to these mechanisms earlier in this book. In Chapter 3, Working with webpage Objects, we worked through two recipes: Blocking CSS from downloading and Causing images to fail randomly. These recipes introduced the onResourceRequested
, onResourceReceived
, and onResourceError
callbacks, and they provide the foundation for network monitoring and performance analysis in PhantomJS.
In this chapter, we will learn how to use PhantomJS for just such performance analysis tasks. We will explore topics such as how to generate a HAR file for waterfall analysis, and how to use...