Can the generated wasm be run in a browser ?
bogdancucosel opened this issue · comments
Hi!
First of all , great work on this.
It is not clear for me, since this is a wasi sdk, is it supposed to also be able to run in a browser ?
I tried something like:
<script>
const importObject = {
module: {},
env: {
memory: new WebAssembly.Memory({ initial: 256 }),
}
};
fetch('test-wasm.wasm')
.then(response =>
response.arrayBuffer())
.then(bytes =>
WebAssembly.instantiate(bytes, importObject))
.then(results => {
const Answer = results.instance.exports.Answer;
console.log(Answer());
}, error => {
console.log(error);
});
</script>
But I get "TypeError: WebAssembly.instantiate(): Import #0 module="wasi_snapshot_preview1" error: module is not an object or function"
Thank you very much
No, browsers does not implement WASI since it cannot access the host system directly.
But there are polyfills for that, replacing the functionality by invoking browser APIs - JS APIs.
@bogdancucosel This is what you are looking for: https://github.com/wasmerio/wasmer-js
@lbguilherme thanks a lot, I will try it