ID:2970905
 
Codebase: Goonstation

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.
Found this on StackOverflow:

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.
In response to Lummox JR
Lummox JR wrote:
Found this on StackOverflow:

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.

The main script, processor script, and HTML file are all in the root directory when served. The processor script is accessible.



I found an SO answer that fixed it.

https://stackoverflow.com/questions/52760219/ let-within-electron-domexception-the-user-aborted-a-request/ 52774181#52774181

I forgot that BYOND sometimes doesn't serve the right MIME type, so I used the SO answer to derive some code that made it work.



It looks like these posts get resolved with votes?

There doesn't seem to be a way for me to resolve it, though it's resolved.

Login to reply.