Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/AudioWorklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions test/AudioWorklet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading