Skip to content

Commit

Permalink
✨ Add onTabReplaced event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
younesaassila committed Dec 9, 2023
1 parent 97ea18d commit 9a4b27f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/background/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions src/background/handlers/onTabReplaced.ts
Original file line number Diff line number Diff line change
@@ -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."));
}

0 comments on commit 9a4b27f

Please sign in to comment.