Add safety checks for infinite loops.

This commit is contained in:
Bauke 2022-10-21 18:49:16 +02:00
parent 696dd8fde8
commit 3e59d0e13b
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 14 additions and 0 deletions

View File

@ -19,7 +19,17 @@ browser.runtime.onInstalled.addListener(async () => {
});
browser.webNavigation.onBeforeNavigate.addListener(async (details) => {
const {latestTime} = await browser.storage.local.get('latestTime');
const redirectDelta = Date.now() - (latestTime ?? 0);
if (redirectDelta < 100) {
return;
}
const url = new URL(details.url);
const {latestUrl} = await browser.storage.local.get('latestUrl');
if (redirectDelta < 30_000 && url.href === latestUrl) {
return;
}
for (const [id, parameters] of Object.entries(
await browser.storage.local.get(),
@ -32,6 +42,10 @@ browser.webNavigation.onBeforeNavigate.addListener(async (details) => {
if (redirect.isMatch(url)) {
const redirectedUrl = redirect.redirect(url);
await browser.tabs.update({url: redirectedUrl.href});
await browser.storage.local.set({
latestTime: Date.now(),
latestUrl: url.href,
});
break;
}
}