Rob--W/cookie-manager

Cookie question -

deehill opened this issue · 3 comments

Hi Rob.

Looking over the cookie-manager app. I've got a couple of questions and thought I'd ping you to see if you might give me insight.

Say I have multiple TABs and each tab is running a url. If the urls are all of the same "domain" but different pages, how are the "cookies" from the urls tracked? If the url in say TAB1 changes ,and it changes the cookie, does this override the cookie previously changed?

I'm looking to try to create a modified extension that will allow me to monitor when a "cookie" changes in a given "TAB" and to then copy that cookie to another TAB, running another url. Both tabs would be running the same "domain"

thanks

-bruce

Cookies are not only keyed by domain and name, but also by the path. By default, the path is /, but you can set the path to something else (e.g. /Rob--W/, /Rob--W/cookie-manager/ or /Rob--W/cookie-manager/issues/ are possible paths for this page on Github).

You can see this helper method to see which parts of cookie contribute to the identity of a cookie:

// Checks whether the given cookies would be written to the same cookie slot.
// The given cookies must be of the type cookies.Cookie.
function isSameCookieKey(cookieA, cookieB) {
// Cookies are keyed by (domain, path, name) + origin attributes.
// (where the domain starts with a dot iff it is a domain cookie (opposed to host-only)).
// Origin attributes currently include:
// - userContextId and privateBrowsingId -> storeId
// - firstPartyDomain -> firstPartyDomain (Firefox 59+)
if (cookieA.name !== cookieB.name ||
cookieA.domain !== cookieB.domain ||
cookieA.path !== cookieB.path ||
cookieA.firstPartyDomain !== cookieB.firstPartyDomain ||
cookieA.storeId !== cookieB.storeId) {
return false;
}
return true;
}

I'm looking to test/do this as I'm looking to generate a test extension that I can use to "test" multiple URLs across multiple Tabs

A better solution for your use case is to use the Container Tabs feature of Firefox. Extensions can create new container tab identities using the contextualIdentities API (https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/contextualIdentities) and then open tabs with browser.tabs.create({ url: "...", cookieStoreId: "firefox-container-1234" }) (where firefox-container-1234 is obtained via the contextualIdentities API).