-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
42 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Placeholder for internal dependency on jsloader | ||
// Placeholder for internal dependency on trusted resource url | ||
|
||
/** | ||
* Fetches each URL in urls, executes them one-by-one in the order they are | ||
* passed, and then returns (or throws if something went amiss). | ||
*/ | ||
declare function importScripts(...urls: Array<string|URL>): void; | ||
|
||
// Quick helper to run the given script safely | ||
export async function runScript(scriptUrl: string) { | ||
if (typeof importScripts === 'function') { | ||
importScripts(scriptUrl.toString()); | ||
} else { | ||
const script = document.createElement('script'); | ||
script.setAttribute('src', scriptUrl); | ||
script.setAttribute('crossorigin', 'anonymous'); | ||
return new Promise<void>((resolve, revoke) => { | ||
script.addEventListener('load', () => { | ||
resolve(); | ||
}, false); | ||
script.addEventListener('error', e => { | ||
revoke(e); | ||
}, false); | ||
document.body.appendChild(script); | ||
}); | ||
} | ||
} |