AudioWorkletGlobalScope: registerProcessor() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.

The registerProcessor method of the AudioWorkletGlobalScope interface registers a class constructor derived from AudioWorkletProcessor interface under a specified name.

Syntax

js
registerProcessor(name, processorCtor)

Parameters

name

A string representing the name under which the processor will be registered.

processorCtor

The constructor of a class derived from AudioWorkletProcessor.

Note: A key-value pair { name: constructor } is saved internally in the AudioWorkletGlobalScope once the processor is registered. The name is to be referred to when creating an AudioWorkletNode based on the registered processor. A new processor by the given name is internally created and associated with the new node.

Return value

None (undefined).

Exceptions

NotSupportedError DOMException

Thrown under the following conditions:

  • The name is an empty string.
  • A constructor under the given name is already registered. Registering the same name twice is not allowed.
TypeError

Thrown under the following conditions:

Examples

In this example we create a custom AudioWorkletNode that outputs silence.

First, we need to define a custom AudioWorkletProcessor and register it. Note that this should be done in a separate file.

js
// test-processor.js
class TestProcessor extends AudioWorkletProcessor {
  process(inputs, outputs, parameters) {
    return true;
  }
}

registerProcessor("test-processor", TestProcessor);

Next, in our main script file we'll load the processor, create an instance of AudioWorkletNode — passing it the processor name that we used when calling registerProcessor — and connect it to an audio graph.

js
const audioContext = new AudioContext();
await audioContext.audioWorklet.addModule("test-processor.js");
const node = new AudioWorkletNode(audioContext, "test-processor");
node.connect(audioContext.destination);

Specifications

Specification
Web Audio API
# dom-audioworkletglobalscope-registerprocessor

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
registerProcessor
Chrome – Full support
Chrome 66 (Release date: 2018-04-17)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 76 (Release date: 2020-05-05)
footnote Full support
Opera – Full support
Opera 53 (Release date: 2018-05-10)
footnote Full support
Safari – Full support
Safari 14.1 (Release date: 2021-04-26)
footnote Full support
Chrome Android – Full support
Chrome Android 66 (Release date: 2018-04-17)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 47 (Release date: 2018-07-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 14.5 (Release date: 2021-04-26)
footnote Full support
Samsung Internet – Full support
Samsung Internet 9 (Release date: 2018-09-15)
footnote Full support
WebView Android – Full support
WebView Android 66 (Release date: 2018-04-17)
footnote Full support
WebView on iOS – Full support
WebView on iOS 14.5 (Release date: 2021-04-26)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also