Use EMSCRIPTEN_FETCH_SYNCHRONOUS in C program compiled with Emscripten to send HTTP(s) requests from inside WASM
Tested with Emscripten v3.1.61.
- Open this repo in devcontainer, e.g. using Github Codespaces. Type or copy/paste following commands to devcontainer's terminal.
cd
into the folder of this example:
cd browser-sync-xhr
- Compile the example using Emscripten:
emcc -s FETCH=1 --proxy-to-worker -o main.js main.c
This command will output main.wasm
, main.js
, and main.worker.js
.
- Run simple HTTP server to temporarily publish project to Web:
python3 -m http.server
Codespace will show you "Open in Browser" button. Just click that button or obtain web address from "Forwarded Ports" tab.
- As
index.html
, JS files, and a 21k-sizedmain.wasm
are loaded into browser, refer to browser developer console to see the results.
Perform your own experiments if desired.