Skip to content

Commit

Permalink
fix(#4): cleanup temp containers after restart
Browse files Browse the repository at this point in the history
  • Loading branch information
igorlogius committed Oct 29, 2023
1 parent a31091c commit 280d3e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* global browser */

// cookieStoreIds of all managed containers
var containers = new Set();
let containerCleanupTimer = null;

// array of all allowed container colors
Expand Down Expand Up @@ -52,10 +51,15 @@ async function onTabRemoved() {
const containerWithTabs = new Set(
(await browser.tabs.query({})).map((t) => t.cookieStoreId)
);

containers = await browser.contextualIdentities.query({});

containers.forEach((c) => {
if (!containerWithTabs.has(c)) {
containers.delete(c);
browser.contextualIdentities.remove(c);
if (
!containerWithTabs.has(c.cookieStoreId) &&
c.name.startsWith("Temp")
) {
browser.contextualIdentities.remove(c.cookieStoreId);
}
});
containerCleanupTimer = null;
Expand Down Expand Up @@ -98,10 +102,11 @@ async function createContainer() {
let cookieStoreId = container.cookieStoreId;
let name = "Temp " + Date.now();
await browser.contextualIdentities.update(cookieStoreId, { name: name });
containers.add(cookieStoreId);
return container;
}

// register listeners
browser.tabs.onRemoved.addListener(onTabRemoved);
browser.browserAction.onClicked.addListener(onBAClicked);
//browser.runtime.onStartup.addListener(onTabRemoved);
setTimeout(onTabRemoved, 5000);
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
"menus",
"tabs"
],
"version": "1.1.3"
"version": "1.1.4"
}

0 comments on commit 280d3e5

Please sign in to comment.