From 3cf268e9dfc68c7985f68054f9e40729c29da89e Mon Sep 17 00:00:00 2001 From: hackademix Date: Fri, 9 Jun 2023 14:48:29 +0200 Subject: [PATCH] [TabGuard] Keep track of anonymized tabs. --- src/bg/TabGuard.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/bg/TabGuard.js b/src/bg/TabGuard.js index 40ea8ad..0b6d98a 100644 --- a/src/bg/TabGuard.js +++ b/src/bg/TabGuard.js @@ -22,6 +22,11 @@ var TabGuard = (() => { (async () => { await include(["/nscl/service/TabCache.js", "/nscl/service/TabTies.js"]); })(); + const anonymizedTabs = new Map(); + browser.tabs.onRemoved.addListener(tab => { + anonymizedTabs.delete(tab.id); + }); + let allowedGroups, filteredGroups; let forget = () => { allowedGroups = {}; @@ -64,6 +69,7 @@ var TabGuard = (() => { const mainFrame = type === "main_frame"; if (mainFrame) { + anonymizedTabs.delete(tabId); let headers = flattenHeaders(requestHeaders); let shouldCut = false; if (headers["sec-fetch-user"] === "?1") { @@ -153,6 +159,7 @@ var TabGuard = (() => { let filterAuth = () => { requestHeaders = requestHeaders.filter(h => !AUTH_HEADERS_RX.test(h.name)); debug("[TabGuard] Removing auth headers from %o (%o)", request, requestHeaders); + anonymizedTabs.set(tabId, {tabDomain, otherDomains: [...otherDomains]}); return {requestHeaders}; }; @@ -195,5 +202,16 @@ var TabGuard = (() => { TabTies.cut(tabId); } }, + isAnonymizedTab(tabId) { + return anonymizedTabs.has(tabId); + }, + getAnonymizedTabInfo(tabId) { + // return a deep copy + return JSON.parse(JSON.stringify(anonymizedTabs.get(tabId))); + }, + reloadNormally(tabId) { + TabTies.cut(tabId); + browser.tabs.reload(tabId); + } } })();