Internal change

PiperOrigin-RevId: 488294157
This commit is contained in:
Sebastian Schmidt 2022-11-14 01:24:32 -08:00 committed by Copybara-Service
parent 6c0ca947de
commit 8d9cdb86dc

View File

@ -970,8 +970,17 @@ async function runScript(scriptUrl: string) {
if (typeof importScripts === 'function') { if (typeof importScripts === 'function') {
importScripts(scriptUrl.toString()); importScripts(scriptUrl.toString());
} else { } else {
await new Promise((resolve, reject) => { const script = document.createElement('script');
fetch(scriptUrl).then(response => response.text()).then(text => Function(text)).then(resolve, reject); script.setAttribute('url', scriptUrl);
script.setAttribute('crossorigin', 'anonymous');
return new Promise<void>((resolve) => {
script.addEventListener('load', () => {
resolve();
}, false);
script.addEventListener('error', () => {
resolve();
}, false);
document.body.appendChild(script);
}); });
} }
} }