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

Managing cookies with the phantom object

In this recipe, we will discuss how to work with cookies in PhantomJS. The phantom object exposes two properties (cookies and cookiesEnabled) and three methods (addCookie, clearCookie, and deleteCookie) that we can use to inspect and manipulate cookies at runtime.

Getting ready

To run this recipe, we may wish to run PhantomJS with persistent cookies using the cookies-file command-line argument.

The script in this recipe is available in the downloadable code repository as recipe02.js under chapter02. If we run the provided example script, we must change to 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 ...

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