laurentj / slimerjs

A scriptable browser like PhantomJS, based on Firefox
http://slimerjs.org
Other
3k stars 258 forks source link

Separated cookie jars by implementing webpage.cookieJar #323

Open prawnsalad opened 9 years ago

prawnsalad commented 9 years ago

Is it possible to have separated cookie jars for each created page?

I have a script that tests different scenarios on a webpage, logging in/out/taking actions/etc but they currently all share the same cookies making it impossible. I'm trying not to have several sublimejs instances open.

laurentj commented 9 years ago

Well, you have all the API to add, remove cookies on a web page. It's not what you want?

prawnsalad commented 9 years ago

Not really what I'm trying to do. I'm trying to use separate cookie jars per page, while at the moment it is per-profile. ie:

    var page1 = require('webpage').create();
    var page2 = require('webpage').create();

    page1.open('http://domain.com/');
    page2.open('http://domain.com/');

I need page1 and page2 accessing their own cookies. Cookies set on page1 should not be accessible via page2 and visa-versa.

I have managed to hack a semi-working solution by keeping a .cookiejar property on my created page then using page.onResourceRequested and page.onResourceReceived to manage my own cookies, reading and setting the cookie headers as needed. However this does not work for cookies that are set/read using javascript on the webpage itself.

laurentj commented 9 years ago

We should see if there is a solution in Gecko. Probably by allowing to load the web site in the "private browsing mode"...

prawnsalad commented 9 years ago

I've no idea where to look, but opening multiple private windows sounds like it would be perfect.

prawnsalad commented 9 years ago

Maybe this will be of some use? An addon that allows switching to private sessions, I see it makes use of some XUL privatesession APIs. https://github.com/Infocatcher/Private_Tab

I'm looking blindly so no idea if it's relevant here

laurentj commented 8 years ago

For the moment, I don't know how to implement this feature. But PhantomJS 2.0 implements it, so we should do it.

Paxa commented 7 years ago

Having a same problem, would be nice to have this feature. Currently solved by running separate Firefox processes

laurentj commented 7 years ago

Firefox 56 has tab containers. We should see if we can use this feature in SlimerJS.