mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
Clean up webrequest autocommands properly
This commit is contained in:
parent
2d0d0da5f9
commit
c37ed9893e
1 changed files with 9 additions and 2 deletions
|
@ -15,7 +15,7 @@ export const requestEvents = Object.keys(requestEventExpraInfoSpecMap)
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
export const LISTENERS: Record<string, Record<string, Function>> = {}
|
export const LISTENERS: Record<string, Record<string, Function>> = {}
|
||||||
|
|
||||||
export const registerWebRequestAutocmd = (
|
export const registerWebRequestAutocmd = async (
|
||||||
requestEvent: string,
|
requestEvent: string,
|
||||||
pattern: string,
|
pattern: string,
|
||||||
func: string,
|
func: string,
|
||||||
|
@ -23,8 +23,15 @@ export const registerWebRequestAutocmd = (
|
||||||
// I'm being lazy - strictly the functions map strings to void | blocking responses
|
// I'm being lazy - strictly the functions map strings to void | blocking responses
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
const listener = eval(func) as Function
|
const listener = eval(func) as Function
|
||||||
if (!LISTENERS[requestEvent]) LISTENERS[requestEvent] = {}
|
|
||||||
|
if (!(requestEvent in LISTENERS)) {
|
||||||
|
LISTENERS[requestEvent] = {}
|
||||||
|
}
|
||||||
|
if (pattern in LISTENERS[requestEvent]) {
|
||||||
|
await unregisterWebRequestAutocmd(requestEvent, pattern)
|
||||||
|
}
|
||||||
LISTENERS[requestEvent][pattern] = listener
|
LISTENERS[requestEvent][pattern] = listener
|
||||||
|
|
||||||
return browser.webRequest["on" + requestEvent].addListener(
|
return browser.webRequest["on" + requestEvent].addListener(
|
||||||
listener,
|
listener,
|
||||||
{ urls: [pattern] },
|
{ urls: [pattern] },
|
||||||
|
|
Loading…
Add table
Reference in a new issue