Using third-party JavaScript libraries

JavaScript libraries are widely available and can make our coding much easier rather than starting from nothing. PhantomJS supports standard JavaScript, and making use of these libraries is supported. There are two ways to inject external JavaScript into PhantomJS: by using either the phantom object or the webpage module.

When external JavaScript is loaded within the phantom object, we can access the external script within our script globally. When JavaScript is injected within the webpage object, we can use these libraries with the page document to manipulate or extract data from the loaded page. Regardless of the loading method, the use of these scripts is dependent on how well they are coded and their purpose. ...

Get Getting Started with PhantomJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.