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

Separate CookieJar objects for WebPages #11417

Closed
jrollinson opened this issue Jun 18, 2013 · 16 comments
Closed

Separate CookieJar objects for WebPages #11417

jrollinson opened this issue Jun 18, 2013 · 16 comments
Labels

Comments

@jrollinson
Copy link

Currently, there exists a single CookieJar object for all web pages. This is in line with the usual behaviour of web pages, but causes difficulty when treating pages as separate entities.

To fix: CookieJar should not be a singleton, and objects that use a CookieJar should have one passed in on construction.

@jrollinson
Copy link
Author

@ariya
Copy link
Owner

ariya commented Jun 19, 2013

Interesting. Let me come up with a hypothetical API and code:

var myJar = new CookieJar();
page.cookieJar = myJar;
myJar.save('/secret/path/to/my/locker/cookie.dat');

Does that make sense? Obviously, there can be a default cookie jar for a new page instance.

@JamesMGreene
Copy link
Collaborator

What about for loading an existing CookieJar? Specify a path in the constructor, maybe?

@jrollinson
Copy link
Author

@ariya Are you suggesting a new CookieJar module like this?

var cookieJarCreator = require('cookieJar');
var myJar = cookieJarCreator.create();

@jrollinson
Copy link
Author

I think an optional path in the constructor would be a great way for loading existing cookie jars.

@ariya
Copy link
Owner

ariya commented Jun 19, 2013

Whether it's in its own module, conveniently constructed, etc are small details. What we need to come up with is the answer to the following question "if such an API is provided, how would your code look like".

@jrollinson
Copy link
Author

Ok. I think the code would look like this:

var myJar = new CookieJar();
page1.cookieJar = myJar;
page2.cookieJar = myJar;
myJar.addCookie(cookie);

... do whatever ...

page1.close();
page2.close();
myJar.save(path);
myJar.close();

A new page would have the default CookieJar and then you can set the page's CookieJar to be whatever you want.
Making the user explicitly close the CookieJar would save a bit of a nightmare.

Also, I think that the CookieJar should have the same API that both the phantom and webpage objects have with cookies.
In other words it should have the following functions and properties:

addCookie(Cookie);
deleteCookie(cookieName);
cookies;
clearCookies();
save(path);
close();

We should also add a CookieJar getter on the phantom object and both a getter and a setter for the CookieJar in webpages.

@AGoblinKing
Copy link

Running into this problem with trying to run tests in parallel in CasperJS. Having the ability to set CookieJars per instance of WebPage would be extremely helpful.

@jrollinson
Copy link
Author

I would like to be responsible for this issue. What do you think about the interface I described above?

@brokenthumbs
Copy link

Any chance that this update could be pulled in to PhantomJS? Would love to use PhantomJS with GhostDriver and run sessions in parallel, and this would help eliminate any shared cookie issues, to mitigate issues concerning logging in as different users and such.

@artkoshelev
Copy link

waiting for this issues as well, it's a show-stopper for using PhantomJS with GhostDriver in our web-tests

jrollinson added a commit to jrollinson/phantomjs that referenced this issue Jan 6, 2014
Adds qDebug messages to CookieJar constructor.

ariya#11417
jrollinson added a commit to jrollinson/phantomjs that referenced this issue Jan 6, 2014
m_cookeJarSingleton has changed from being the only cookie jar to being the
default cookie jar.
This warrants a name change.

ariya#11417
jrollinson added a commit to jrollinson/phantomjs that referenced this issue Jan 6, 2014
jrollinson added a commit to jrollinson/phantomjs that referenced this issue Jan 6, 2014
Changes order of constructor parameters so that the parent is last and can be
defaulted to NULL.

ariya#11417
jrollinson added a commit to jrollinson/phantomjs that referenced this issue Jan 6, 2014
Previously cookieToMap was a public function.
Since cookiesToMap is a public slot, this change makes the cookie jar
interface more symmetric.

ariya#11417
jrollinson pushed a commit to jrollinson/phantomjs that referenced this issue Jan 7, 2014
Previously, there was a single global cookie jar shared between all web pages.
Now, one can have separate cookie jars for different web pages.

Makes CookieJar a normal class, not a singleton.
Moves many public CookieJar methods to public slots.
Adds default cookie jar to Phantom.
Adds the CookieJar module that provides access to cookie jars in javascript.
Adds cookie jar module tests.

Usage:
var jar = require('cookiejar').create();
var webpage = require('webpage').create();
webpage.cookieJar = jar;
...
webpage.close();
jar.close();

JS API changes:
Webpage:
    var jar = page.cookieJar; -- assigns 'jar' the given webpage's cookie jar.
    page.cookiejar = jar; -- sets 'jar' as the given webpage's cookie jar.
CookieJar:
    var jar = require('cookiejar').create(path)
        creates a cookie jar with persistent storage at the given file path
        (path not mandatory).
    var cookies = jar.cookies; -- assign's 'jar' the list of cookies in the
        cookie jar.
    jar.cookies = [c1, c2]; -- sets the cookie jar's cookies as the ones in the
        list.
    jar.addCookie(cookie) -- adds cookie 'cookie' to the cookie jar.

fixes issue ariya#11417
jrollinson pushed a commit to jrollinson/phantomjs that referenced this issue Jan 10, 2014
Previously, there was a single global cookie jar shared between all web pages.
Now, one can have separate cookie jars for different web pages.

Makes CookieJar a normal class, not a singleton.
Moves many public CookieJar methods to public slots.
Adds default cookie jar to Phantom.
Adds the CookieJar module that provides access to cookie jars in javascript.
Adds cookie jar module tests.

Usage:
var jar = require('cookiejar').create();
var webpage = require('webpage').create();
webpage.cookieJar = jar;
...
webpage.close();
jar.close();

JS API changes:
Webpage:
    var jar = page.cookieJar; -- assigns 'jar' the given webpage's cookie jar.
    page.cookiejar = jar; -- sets 'jar' as the given webpage's cookie jar.
CookieJar:
    var jar = require('cookiejar').create(path)
        creates a cookie jar with persistent storage at the given file path
        (path not mandatory).
    var cookies = jar.cookies; -- assign's 'jar' the list of cookies in the
        cookie jar.
    jar.cookies = [c1, c2]; -- sets the cookie jar's cookies as the ones in the
        list.
    jar.addCookie(cookie) -- adds cookie 'cookie' to the cookie jar.

fixes issue ariya#11417
jrollinson pushed a commit to jrollinson/phantomjs that referenced this issue Jan 10, 2014
Previously, there was a single global cookie jar shared between all web pages.
Now, one can have separate cookie jars for different web pages.

Makes CookieJar a normal class, not a singleton.
Moves many public CookieJar methods to public slots.
Adds default cookie jar to Phantom.
Adds the CookieJar module that provides access to cookie jars in javascript.
Adds cookie jar module tests.

Usage:
var jar = require('cookiejar').create();
var webpage = require('webpage').create();
webpage.cookieJar = jar;
...
webpage.close();
jar.close();

JS API changes:
Webpage:
    var jar = page.cookieJar; -- assigns 'jar' the given webpage's cookie jar.
    page.cookiejar = jar; -- sets 'jar' as the given webpage's cookie jar.
CookieJar:
    var jar = require('cookiejar').create(path)
        creates a cookie jar with persistent storage at the given file path
        (path not mandatory).
    var cookies = jar.cookies; -- assign's 'jar' the list of cookies in the
        cookie jar.
    jar.cookies = [c1, c2]; -- sets the cookie jar's cookies as the ones in the
        list.
    jar.addCookie(cookie) -- adds cookie 'cookie' to the cookie jar.

fixes issue ariya#11417
ariya pushed a commit that referenced this issue Jan 11, 2014
Previously, there was a single global cookie jar shared between all web pages.
Now, one can have separate cookie jars for different web pages.

Makes CookieJar a normal class, not a singleton.
Moves many public CookieJar methods to public slots.
Adds default cookie jar to Phantom.
Adds the CookieJar module that provides access to cookie jars in javascript.
Adds cookie jar module tests.

Usage:
var jar = require('cookiejar').create();
var webpage = require('webpage').create();
webpage.cookieJar = jar;
...
webpage.close();
jar.close();

JS API changes:
Webpage:
    var jar = page.cookieJar; -- assigns 'jar' the given webpage's cookie jar.
    page.cookiejar = jar; -- sets 'jar' as the given webpage's cookie jar.
CookieJar:
    var jar = require('cookiejar').create(path)
        creates a cookie jar with persistent storage at the given file path
        (path not mandatory).
    var cookies = jar.cookies; -- assign's 'jar' the list of cookies in the
        cookie jar.
    jar.cookies = [c1, c2]; -- sets the cookie jar's cookies as the ones in the
        list.
    jar.addCookie(cookie) -- adds cookie 'cookie' to the cookie jar.

#11417
@yelizariev
Copy link

This issue is closed, I guess

@vitallium
Copy link
Collaborator

It's not closed and this problem is in out TODO list. I believe this is a crucial feature and it should be implemented.

@yelizariev
Copy link

@vitallium have you tried 2.0.0+ version? 244cf25

@vitallium
Copy link
Collaborator

The problem is that in the current state this feature requires some work to do. For example. it can't handle when the user closes a web page. We need to improve it and fix some nasty bugs.

@stale stale bot added the stale label Dec 26, 2019
@stale
Copy link

stale bot commented Dec 29, 2019

Due to our very limited maintenance capacity, we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed (see #15395 for more details). In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!

@stale stale bot closed this as completed Dec 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants