Work with contextual identities: list, create, remove, and update contextual identities.
"Contextual identities", also known as "containers", are a browser feature which addresses the idea that users assume multiple identities when browsing the web, and wish to maintain some separation between these identities. For example, a user might consider their "work identity" separate from their "personal identity", and not want to share cookies between these two contexts.
With the contextual identities feature, each contextual identity has a name, a color, and an icon. New tabs can be assigned to an identity, and the name, icon, and color will appear in the address bar. Internally, each identity gets its own cookie store which is not shared with other tabs.
Contextual identities are an experimental feature in Firefox and are only enabled by default in Firefox Nightly. To enable them in other versions of Firefox, set the privacy.userContext.enabled
preference to true
. Note that although contextual identities are available in Firefox for Android, there's no UI to work with them in this version of the browser.
Before Firefox 57, the contextualIdentities
API is only available if the contextual identities feature is itself enabled. If an extension tried to use the contextualIdentities
API without the feature being enabled, then method calls would resolve their promises with false
.
From Firefox 57 onwards, if an extension that uses the contextualIdentities
API is installed, then the contextual identities feature will be enabled automatically. Note though that it's still possible for the user to disable the feature using the "privacy.userContext.enabled" preference. If this happens, then contextualIdentities
method calls will reject their promises with an error message.
For more information about contextual identities in Firefox, see this guide.
Contextual identities are not currently supported in any other browsers.
To use this API you need to include the "contextualIdentities" and "cookies" permissions in your manifest.json file.
contextualIdentities.ContextualIdentity
contextualIdentities.create()
contextualIdentities.get()
contextualIdentities.query()
contextualIdentities.update()
contextualIdentities.remove()
contextualIdentities.onCreated
contextualIdentities.onRemoved
contextualIdentities.onUpdated
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
create |
No |
No |
53
Before version 57, this method resolves its promise with
false if the contextual identities feature is disabled. |
? |
No |
No |
? |
? |
53
Before version 57, this method resolves its promise with
false if the contextual identities feature is disabled. |
? |
? |
? |
get |
No |
No |
53
["Before version 57, this method resolves its promise with
false if the contextual identities feature is disabled.", "Before version 57, this method resolves its promise with null if the given identity was not found."] |
? |
No |
No |
? |
? |
53
["Before version 57, this method resolves its promise with
false if the contextual identities feature is disabled.", "Before version 57, this method resolves its promise with null if the given identity was not found."] |
? |
? |
? |
onCreated |
No |
No |
57 |
? |
No |
No |
? |
? |
57 |
? |
? |
? |
onRemoved |
No |
No |
57 |
? |
No |
No |
? |
? |
57 |
? |
? |
? |
onUpdated |
No |
No |
57 |
? |
No |
No |
? |
? |
57 |
? |
? |
? |
query |
No |
No |
53
Before version 57, this method resolves its promise with
false if the contextual identities feature is disabled. |
? |
No |
No |
? |
? |
53
Before version 57, this method resolves its promise with
false if the contextual identities feature is disabled. |
? |
? |
? |
remove |
No |
No |
53
["Before version 57, this method resolves its promise with
false if the contextual identities feature is disabled.", "Before version 57, this method resolves its promise with null if the given identity was not found."] |
? |
No |
No |
? |
? |
53
["Before version 57, this method resolves its promise with
false if the contextual identities feature is disabled.", "Before version 57, this method resolves its promise with null if the given identity was not found."] |
? |
? |
? |
update |
No |
No |
53
["Before version 57, this method resolves its promise with
false if the contextual identities feature is disabled.", "Before version 57, this method resolves its promise with null if the given identity was not found."] |
? |
No |
No |
? |
? |
53
["Before version 57, this method resolves its promise with
false if the contextual identities feature is disabled.", "Before version 57, this method resolves its promise with null if the given identity was not found."] |
? |
? |
? |
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/contextualIdentities