Open muse254 opened 2 days ago
Go's Package js gives access to the WebAssembly host environment when using the js/wasm architecture. Its API is based on JavaScript semantics.
So we are just calling wasi with Go.
We need to find a way to not call browser apis, we are not bringing the browser. Maybe object construction that would mimic all that we need to a tee since it's just a standard?
Check node version 22+ and see if that works. It's a very recent addition.
Issue
Reference: https://github.com/globe-and-citizen/layer8-middleware/blob/11635a4080a31d8f7c865dc978a40eba38a27c85/middleware.go#L601-L606
The File API, which is only available in web browsers, is being used in a WASM module that is being compiled and run in Node.js. This results in a
ReferenceError: File is not defined
error because the File object is not available in Node.js.https://developer.mozilla.org/en-US/docs/Web/API/File This API is only available in browsers. Tried to init a WebWorker but that also doesn't happen server side.
The Go
syscall/js
provides a generic build that can be used server side and client side. The APIs in rust cannot target server side coming from a browser api: https://rustwasm.github.io/wasm-bindgen/api/web_sys/Build passes but the APIs are
ReferenceError: *** is not defined
Possible Solutions
We could isolate the APIs that we are manipulating server side that are tied to browsers written as Go modules. We can then call them via an ABI/FFI interface our code