Baking some cookies
How about creating our own cookies? Normally, users do not push the creation of cookies, but in PhantomJS, we can do that in our script to change the browser behavior.
Let us modify our previous code, and before displaying the list of cookies, we will add a "username"
property to the cookie.
page.open(url, function(status) { if ( status === "success" ) { phantom.addCookie({ 'name' : 'username', 'value' : 'aries', 'domain' : '.yahoo.com' }); console.log(JSON.stringify(phantom.cookies, null, 4)); phantom.exit(0); } });
We will use the addCookie
function from the phantom
object. The function expects an object to be passed in JSON format. However, the name
, value
, and domain
property are the only properties required to be present; all other properties are optional.
Cookie property |
Expected value |
---|---|
|
The name of the cookie must be present. As per... |