Skip to content

Commit

Permalink
feat/fix: create new tc on origin change
Browse files Browse the repository at this point in the history
fix: remove debug output
fix: retain active state
  • Loading branch information
igorlogius committed Jul 27, 2024
1 parent 35e1de3 commit 820e3e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ async function onStorageChange() {
neverOpenInTempContainerRegexList =
await buildNeverOpenInTempContainerRegExList();

console.debug(neverOpenInTempContainerRegexList);

historyCleanUpQueue = await getFromStorage(
"object",
"historyCleanUpQueue",
Expand Down Expand Up @@ -315,6 +313,12 @@ 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) {
if (details.frameId > 0) {
return;
Expand All @@ -328,8 +332,8 @@ async function onBeforeNavigate(details) {
const _isOnNeverInTempContainerRegexList =
isOnNeverOpenInTempContainerRegexList(details.url);

const tabInfo = await browser.tabs.get(details.tabId);
try {
const tabInfo = await browser.tabs.get(details.tabId);
const container = await browser.contextualIdentities.get(
tabInfo.cookieStoreId,
);
Expand All @@ -344,6 +348,19 @@ async function onBeforeNavigate(details) {
browser.tabs.remove(details.tabId);
return;
}

// make links open from containered tabs not open in the same container
// !experimental
if (tabInfo.openerTabId) {
const openertabInfo = await browser.tabs.get(tabInfo.openerTabId);
if (openertabInfo.cookieStoreId === tabInfo.cookieStoreId) {
if (!sameOrigin(details.url, openertabInfo.url)) {
await createTempContainerTab(details.url, tabInfo.active);
browser.tabs.remove(details.tabId);
}
}
}

if (!historyPermissionEnabled) {
return;
}
Expand All @@ -361,7 +378,7 @@ async function onBeforeNavigate(details) {
(listmode === "exclude" && !_isOnList) ||
(listmode === "include" && _isOnList)
) {
await createTempContainerTab(details.url, true);
await createTempContainerTab(details.url, tabInfo.active);
browser.tabs.remove(details.tabId);
}
}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
"tabs"
],
"optional_permissions": ["bookmarks", "history"],
"version": "1.1.36"
"version": "1.1.37"
}

0 comments on commit 820e3e8

Please sign in to comment.