Loading the binary
Since it was built on Go, the binary requires that you preload the wasm_exec.js library file that comes with your Go instance. You can find out more on how to locate it here.

The Go-WASM namespace

Our build's target OS is Javascript, so each of our functions must be bound to a variable in the JS runtime environment. Following the naming convention from this repo, they live under global.__gobridge__ like so:
1
func1 -> global.__gobridge__.func1
Copied!
to avoid polluting the global object.

Loading to a web page

Provided you have wasm_exec.js and privacy.wasm served, you can load it using this HTML snippet:
1
<script src="wasm_exec.js"></script>
2
<script>
3
const go = new Go();
4
WebAssembly.instantiateStreaming(fetch("privacy.wasm"), go.importObject).then((result) => {
5
go.run(result.instance);
6
});
7
</script>
Copied!
or this Javascript snippet:
1
require("./wasm_exec")
2
const go = new Go();
3
let inst;
4
5
if (!WebAssembly.instantiateStreaming) {
6
WebAssembly.instantiateStreaming = async (resp, importObject) => {
7
const source = await (await resp).arrayBuffer();
8
return await WebAssembly.instantiate(source, importObject);
9
};
10
}
11
let result = await WebAssembly.instantiateStreaming(fetch(fileName), go.importObject);
12
inst = result.instance;
13
go.run(inst);
Copied!
Look for the log message WASM loading finished to verify that it was loaded, or you can use the console
Last modified 10mo ago