Javascript API for Cookie Storage
It makes sense to expose a way to override the running chromium cookie store (sqlite based 0da35bedf36f6b0fd8be6b4b5ea19143377da961) with a Javascript version of it
I'd love to create a pull-request for this (which could pave the way to add much more delegation APIs to customize Webkit behavior directly from Javascript)
I've been looking into the architecture of the UI api. Unfortunately the one to one mapping between Javascript object and Chrome objects based on id won't cut it if we want async delegation in Javascript.
Talking about Cookie Storage, the idea would be to create new addon nw.net that would expose a simple setCookieStore(obj) function that the user would call with object being a subclass of a dummy CookieStore base class.
When called setCookieStore(obj) would change the Cookie Storage in the URLRequestContextGetter for a Cookie Storage that would bind all calls to the Javascript Object it had been passed.
I still need to wrap my head around how to properly expose a new module and will provide a Pull Request here. I'm definitely looking for early comments on that as well!
@spolu Have you started working on this yet? I'm very interested in this, so if you haven't started working on it, then I probably will in the near future.
@twrodriguez unfortunately I didn't find the time to finish it. Looks perfectly feasible from what I've tinkered with.
Why it'd be in nw.net rather in nw.gui?
and feature wise how is your proposal compared with chrome.cookie API? I'll look into this feature soon.
http://developer.chrome.com/extensions/cookies.html
The Chrome Cookie API lets you access and set cookies, but does not let you replace the cookie store entirely unfortunately. Some cases, like building a browser out of node-webkit would require a deeper integration in my opinion.
One fairly easy solution would be to expose the persistent cookie store + something similar to the Chrome Cookie API. You also have the ability to expose the net::NetworkDelegate APIs to intercept cookie I/O. The latter one is what CEF exposes, but as far as I could experiment, it's not really useful.
nw.net is because Cookies have nothing to do with "gui" and additional API could be exposed there (local storage, net::NetworkDelegate, etc...). But that's just a suggestion.
Working on a project of mine, I had a very good experience exposing the PersistentCookieStore. The API is simple and it lets you do pretty much everything you can think of.
Hope it helps!
Thanks. I'll see whether I need to come up with the easy solution first and then this proposal.
Is there any JS code I can use to implement a persistent cookie store on top of this proposed API?
Sure. you can look there: https://github.com/spolu/exo_browser/blob/master/shell/lib/cookie_store.js
And here to see how CanonicalCookies are mapped to JS objects. https://github.com/spolu/exo_browser/blob/master/src/node/api/exo_session_wrap.cc#L23
I recommend using nedb (https://github.com/louischatriot/nedb/)
Awesome you guys are working on this! Currently I'm using the following code to retrieve a specific cookie.
this.fs.readFile(Config.dataPath + '/cookies', 'utf8', function(err, text) {
text = text || "";
var match = text.match(/_cookiename([^\/]*)/);
if (match) {
_this.set('cookie', '_cookiename=' + match[1]);
console.log(_this.get('cookie'))
}
});
The problem is that the cookies file that resides in the data path does not get instantly updated. It takes about 5s after an incoming response with cookie header before the file changes.
this is now supported.