I wrote a simple script that detects cookies that a website sets. Here's the code:
var system = require('system');
var url = system.args[1];
var page = require('webpage').create();
page.open(url, function (status) {
console.log(JSON.stringify(page.cookies, null, 2));
phantom.exit();
});
When I execute this from a shell e.g.:
# phantomjs test.js
http://www.phantomjs.orgI get a list of cookies that are set at
www.phantomjs.org like:
[
{
"domain": ".
phantomjs.org",
"expires": "Wed, 11 Dec 2013 18:51:14 GMT",
"expiry": 1386787874,
"httponly": false,
"name": "__utmz",
"path": "/",
"secure": false,
"value": "205055825.1371019874.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)"
},
{
"domain": ".
phantomjs.org",
"expires": "Wed, 11 Dec 2013 18:51:14 GMT",
"expiry": 1386787874, "httponly": false,
"name": "__utmc",
"path": "/",
"secure": false,
"value": "205055825"
},
{
"domain": ".
phantomjs.org",
"expires": "Wed, 12 Jun 2013 07:21:14 GMT",
"expiry": 1371021674,
"httponly": false,
"name": "__utmb",
"path": "/",
"secure": false,
"value": "205055825.1.10.1371019874"
},
{
"domain": ".
phantomjs.org",
"expires": "Fri, 12 Jun 2015 06:51:14 GMT",
"expiry": 1434091874,
"httponly": false,
"name": "__utma",
"path": "/",
"secure": false,
"value": "205055825.1902598942.1371019874.1371019874.1371019874.1"
}
]
This is correct but if you visit
phantomjs.org and take a look at all the cookies that are being set you will see that "__utmc" is a session cookie - it has no expiry date - but phantomjs displays its expiry date as Wed, 11 Dec 2013 18:51:14 GMT (which in my case is 6 months and 12 hours from now). Why?
If I use cookie jar file (e.g. phantomjs --cookies-file=cookies.txt test.js
http://www.phantomjs.org) the __utmc cookie is not stored inside (which is correct) but how can I know inside my script that this is a session cookie if phantomjs has its expiry date defined?
I want to strictly separate session cookies from persistent cookies in my script but I am unable to do that since all cookies are shown the same.