diff --git a/src/AudioWorklet.js b/src/AudioWorklet.js index 04afefd..9a5edc3 100644 --- a/src/AudioWorklet.js +++ b/src/AudioWorklet.js @@ -376,6 +376,10 @@ class AudioWorklet { return meta.includes('base64') ? atob(body) : decodeURIComponent(body) } + if (url.startsWith('blob:')) { + return await fetch(url).then(res => res.text()) + } + // Dynamic import fs/path — works in Node.js, throws in browser let fs, path try { fs = await import('fs'); path = await import('path') } catch { diff --git a/test/AudioWorklet.test.js b/test/AudioWorklet.test.js index 0835e2b..a084b61 100644 --- a/test/AudioWorklet.test.js +++ b/test/AudioWorklet.test.js @@ -160,6 +160,22 @@ test('AudioWorklet > addModule with base64 data URI', async () => { ok(node, 'base64 data URI works') }) +test('AudioWorklet > addModule with blob URI', async () => { + let ctx = await mkCtx() + let code = `class P extends AudioWorkletProcessor { + process() { return true } + }; registerProcessor('blob-proc', P)` + let url = URL.createObjectURL(new Blob([code], { type: 'text/javascript' })) + + try { + await ctx.audioWorklet.addModule(url) + let node = new AudioWorkletNode(ctx, 'blob-proc') + ok(node, 'blob URI works') + } finally { + URL.revokeObjectURL(url) + } +}) + test('AudioWorklet > message ports are entangled', async () => { let ctx = await mkCtx() await ctx.audioWorklet.addModule(scope => scope.registerProcessor('msg', AudioWorkletProcessor))