Reputation: 680
WebAssembly.instantiateStreaming fails when using a local relative path. Is there any way to disable this check or does anyone have any advice on another approach of getting around the problem? I'm trying to remove having the dependency of a web backend of my electron project.
<script>
WebAssembly.instantiateStreaming(fetch("relative/path/to/file.wasm", {
credentials: "same-origin",
headers: {
"Content-Type": "application/wasm"
}
}), {}).then(output => {
console.log(output);
}).catch(reason => {
console.log(reason);
});
</script>
Upvotes: 1
Views: 3716
Reputation: 20816
You can still use fetch()
as long as you switch to using instantiate()
instead of instantiateStreaming()
, since the former does not care about MIME types, while the latter does. Example:
const response = await fetch("relative/path/to/file.wasm");
const buffer = await response.arrayBuffer();
const output = await WebAssembly.instantiate(buffer);
console.log(output);
Upvotes: 0