From 9a4b27fc2dca0ba0a420d04836bacf3aeb9bb680 Mon Sep 17 00:00:00 2001 From: Younes Aassila <47226184+younesaassila@users.noreply.github.com> Date: Sat, 9 Dec 2023 19:42:55 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20onTabReplaced=20event=20handl?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/background/background.ts | 2 ++ src/background/handlers/onTabReplaced.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/background/handlers/onTabReplaced.ts 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.")); +}