aries-framework-go
aries-framework-go copied to clipboard
Proposal: always instantiate WASM via ArrayBuffer
This is a weak proposal, and tries to fix problems arising elsewhere, so take it with a grain of salt.
Here's the error I saw when converting the WebApp PWA bundling Aries as WASM into a mobile iOS app using https://ionicframework.com/:
Unhandled Promise Rejection: Error: failed to fetch wasm blob: Unexpected response MIME type. Expected ‘application/wasm’
Frameworks like these just copy files in when converting a WebApp or PWA into a native app and don't add a server that sends Content-Type headers based on files. This seems to have worked for them so far. In fact, they would probably require framework by framework fix to add such a functionality. (Interestingly, Android with its WebView doesn't have this issue and works just fine).
I've been able to work around the issue by simply fetching the WASM code into an ArrayBuffer and instantiating from there, very similar to what the polyfill does here: https://github.com/hyperledger/aries-framework-go/blob/bc126d50cdf9d4754e8b7976ccdbabe0376d35ed/cmd/aries-js-worker/src/worker-impl-web.js#L25-L29
e.g.:
diff --git a/eque-app/public/assets/worker-impl-web.js b/eque-app/public/assets/worker-impl-web.js
index 659a1b1..2259239 100644
--- a/eque-app/public/assets/worker-impl-web.js
+++ b/eque-app/public/assets/worker-impl-web.js
@@ -33,7 +33,15 @@ const go = new Go();
// Firefox is not including 'br' in fetch() for some reason.
// Cannot override Accept-Encoding header for the fetch call (would've liked to use brotli).
// Accept-Encoding is one of the forbidden headers of the Fetch API: https://fetch.spec.whatwg.org/#forbidden-header-name
-WebAssembly.instantiateStreaming(fetch(wasm), go.importObject).then(
+fetch(wasm).then(
+ (response) => {
+ return response.arrayBuffer();
+ }
+).then(
+ (bytes) => {
+ return WebAssembly.instantiate(bytes, go.importObject);
+ }
+).then(
(result) => {
go.run(result.instance);
},
Question is, what are the disadvantages? The WASM is ~8 MB which modern browsers and mobile devices should handle like a charm. Or is there something else?
One other benefit of indirect instantiation would be being able to display a progress bar perhaps?