-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Separate CookieJar objects for WebPages #11417
Comments
Relevant Ghostdriver issues: |
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. |
What about for loading an existing CookieJar? Specify a path in the constructor, maybe? |
@ariya Are you suggesting a new CookieJar module like this? var cookieJarCreator = require('cookieJar');
var myJar = cookieJarCreator.create(); |
I think an optional path in the constructor would be a great way for loading existing cookie jars. |
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". |
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. Also, I think that the CookieJar should have the same API that both the phantom and webpage objects have with cookies. 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. |
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. |
I would like to be responsible for this issue. What do you think about the interface I described above? |
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. |
waiting for this issues as well, it's a show-stopper for using PhantomJS with GhostDriver in our web-tests |
Adds qDebug messages to CookieJar constructor. ariya#11417
m_cookeJarSingleton has changed from being the only cookie jar to being the default cookie jar. This warrants a name change. ariya#11417
Changes order of constructor parameters so that the parent is last and can be defaulted to NULL. ariya#11417
Previously cookieToMap was a public function. Since cookiesToMap is a public slot, this change makes the cookie jar interface more symmetric. ariya#11417
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
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
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
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
This issue is closed, I guess |
It's not closed and this problem is in out TODO list. I believe this is a crucial feature and it should be implemented. |
@vitallium have you tried 2.0.0+ version? 244cf25 |
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. |
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! |
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.
The text was updated successfully, but these errors were encountered: