WebAudio / web-audio-api

The Web Audio API v1.0, developed by the W3C Audio WG
https://webaudio.github.io/web-audio-api/
Other
1.05k stars 166 forks source link

Event handler for all errors in AudioWorkletProcessor #2548

Closed mehagar closed 1 year ago

mehagar commented 1 year ago

The current specification includes onprocessorerror (https://www.w3.org/TR/webaudio/#dom-audioworkletnode-onprocessorerror), but I would like to be able to get events from errors that may happen in other contexts.

For example, I have this:

class CustomAudioWorletProcessor extends AudioWorkletProcessor {
  constructor(options) {
    super();
    this.port.onmessage = ((message) => throw new Error('test exception'));
  }
}

onprocessorerror will not receive the test exception, because the error does not occur in the constructor. It is only later when I send a message to the worklet processor that the exception happens.

Is it possible to do this already? Ideally I would be able to register an event handler like so:

myAudioNode.onerror = (event) => { console.log('error in worklet') }
hoch commented 1 year ago

onprocessorerror gets triggered only by two cases: 1) The processor constructor. 2) The processor's process() function.

See https://webaudio.github.io/web-audio-api/#dom-audioworkletnode-onprocessorerror.

For your question, we have a plan to add an error handler on AudioWorkletGlobalScope, but the spec work has not been started: https://github.com/WebAudio/web-audio-api/issues/2431

hoch commented 1 year ago

Closing this since we have #2431 to track the same problem.