-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into no-stringify-inject
- Loading branch information
Showing
13 changed files
with
103 additions
and
125 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
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
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
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
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,20 +1,28 @@ | ||
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); | ||
|
||
const result = await func.apply(target, args); | ||
target.dispatchEvent( | ||
new CustomEvent('xkitinjectionresponse', { detail: { id, result } }) | ||
); | ||
} catch (exception) { | ||
target.dispatchEvent( | ||
new CustomEvent('xkitinjectionresponse', { detail: { id, exception } }) | ||
); | ||
} | ||
}); | ||
try { | ||
moduleCache[path] ??= await import(path); | ||
const func = moduleCache[path].default; | ||
|
||
if (target.isConnected === false) return; | ||
|
||
const result = await func.apply(target, args); | ||
target.dispatchEvent( | ||
new CustomEvent('xkitinjectionresponse', { detail: { id, result } }) | ||
); | ||
} catch (exception) { | ||
target.dispatchEvent( | ||
new CustomEvent('xkitinjectionresponse', { detail: { id, exception } }) | ||
); | ||
} | ||
}); | ||
|
||
document.documentElement.dispatchEvent(new CustomEvent('xkitinjectionready')); | ||
} |
Oops, something went wrong.