Add safety checks for infinite loops.
This commit is contained in:
parent
696dd8fde8
commit
3e59d0e13b
|
@ -19,7 +19,17 @@ browser.runtime.onInstalled.addListener(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
browser.webNavigation.onBeforeNavigate.addListener(async (details) => {
|
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 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(
|
for (const [id, parameters] of Object.entries(
|
||||||
await browser.storage.local.get(),
|
await browser.storage.local.get(),
|
||||||
|
@ -32,6 +42,10 @@ browser.webNavigation.onBeforeNavigate.addListener(async (details) => {
|
||||||
if (redirect.isMatch(url)) {
|
if (redirect.isMatch(url)) {
|
||||||
const redirectedUrl = redirect.redirect(url);
|
const redirectedUrl = redirect.redirect(url);
|
||||||
await browser.tabs.update({url: redirectedUrl.href});
|
await browser.tabs.update({url: redirectedUrl.href});
|
||||||
|
await browser.storage.local.set({
|
||||||
|
latestTime: Date.now(),
|
||||||
|
latestUrl: url.href,
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue