I am attempting to get this tutorial (here: https://www.hellorust.com/demos/add/index.html) to work, and it seems that whatever I do, I cannot get the WebAssembly MDN reserved f
Considering you can't change the server to properly return application/wasm
for .wasm
file requests for any reason, you can work around the issue by changing the way you instantiate the WebAssembly module. Instead of doing this:
WebAssembly.instantiateStreaming(fetch("./add.wasm")).then(obj => /* ... */)
Do this:
const response = await fetch("add.wasm");
const buffer = await response.arrayBuffer();
const obj = await WebAssembly.instantiate(buffer);
obj.instance.exports.exported_func();
Or the equivalent using then()
if you cannot use async/await
.
In practice, what my workaround does is to avoid calling instantiateStreaming()
, which must check the MIME type returned by the server before proceeding (according to this specification). Instead, I call instantiate()
passing an ArrayBuffer
and avoid the check altogether.