From 8d9cdb86dcf837cc59be07761bd23176bbbe6c9f Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Mon, 14 Nov 2022 01:24:32 -0800 Subject: [PATCH] Internal change PiperOrigin-RevId: 488294157 --- mediapipe/web/graph_runner/wasm_mediapipe_lib.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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); }); } }