From bf9a265f652c969c27d222cf292971bbaa1ca746 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Wed, 31 May 2023 14:04:20 +0200 Subject: [PATCH] fix(wasm): Avoid throwing an error when WASM modules are loaded from blobs --- packages/wasm/src/registry.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/wasm/src/registry.ts b/packages/wasm/src/registry.ts index 765b47026f00..2005c840b630 100644 --- a/packages/wasm/src/registry.ts +++ b/packages/wasm/src/registry.ts @@ -45,11 +45,22 @@ export function registerModule(module: WebAssembly.Module, url: string): void { if (oldIdx >= 0) { IMAGES.splice(oldIdx, 1); } + + let debugFileUrl = null; + if (debugFile) { + try { + debugFileUrl = new URL(debugFile, url).href; + } catch { + // debugFile could be a blob URL which causes the URL constructor to throw + // for now we just ignore this case + } + } + IMAGES.push({ type: 'wasm', code_id: buildId, code_file: url, - debug_file: debugFile ? new URL(debugFile, url).href : null, + debug_file: debugFileUrl, debug_id: `${buildId.padEnd(32, '0').slice(0, 32)}0`, }); }