diff --git a/src/background/background.ts b/src/background/background.ts index 8db61947..199eceb9 100644 --- a/src/background/background.ts +++ b/src/background/background.ts @@ -10,6 +10,7 @@ import onResponseStarted from "./handlers/onResponseStarted"; import onStartupStoreCleanup from "./handlers/onStartupStoreCleanup"; import onTabCreated from "./handlers/onTabCreated"; import onTabRemoved from "./handlers/onTabRemoved"; +import onTabReplaced from "./handlers/onTabReplaced"; import onTabUpdated from "./handlers/onTabUpdated"; console.info("🚀 Background script loaded."); @@ -40,6 +41,7 @@ if (isChromium) { browser.tabs.onCreated.addListener(onTabCreated); browser.tabs.onUpdated.addListener(onTabUpdated); browser.tabs.onRemoved.addListener(onTabRemoved); + browser.tabs.onReplaced.addListener(onTabReplaced); } else { // Block tracking pixels. browser.webRequest.onBeforeRequest.addListener( diff --git a/src/background/handlers/onTabReplaced.ts b/src/background/handlers/onTabReplaced.ts new file mode 100644 index 00000000..2a63ab49 --- /dev/null +++ b/src/background/handlers/onTabReplaced.ts @@ -0,0 +1,14 @@ +import browser from "webextension-polyfill"; +import onTabCreated from "./onTabCreated"; +import onTabRemoved from "./onTabRemoved"; + +export default function onTabReplaced( + addedTabId: number, + removedTabId: number +): void { + onTabRemoved(removedTabId); + browser.tabs + .get(addedTabId) + .then(tab => onTabCreated(tab)) + .catch(() => console.error("❌ Failed to get tab after replacement.")); +}