Hello, I'd like to start by thanking all of those who contributed to this awesome software.
I am trying to write a little script that logs in to a website and does a set of actions, but I need to preserve the session cookie so I can use it for other instances.
The website I am logging to, does not support authentication using cookies "Only session cookie", so there is no "Remember me" Option to use here.
I have searched or this issue but no solution came up, so I wanted to try and "Manually" add the session cookie hoping this will solve it, cos if it does, then I will be handling the session cookie manually, so I went ahead and added this to my script (before page.open):
phantom.addCookie({
'name' : 'sess_id',
'value' : '9b11ae92a98c98af8a6bacb91023801f',
'domain' : 'domain.com',
'path' : '/',
});
But it did not work.
And to clear things up, I used to do this with cURL, saving the cookie jar, and sure enough the session cookie is saved there as well, so I used to perform my actions using cURL, but now that there are JS actions to be made I have to use PhantomJS
So to sum up my issue, I am posting login data, taking a screenshot and sure enough I'm logged in, phantom is only saving cookies in --cookies-file, but not session cookie (cos it is purging it according to the output when using --debug=true), is there an option? A switch, or a workaround to make PhantomJS save and load session cookies?
P.S: While I know this might not technically an "issue", I think it still is, I understand that by being a headless browser it needs to act like one, thus deleting session cookies when the browser is closed, but as it is for developers I think an option for this should be present to help developers with a case like mine.
Thanks
For what it is worth I've solved the problem:
I downloaded the source and commented out "purgeSessionCookies();" in "src/cookiejar.cpp", I built it and now the session cookies are not being removed
Thanks
You can post out a nice tutorial to use phantom generated cookie file , which can be used in curl , or for selenium
it's better way add option --cookies-keep-session to keep the session cookie not be removed
can i set this option this way if using php-webdriver
$capabilities->setCapability(
'phantomjs.cli.args',
['--ignore-ssl-errors=true', '--web-security=false','--cookies-file=/usr/share/nginx/html/php-webdriver/cookies.txt', '--webdriver=4444','--cookies-keep-session=true']
);
Error: Unknown option: cookies-keep-session
@radarhere @spedy
Sorry for my comments. It is not been implemented; Just a suggestion
I also need something like --cookies-keep-session and don't think that the solution should be to comment out the line and create your own build (especially since I need a WIN build without purgeSessionCookies() call :/). The problem is not just reusing/restarting the EXE that wipes them out, but even using the WebDriver on Windows (2.1.1), I don't think I have ever ran 100 URLs through it without the process crashing. It can be detected and restarted, but then you are back to square one with Session Cookies... Has there been any solutions to this since?
why this issue is closed? what is the solution?
// private:
CookieJar::~CookieJar()
{
// On destruction, before saving, clear all the session cookies
//purgeSessionCookies();
save();
}
Most helpful comment
Error: Unknown option: cookies-keep-session