-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix extension restarts in Firefox (#1551)
- Loading branch information
1 parent
526466b
commit 9383a00
Showing
2 changed files
with
32 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
const moduleCache = {}; | ||
'use strict'; | ||
|
||
document.documentElement.addEventListener('xkitinjectionrequest', async event => { | ||
const { detail, target } = event; | ||
const { id, path, args } = JSON.parse(detail); | ||
{ | ||
const moduleCache = {}; | ||
|
||
try { | ||
moduleCache[path] ??= await import(path); | ||
const func = moduleCache[path].default; | ||
document.documentElement.addEventListener('xkitinjectionrequest', async event => { | ||
const { detail, target } = event; | ||
const { id, path, args } = JSON.parse(detail); | ||
|
||
if (target.isConnected === false) return; | ||
try { | ||
moduleCache[path] ??= await import(path); | ||
const func = moduleCache[path].default; | ||
|
||
const result = await func.apply(target, args); | ||
target.dispatchEvent( | ||
new CustomEvent('xkitinjectionresponse', { detail: JSON.stringify({ id, result }) }) | ||
); | ||
} catch (exception) { | ||
target.dispatchEvent( | ||
new CustomEvent('xkitinjectionresponse', { | ||
detail: JSON.stringify({ | ||
id, | ||
exception: { | ||
message: exception.message, | ||
name: exception.name, | ||
stack: exception.stack, | ||
...exception | ||
} | ||
if (target.isConnected === false) return; | ||
|
||
const result = await func.apply(target, args); | ||
target.dispatchEvent( | ||
new CustomEvent('xkitinjectionresponse', { detail: JSON.stringify({ id, result }) }) | ||
); | ||
} catch (exception) { | ||
target.dispatchEvent( | ||
new CustomEvent('xkitinjectionresponse', { | ||
detail: JSON.stringify({ | ||
id, | ||
exception: { | ||
message: exception.message, | ||
name: exception.name, | ||
stack: exception.stack, | ||
...exception | ||
} | ||
}) | ||
}) | ||
}) | ||
); | ||
} | ||
}); | ||
); | ||
} | ||
}); | ||
|
||
document.documentElement.dispatchEvent(new CustomEvent('xkitinjectionready')); | ||
document.documentElement.dispatchEvent(new CustomEvent('xkitinjectionready')); | ||
} |