Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contextualIdentities.move #31191

Merged
merged 7 commits into from
Jan 5, 2024
Merged

Conversation

rebloor
Copy link
Contributor

@rebloor rebloor commented Dec 21, 2023

Description

Documentation and release note in support of Bug 1333395 Consider support for containers sort order.

@rebloor rebloor added the Content:WebExt WebExtensions docs label Dec 21, 2023
@rebloor rebloor requested a review from Rob--W December 21, 2023 08:04
@rebloor rebloor self-assigned this Dec 21, 2023
@rebloor rebloor requested review from a team as code owners December 21, 2023 08:04
@rebloor rebloor requested review from hamishwillee and removed request for a team December 21, 2023 08:04
@github-actions github-actions bot added the Content:Firefox Content in the Mozilla/Firefox subtree label Dec 21, 2023
Copy link
Contributor

github-actions bot commented Dec 21, 2023

Preview URLs

Flaws (1)

Note! 2 documents with no flaws that don't need to be listed. 🎉

URL: /en-US/docs/Mozilla/Add-ons/WebExtensions/API/contextualIdentities/move
Title: contextualIdentities.move()
Flaw count: 1

  • bad_bcd_queries:
    • No BCD data for query: webextensions.api.contextualIdentities.move
External URLs (1)

URL: /en-US/docs/Mozilla/Firefox/Releases/123
Title: Firefox 123 for developers

(comment last updated: 2024-01-05 16:56:57)


## Examples

Starting with this list of contextual identities `[id0, id1, id2, id3]`:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that these were based on the testcase. In there, id0, id1, etc are variable names referring to the actual IDs. The examples below are unclear and not working.

I would simplify this section by showing how one can query identities, then choose the identity to move. For example, the scenario of moving the last identity to the start, and then back to the end. And another one where multiple identities are moved.

let identities = await browser.contextualIdentities.query({});
let firstId = identities[0].cookieStoreId;

// Moves first identity to the end.
await browser.contextualIdentities.move(firstId, -1);

// Move identity to the start again.
await browser.contextualIdentities.move(firstId, 0);

Alternative way of moving the first identity to the end: by moving all other identities to the start we get the same effect:

let identities = await browser.contextualIdentities.query({});
let ids = identities.map(identity => identity.cookieStoreId);
// Create array without the first item:
let otherIds = ids.slice(1);

// Moves other identities to the start,
// effectively putting the first identity to the end.
await browser.contextualIdentities.move(otherIds, 0);

Another example, move "Personal" identity before "Work". Important note: this example assumes containers with these names to exist. This is often not the case in customized or localized (non-English) Firefox instances.

let identities = await browser.contextualIdentities.query({});

// Find cookieStoreId of container with name "Personal".
let personalId = identities.find(ci => ci.name === "Personal")?.cookieStoreId;
if (!personalId) {
  throw new Error("Personal container not found");
}

// Find index of container with name "Work".
let workIndex = identities.findIndex(identity => identity.name === "Work");
if (workIndex === -1) {
  throw new Error("Work container not found!");
}
await browser.contextualIdentities.move(personalId, workIndex);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestions @Rob--W

@rebloor rebloor requested a review from Rob--W December 30, 2023 17:10
@hamishwillee hamishwillee removed their request for review January 2, 2024 00:50
Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please apply the suggested edits before merging.

@rebloor rebloor merged commit b303867 into mdn:main Jan 5, 2024
7 checks passed
estelle pushed a commit to estelle/content that referenced this pull request Jan 9, 2024
* Add contextualIdentities.move

* typo

* Apply suggestions from review

* Examples update

* Apply suggestions from review

Co-authored-by: Rob Wu <rob@robwu.nl>

---------

Co-authored-by: Rob Wu <rob@robwu.nl>
dipikabh pushed a commit to dipikabh/content that referenced this pull request Jan 17, 2024
* Add contextualIdentities.move

* typo

* Apply suggestions from review

* Examples update

* Apply suggestions from review

Co-authored-by: Rob Wu <rob@robwu.nl>

---------

Co-authored-by: Rob Wu <rob@robwu.nl>
@rebloor rebloor deleted the contextualIdentities.move branch November 14, 2024 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:Firefox Content in the Mozilla/Firefox subtree Content:WebExt WebExtensions docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants