Skip to content

Commit

Permalink
fix/chore: reduce required permission
Browse files Browse the repository at this point in the history
fix/chore: reduce container deletion delay (might help not to sync temp containers ... maybe)
  • Loading branch information
igorlogius committed Sep 17, 2024
1 parent cb19e40 commit bdcbb92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 39 deletions.
51 changes: 16 additions & 35 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ let intId = null;
let historyCleanUpQueue = [];
let containerCleanupTimer = null;
let toolbarAction = "";
let deldelay = 30000; // delay until Tmp Containers and History Entries are removed
let histdeldelay = 30000;
let tcdeldelay = 5000;
let regexList = null;
let ignoredRegexList = null;
let splitorigins = false;

// array of all allowed container colors
const allcolors = [
Expand Down Expand Up @@ -170,27 +170,21 @@ browser.menus.create({

// delayed container cleanup
async function onTabRemoved() {
if (containerCleanupTimer !== null) {
clearTimeout(containerCleanupTimer);
}

clearTimeout(containerCleanupTimer);
containerCleanupTimer = setTimeout(async () => {
const containerWithTabs = new Set(
(await browser.tabs.query({})).map((t) => t.cookieStoreId),
);

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

containers.forEach((c) => {
if (
!containerWithTabs.has(c.cookieStoreId) &&
c.name.startsWith("Temp")
c.name.startsWith("Temp ")
) {
browser.contextualIdentities.remove(c.cookieStoreId);
}
});
containerCleanupTimer = null;
}, deldelay);
}, tcdeldelay);
}

async function createTempContainerTab(url, activ = true) {
Expand Down Expand Up @@ -234,13 +228,13 @@ async function onBAClicked(tab) {
async function createContainer() {
const color = usecolors[Math.floor(Math.random() * usecolors.length)];
let container = await browser.contextualIdentities.create({
name: "Temp",
name: "Temp " + Date.now(),
color: color,
icon: "circle",
});
await browser.contextualIdentities.update(container.cookieStoreId, {
/*await browser.contextualIdentities.update(container.cookieStoreId, {
name: "Temp " + Date.now(),
});
});*/
return container;
}

Expand All @@ -262,8 +256,6 @@ async function onStorageChange() {
"historyCleanUpQueue",
[],
);

splitorigins = await getFromStorage("boolean", "splitorigins", false);
}

// show the user the options page on first installation
Expand Down Expand Up @@ -293,12 +285,6 @@ async function onCommand(command) {
}
}

function sameOrigin(urlA, urlB) {
const a = new URL(urlA);
const b = new URL(urlB);
return a.origin === b.origin;
}

async function onBeforeNavigate(details) {
const isIgnored = isOnIngoreList(details.url);

Expand Down Expand Up @@ -332,11 +318,11 @@ async function onBeforeNavigate(details) {
) {
await createTempContainerTab(details.url, tabInfo.active);
browser.tabs.remove(tabInfo.id);
return;
}
} else {
// in a container
if (inTempContainer) {
// in a TC
if (!historyPermissionEnabled) {
return;
}
Expand All @@ -359,6 +345,7 @@ function cleanupHistory() {
});
} catch (e) {
//noop
console.warn(e);
}
}
setToStorage("historyCleanUpQueue", historyCleanUpQueue);
Expand All @@ -369,7 +356,7 @@ async function handlePermissionChange() {
await browser.permissions.contains(historyPermission);
clearInterval(intId);
if (historyPermissionEnabled) {
intId = setInterval(cleanupHistory, deldelay);
intId = setInterval(cleanupHistory, histdeldelay);
}
}

Expand All @@ -380,21 +367,15 @@ async function handlePermissionChange() {
await onStorageChange();
await handlePermissionChange();

// trigger inital cleanup, for browser restart
setTimeout(onTabRemoved, deldelay);
// trigger inital cleanup, for browser re-start
setTimeout(onTabRemoved, tcdeldelay);

// register listeners
browser.browserAction.onClicked.addListener(onBAClicked);
browser.commands.onCommand.addListener(onCommand);
browser.storage.onChanged.addListener(onStorageChange);
browser.tabs.onRemoved.addListener(onTabRemoved);

browser.webRequest.onBeforeRequest.addListener(
onBeforeNavigate,
{ urls: ["<all_urls>"], types: ["main_frame"] },
["blocking"],
);

browser.permissions.onAdded.addListener(handlePermissionChange);
browser.permissions.onRemoved.addListener(handlePermissionChange);
browser.storage.onChanged.addListener(onStorageChange);
browser.tabs.onRemoved.addListener(onTabRemoved);
browser.webNavigation.onBeforeNavigate.addListener(onBeforeNavigate);
})();
6 changes: 2 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@
"page": "options.html"
},
"permissions": [
"<all_urls>",
"contextualIdentities",
"cookies",
"menus",
"storage",
"tabs",
"webRequest",
"webRequestBlocking"
"webNavigation"
],
"optional_permissions": ["bookmarks", "history"],
"version": "1.1.44"
"version": "1.1.45"
}

0 comments on commit bdcbb92

Please sign in to comment.