SteveSandersonMS / dotnet-wasi-sdk

Packages for building .NET projects as standalone WASI-compliant modules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

Thanks for the answer.
I see now, so basically I would need polyfills for the functions that are imported in the compiled wasi, right ?.
image

Is there somewhere I could grab these polyfills ?

Thank you again

@lbguilherme thanks a lot, I will try it