Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

PhantomJS does not preserve session cookie when using --cookies-file #12277

Closed
AL-Kateb opened this issue May 29, 2014 · 9 comments
Closed

PhantomJS does not preserve session cookie when using --cookies-file #12277

AL-Kateb opened this issue May 29, 2014 · 9 comments

Comments

@AL-Kateb
Copy link

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

@AL-Kateb
Copy link
Author

AL-Kateb commented Jun 1, 2014

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

@AL-Kateb AL-Kateb closed this as completed Jun 1, 2014
@davidandorf
Copy link

You can post out a nice tutorial to use phantom generated cookie file , which can be used in curl , or for selenium

@geekli
Copy link

geekli commented Oct 28, 2014

it's better way add option --cookies-keep-session to keep the session cookie not be removed

@emiglobetrotting
Copy link

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']
);

@ryancwalsh
Copy link

Error: Unknown option: cookies-keep-session

@geekli
Copy link

geekli commented Sep 19, 2016

@radarhere @spedy
Sorry for my comments. It is not been implemented; Just a suggestion

@artemstry
Copy link

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?

@d668
Copy link

d668 commented Mar 4, 2017

why this issue is closed? what is the solution?

@safrizal
Copy link

// private:
CookieJar::~CookieJar()
{
// On destruction, before saving, clear all the session cookies
//purgeSessionCookies();
save();
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants