Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XMLHttpRequest is not defined when running emscripten-built AudioWorklet with preloaded files #15925

Open
paulfd opened this issue Jan 8, 2022 · 3 comments

Comments

@paulfd
Copy link

paulfd commented Jan 8, 2022

Please include the following in your bug report:

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 2.0.34 (0d24418f0eac4828f096ee070dae8472d427edaa)
clang version 14.0.0 (https://github.com/llvm/llvm-project 3d39612b3dd3f6b67ee63da305d30606abbe7287)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/paul/source/emsdk/upstream/bin

Failing command line in full:
Compiling/linkin works out. I compiled with --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/assets in a CMake project. I do get the js file and the .data file.

Error
I use emscripten in an AudioWorklet scenario.
I would like to preload a set of files to be accessed by the C++ sources.
When loading the file however, I have the following error in the JS Chrome console:

sound-engine.wasm.js:48 Uncaught ReferenceError: XMLHttpRequest is not defined
    at fetchRemotePackage (sound-engine.wasm.js:48)
    at loadPackage (sound-engine.wasm.js:102)
    at sound-engine.wasm.js:196
    at sound-engine.wasm.js:198

I am very newb when it comes to web technologies. I wonder if this is because AudioWorklets don't really start in a javascript environment where XMLHttpRequest are available? To be clearer, I'm supposed to load the processor module through this._context.audioWorklet.addModule('./batteur-processor.js'), which in turns imports the WASM file. Maybe this addModule function doesn't provide XMLHttpRequest? Any pointer towards a solution would be appreciated! Thanks!

@sbc100
Copy link
Collaborator

sbc100 commented Jan 8, 2022

There are some folks who have been looking into supporting running in AudioWorklet, but AFAIK nothing official has landed yet. If you search for AudioWorklet in the open issues and PRs you should be able to find out more about the current state of play.

@Jonathhhan
Copy link
Contributor

Jonathhhan commented Jan 21, 2022

@paulfd I guess I had a similar issue. Whether you need to edit filepackeger.py or use -s ASSERTIONS=0 ?
Its described here (at the end of the thread): #12502
And @sbc100 is right, it is not official yet.

@seanmorris
Copy link
Contributor

You can work around this issue by using --embed-file in place of --preload-file. That will embed the data directly in your .wasm file rather than adding a .data file to load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants