v160 · multimedia · web audio
Bootstrap-processor migration
Before the shared port, the only way into AudioWorkletGlobalScope was to construct an AudioWorkletNode whose processor did nothing but relay messages — Emscripten output and MOD players ship exactly that. This page runs the legacy workaround and the spec path side by side on the same module, then probes the edges you hit while migrating.
Probing this browser…
Side by side: deliver a config object to global scope
Legacy: bootstrap processor
await ctx.audioWorklet.addModule(url);
const boot = new AudioWorkletNode(ctx, "bootstrap");
boot.port.postMessage({ type: "config", … });
- result
- not run
Spec: shared port
await ctx.audioWorklet.addModule(url);
ctx.audioWorklet.port.postMessage({ type: "config", … });
Edge probes
| probe | observed | verdict |
|---|---|---|
| Press “Run edge probes”. | ||
migration pattern
async function globalScopePort(ctx) {
if ("port" in AudioWorklet.prototype) return ctx.audioWorklet.port; // Chrome 160+, Firefox 138+
return new AudioWorkletNode(ctx, "bootstrap").port; // legacy fallback
}
// In the module, wire ONE handler to whichever end arrives:
if (typeof port === "object" && port) port.onmessage = (e) => handle(e.data, port);
registerProcessor("bootstrap", class extends AudioWorkletProcessor {
constructor() { super(); this.port.onmessage = (e) => handle(e.data, this.port); }
process() { return false; } // never renders: it only existed to borrow a port
});
Rows labelled observed describe what this engine did; the spec text defines the port pair and the close() note, but not every ordering detail. The WebAssembly.Module row matters for Emscripten-style loaders: a compiled module can only be shared within an agent cluster, so this page shows the portable alternative — transfer the bytes and compile inside the worklet.