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

Blocking CSS from downloading


In this recipe, we will demonstrate how to use the onResourceRequested callback to block files from downloading. Although we can use this technique to block any resource type, we will specifically be blocking CSS here; this can be useful to generate snapshots of how our sites look when the CSS fails.

Getting ready

To run this recipe, we will need a script that loads a web page; that web page must use CSS so that we can block the style sheet resources.

The script in this recipe is available in the downloadable code repository as recipe11.js under chapter03. If we run the provided example script, we must change into the root directory for the book's sample code.

Lastly, the script in this recipe runs against the demo site that is included with the cookbook's sample code repository. To run that demo site, we must have Node.js installed. In a separate terminal, change to the phantomjs-sandbox directory (in the sample code's directory), and start the app with the following...