Skip to content

Commit f41d0e8

Browse files
committed
Cleaning up the map of redirects if a tab was closed
1 parent ed60fe8 commit f41d0e8

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/background/browserAction.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,14 @@ browser.storage.onChanged.addListener((changes, areaName) => {
7474

7575
const redirectedToTwitch = {};
7676

77+
7778
console.log('location', window.location.href);
7879

7980
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
8081
if (changeInfo.status === 'loading' && changeInfo.url) {
8182
console.log('changeInfo', changeInfo);
82-
if (
83-
!redirectedToTwitch[tabId] &&
84-
// if redirecting within twitch
85-
twitchUrlRegexp.test(changeInfo.url)
86-
// // or reloading the twitch page
87-
// || !changeInfo.url && twitchUrlRegexp.test(tab.url)
88-
) {
83+
// if redirecting within twitch
84+
if (!redirectedToTwitch[tabId] && twitchUrlRegexp.test(changeInfo.url)) {
8985
console.log('valid url', (changeInfo || tab).url);
9086
unlockForTab(tabId);
9187
redirectedToTwitch[tabId] = true;
@@ -105,6 +101,12 @@ browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
105101
}
106102
});
107103

104+
browser.tabs.onRemoved.addListener((tabId) => {
105+
if (redirectedToTwitch[tabId]) {
106+
delete redirectedToTwitch[tabId];
107+
}
108+
})
109+
108110
// browser.runtime.onMessage.addListener((message, sender) => {
109111
// console.log('sender', sender);
110112
// console.log('message', message);

0 commit comments

Comments
 (0)