diff --git a/mediapipe/web/graph_runner/wasm_mediapipe_lib.ts b/mediapipe/web/graph_runner/wasm_mediapipe_lib.ts index 714f42134..82a3a3f16 100644 --- a/mediapipe/web/graph_runner/wasm_mediapipe_lib.ts +++ b/mediapipe/web/graph_runner/wasm_mediapipe_lib.ts @@ -970,8 +970,17 @@ async function runScript(scriptUrl: string) { if (typeof importScripts === 'function') { importScripts(scriptUrl.toString()); } else { - await new Promise((resolve, reject) => { - fetch(scriptUrl).then(response => response.text()).then(text => Function(text)).then(resolve, reject); + const script = document.createElement('script'); + script.setAttribute('url', scriptUrl); + script.setAttribute('crossorigin', 'anonymous'); + return new Promise((resolve) => { + script.addEventListener('load', () => { + resolve(); + }, false); + script.addEventListener('error', () => { + resolve(); + }, false); + document.body.appendChild(script); }); } }