Search code examples
javascriptweb-audio-api

AudioWorklet DOMException error when loading modules


I'm working on a WebAudio application that requires AudioWorklets and needs functions from many different scripts to be used in the process() function. Therefore, I'm trying to load said scripts in the processor script (frictionProcessor.js) with the import command as shown:

import {MAX_ERROR, MAX_ITERATIONS} from "./utilities.js";  
class FrictionProcessor extends AudioWorkletProcessor {...}
registerProcessor('frictionProcessor', FrictionProcessor);

where utilities.js is:

//Constants
const MAX_ERROR = 0.001;
const MAX_ITERATIONS = 50;
const MAX_POS = 10000.0;
const LCG_MULT = 1664525;
const LCG_ADD = 1013904223;

This gives the error: Uncaught (in promise) DOMException: The user aborted a request.
This error disappears when the line with the import is commented, but I need to load a lot of modules (not only the one shown here), so just not using it is not a workaround.

The closest question I've found is: AudioWorklet error: DOMException: The user aborted a request . However, this was not of much help, because I am not sure of how to serve the worklet-processor with application/javascript since it is loaded with the addModule function.

On the other hand, I've tried the design-pattern example codes from https://developers.google.com/web/updates/2018/06/audio-worklet-design-pattern , and they work fine.

I'm using Chrome 69 and Web Server for Chrome as the local host.

Does anybody know why this is happening, or how to avoid it? The error is recurrent and not quite self-explanatory.

Thank you


Solution

  • Perhaps your utilities.js should be:

    const MAX_ERROR = 0.001;
    const MAX_ITERATIONS = 50;
    const MAX_POS = 10000.0;
    const LCG_MULT = 1664525;
    const LCG_ADD = 1013904223;
    
    export {
      MAX_ERROR,
      MAX_ITERATIONS,
      MAX_POS,
      LCG_MULT,
      LCG_ADD,
    };
    

    Also any evaluation/parse error will result in a DOMException. I agree that this this could be improved. I filed a bug for it.