Skip to content

Commit 6a751e0

Browse files
committed
2 parents 6ad6f4c + 992c157 commit 6a751e0

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/AudioWorklet.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ class AudioWorklet {
376376
return meta.includes('base64') ? atob(body) : decodeURIComponent(body)
377377
}
378378

379+
if (url.startsWith('blob:')) {
380+
return await fetch(url).then(res => res.text())
381+
}
382+
379383
// Dynamic import fs/path — works in Node.js, throws in browser
380384
let fs, path
381385
try { fs = await import('fs'); path = await import('path') } catch {

test/AudioWorklet.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@ test('AudioWorklet > addModule with base64 data URI', async () => {
160160
ok(node, 'base64 data URI works')
161161
})
162162

163+
test('AudioWorklet > addModule with blob URI', async () => {
164+
let ctx = await mkCtx()
165+
let code = `class P extends AudioWorkletProcessor {
166+
process() { return true }
167+
}; registerProcessor('blob-proc', P)`
168+
let url = URL.createObjectURL(new Blob([code], { type: 'text/javascript' }))
169+
170+
try {
171+
await ctx.audioWorklet.addModule(url)
172+
let node = new AudioWorkletNode(ctx, 'blob-proc')
173+
ok(node, 'blob URI works')
174+
} finally {
175+
URL.revokeObjectURL(url)
176+
}
177+
})
178+
163179
test('AudioWorklet > message ports are entangled', async () => {
164180
let ctx = await mkCtx()
165181
await ctx.audioWorklet.addModule(scope => scope.registerProcessor('msg', AudioWorkletProcessor))

0 commit comments

Comments
 (0)