Skip to content

Commit

Permalink
Fixed annoying infinite "Loading webpage" message
Browse files Browse the repository at this point in the history
  • Loading branch information
ingui-n committed Dec 12, 2024
1 parent 84f5ab2 commit a0e87bb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
11 changes: 8 additions & 3 deletions src/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ export const updateCurrentTab = async () => {
return tab;
};

export const getTabByUrl = async url => {
const [tab] = await browser.tabs.query({url});
return tab;
export const getTabByUrl = async (url, id) => {
const tabs = await browser.tabs.query({url});

for (const tab of tabs) {
if (tab.id === id) {
return tab;
}
}
};

export const isConnectionOk = async tabId => {
Expand Down
22 changes: 11 additions & 11 deletions src/popup/popup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export default function Popup() {
(async () => {
setTimeout(() => {
setShowContent(true);
setTimeout(resetBgColorAnimation, 20);
}, 1250);
setTimeout(resetBgColorAnimation, 50);
}, 1500);
})();
}
}
Expand All @@ -47,14 +47,14 @@ export default function Popup() {
if (curr.status === 'complete')
return;

const tabListenerHandler = async (tabId, changeInfo) => {
if (tabId === curr.id && changeInfo.status === 'complete') {
browser.tabs.onUpdated.removeListener(tabListenerHandler);
setCurrentTab(await getTabByUrl(curr.url));
}
};
const interval = setInterval(async () => {
const tab = await getTabByUrl(curr.url, curr.id);

browser.tabs.onUpdated.addListener(tabListenerHandler);
if (tab.id === curr.id && tab.status === 'complete') {
clearInterval(interval);
setCurrentTab(tab);
}
}, 300);
})();
}, []);

Expand Down Expand Up @@ -100,7 +100,7 @@ export default function Popup() {
}

setShowContent(true);
setTimeout(resetBgColorAnimation, 20);
setTimeout(resetBgColorAnimation, 50);
};

const showMessage = ({message, loading = false, showBtn = false, btnText = ''}) => {
Expand Down Expand Up @@ -146,7 +146,7 @@ export default function Popup() {

if (isStopped) {
setShowContent(true);
setTimeout(resetBgColorAnimation, 20);
setTimeout(resetBgColorAnimation, 50);
}
};

Expand Down

0 comments on commit a0e87bb

Please sign in to comment.