Firefox Container detection using "cookieStoreId"

I’ve noticed the “cookieStoreId” property of “Tab” object is:

  • "firefox-default" in default Firefox (no container)
  • "firefox-private" in private Firefox window
  • "firefox-container-<number>" in container tab

But is this documented somewhere?
Can it change?
And is it same for Android / all Firefox forks?

I would like to use this to detect container/private window (instead of using getBackgroundPage which is buggy and will break in V3 anyway).

No, the documented behavior is that the cookieStoreId will match whatever the https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/contextualIdentities API returns if applicable. To detect private tabs, you should use the incognito attribute. If you can see a different cookie store id for private tabs without having access to the incognito attribute that might actually be a bug in the API.

1 Like

Good idea with the incognito, I’ve forgot about that one!

So to detect a container, I should call contextualIdentities.get() and if it doesn’t fail, it’s a container, right?
Something like this:

export async function isContainerTab() {
  const tab = await browser.tabs.getCurrent();
  return await browser.contextualIdentities.get(tab.cookieStoreId).then(() => true, () => false);
}

Or you can load all the containers with browser.contextualdentities.query().

Yes but I would have to query it each time since containers can be created / removed at runtime. Especially when using some addons which can create new temp container for each tab/page.

Anyway, thanks a lot for pointing me to the right direction!