Code:
JS code derived from an MDN Web Docs example.
audio_worklet_test_main_script.js
async function test_audio_worklet() {
const audioContext = new AudioContext();
await audioContext.audioWorklet.addModule("random-noise-processor.js");
const randomNoiseNode = new AudioWorkletNode(
audioContext,
"random-noise-processor",
);
randomNoiseNode.connect(audioContext.destination);
}
random-noise-processor.js
class RandomNoiseProcessor extends AudioWorkletProcessor {
process(inputs, outputs, parameters) {
const output = outputs[0];
output.forEach((channel) => {
for (let i = 0; i < channel.length; i++) {
channel[i] = Math.random() * 2 - 1;
}
});
return true;
}
}
registerProcessor("random-noise-processor", RandomNoiseProcessor);
Added the following script tag to browserOutput.html.
<script src="audio_worklet_test_main_script.js" type="text/javascript"></script>
Added the following strings to the
chatResources
list in /datum/chatOutput/proc/load()
that's in browserOutput.dm."browserassets/js/audio_worklet_test/random-noise-processor.js",
"browserassets/js/audio_worklet_test/audio_worklet_test_main_script.js",
Problem description:
Whenever I try to run
test_audio_worklet()
in DevTools, I get the following error.Uncaught (in promise) AbortError: Unable to load a worklet's module.
- The main and processor scripts are both accessible from the browser
-
window.isSecureContext
is true
- I can run this on pywebview with edgechromium set as the GUI, so it probably isn't an WebView2 issue
I did not find any reference to AudioWorklets when searching the forum.
https://stackoverflow.com/questions/64170251/ angular-electron-audioworklet-addmodule-error-domexception-t he-user-aborted
I suspect the problem is you're not passing the path to addModule(), just the filename. The URI of the module will be relative to the document that includes audio_worklet_test_main_script.js, not to audio_worklet_test_main_script.js itself.