Data, Maps, Usability, and Performance

Viewing and Disabling Cookies in CasperJS and PhantomJS

Last updated on July 23, 2012 in Development

browser cookies

Today, I have once again been messing around with CasperJS and this time around, I wanted to play around with browser cookies. PhantomJS API Reference has a command line option –cookies-file=/path/to/cookies.txt that specifies the file name to store persistent cookies but I want to disable cookies, not store them. I also want to test and see what the cookies are on the page to verify that they have been disabled.

Let’s start with viewing the current cookies, in a normal browser I can just go into the console and check the output of document.cookie. So, with CasperJS, this can be done by using the echo and evaluate functions and returning document.cookie to be printed to the console. Pretty simple. In terms of disabling cookies, you can use the command specified above but without providing an appropriate text file to store the cookies. To clarify, you can give this option –cookies-file=/dev/null? and cookies will be disabled. Here is the code:

Tags: , ,

Facebook Twitter Hacker News Reddit More...