diff options
Diffstat (limited to 'html')
| -rw-r--r-- | html/wasm.html | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/html/wasm.html b/html/wasm.html new file mode 100644 index 00000000..7b135308 --- /dev/null +++ b/html/wasm.html @@ -0,0 +1,64 @@ +<!doctype html> +<!-- +Copyright 2018 The Go Authors. All rights reserved. +Use of this source code is governed by a BSD-style +license that can be found in the LICENSE file. +--> +<html> + +<head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> + <title>Go wasm</title> + <script src="eruda.js"></script> + <script>eruda.init();</script> +</head> + +<body> + <script src="js/wasm_exec.js"></script> + <script> + if (!WebAssembly.instantiateStreaming) { // polyfill + WebAssembly.instantiateStreaming = async (resp, importObject) => { + const source = await (await resp).arrayBuffer(); + return await WebAssembly.instantiate(source, importObject); + }; + } + + const go = new Go(); + let mod, inst; + let url = new URLSearchParams(window.location.search).get("wasm"); + if (!url) { + // url = "dummy-ui/dummy-ui.wasm"; + // url = "client/client.wasm"; + url = "ai-companion.wasm"; + } + + + WebAssembly.instantiateStreaming(fetch(url), go.importObject).then((result) => { + document.getElementById("wasmName").innerHTML = url; + mod = result.module; + inst = result.instance; + document.getElementById("runButton").disabled = false; + }).catch((err) => { + console.error(err); + }); + + async function run() { + let wN = document.getElementById("wasmName"); + let rB = document.getElementById("runButton"); + document.body.removeChild(wN); + document.body.removeChild(rB); + + console.clear(); + await go.run(inst); + } + </script> + <div style="width:0; height:0; overflow:hidden;"> + <input id="hiddenInput"></input> + </div> + <div id="wasmName"></div> + + <button onClick="run();" id="runButton" disabled>Run</button> +</body> + +</html> |
