contextualIdentities 编辑

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.

Types

contextualIdentities.ContextualIdentity
Contains information about a contextual identity.

Functions

contextualIdentities.create()
Creates a new contextual identity.
contextualIdentities.get()
Retrieves a single contextual identity, given its cookie store ID.
contextualIdentities.query()
Retrieves all contextual identities, or all contextual identities with a particular name.
contextualIdentities.update()
Updates properties of an existing contextual identity.
contextualIdentities.remove()
Deletes a contextual identity.

Events

contextualIdentities.onCreated
Fired when a contextual identity is created.
contextualIdentities.onRemoved
Fired when a contextual identity is removed.
contextualIdentities.onUpdated
Fired when one or more properties of a contextual identity is updated.

Browser compatibility

BCD tables only load in the browser

Example extensions

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:135 次

字数:5367

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文