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);contextualIdentities.move() / notebook
contextualIdentities.move()
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
let identities = await browser.contextualIdentities.query({});
let ids = identities.map((identity) => identity.cookieStoreId);
// Create an array without the first item:
let otherIds = ids.slice(1);
// Move other identities to the start,
// effectively putting the first identity at the end.
await browser.contextualIdentities.move(otherIds, 0);let identities = await browser.contextualIdentities.query({});
// Find the index and ID of the container with the name "Personal".
let personalIndex = identities.findIndex((ci) => ci.name === "Personal");
if (personalIndex === -1) {
throw new Error("Personal container not found");
}
let personalId = identities[personalIndex].cookieStoreId;
// Find the index of the container with the name "Work".
let workIndex = identities.findIndex((identity) => identity.name === "Work");
if (workIndex === -1) {
throw new Error("Work container not found!");
}
if (personalIndex < workIndex) {
// When the Personal identity moves, all following
// identities shift to the left by one. To place
// the Personal identity before the Work identity,
// we should therefore subtract one.
workIndex--;
}
await browser.contextualIdentities.move(personalId, workIndex);