mozilla / multi-account-containers

Firefox Multi-Account Containers lets you keep parts of your online life separated into color-coded tabs that preserve your privacy. Cookies are separated by container, allowing you to use the web with multiple identities or accounts simultaneously.
https://addons.mozilla.org/firefox/addon/multi-account-containers/
Mozilla Public License 2.0
2.64k stars 322 forks source link

Container tabs have inconsistent IDs #2581

Open tanwald opened 9 months ago

tanwald commented 9 months ago

Before submitting a bug report

Step to reproduce

  1. Open a bookmark that is set to launch in a container in a new tab and log its ID!
browser.tabs.create({url: bookmark.url, windowId: 1, active: false})
  .then((tab) => {
      console.debug(tab.id);
  }, (error) => {
      console.error(`Could not create tab: ${error}`);
  });
  1. Log the ID of the new tab after webNavigation has completed!
browser.webNavigation.onCompleted.addListener((details) => console.debug(details.tabId));

Actual behavior

The ID of the created tab in step 1 is different than the ID of the same tab in step 2. The tab changes its identity.

Expected behavior

The ID of a tab should be immutable/consistent. Changes should be at least observable. Extensions that create tabs should be able to close them again.

dannycolin commented 9 months ago

This is the expected behavior because you create the tab in the default contextualidentity since you didn't specify the cookieStoreId parameter (see: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/create). So what's currently happening is:

  1. Create tab in default context
  2. Multi-Account Container rules kick in and move the tab to a new context (it needs to close and reopen a new tab for that. This is how it's implemented in Firefox itself and we can't control that on the addon side).
  3. onCompleted listener returns the id of the container tab which is different from the first tab created

Related to: https://github.com/mozilla/multi-account-containers/issues/1029