Webstrates A research prototype enabling collaborative editing of websites through DOM manipulations.

Webstrates has a built-in cookie mechanism that allows logged in users to persist JavaScript objects across devices. There are two kinds of cookies: “anywhere” cookies, which may be accessed and modified from any webstrate the user is accessing, and document-bound cookies (“here”), only available from the webstrate they were created in.

The cookies are simple key-value stores persisted on the server and distributed to the user’s connected clients. Any serializable JavaScript object can be stored in cookies. To set an “anywhere” cookie foo with the value bar, call:

webstrate.user.cookies.anywhere.set("foo", "bar");

To retrieve it again (possibly in another webstrate, from another device the user is logged in to), the application/user may call:

webstrate.user.cookies.anywhere.get("foo");

and get back bar. “here” cookies are managed in a similar fashion through webstrate.cookies.here.set() and webstrate.cookies.here.get().

To retrieve all cookies, call get() without any parameters on either the here or anywhere object.

Cookies can only be saved for logged-in users, hence their placement on the webstrate.user object, which won’t exist for non-logged in users.

Listening for cookie updates can be done by subscribing to cookieUpdateHere and cookieUpdateAnywhere events, e.g.:

webstrate.on("cookieUpdateHere", function(key, value) {
  // A cookie key-value pair was added/updated.
});

Note that contrary to HTTP cookies, the cookies’ contents are stored on the server; only the session token (the user’s credentials) are stored in an actual HTTP cookie. A value set on one client will therefore be persisted to all of the user’s other connected clients (other computers, tablets, etc.).