O'Reilly logo

PhantomJS Cookbook by Rob Friesel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating clipped screenshots from PhantomJS

This recipe introduces the clipRect property on webpage instances, and it describes its role in rendering portions of our web page content. The recipe also illustrates how to set the property dynamically (for example, to capture specific page elements).

Getting ready

To run this recipe, we will need a script that accesses a web page. We need some knowledge of the structure of the target web page so that we can define a selector to use for further targeting specific content on that web page. We also need write permissions to the filesystem in that script's working directory.

The script in this recipe is available in the downloadable code repository as recipe04.js under chapter07. If we run the provided ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required