blob: a839ef6b0a509eb16f886fd530f6deb1cd62120c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
<!doctype html>
<!--
Copyright 2018 The Go Authors. All rights reserved.
Copyright 2025 Florian Fischer
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>
<script src="js/wasm_exec.js"></script>
<style>
.loader {
border: 16px solid #f3f3f3;
border-top: 16px solid;
border-radius: 50%;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.container {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
</style>
</head>
<body>
<div style="width:0; height:0; overflow:hidden;">
<input id="hiddenInput"></input>
</div>
<div class="container" id="loader">
<div class="loader"></div>
<div id="url"></div>
</div>
<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 = "client.wasm";
}
document.getElementById("url").innerHTML = url;
WebAssembly.instantiateStreaming(fetch(url), go.importObject).then((result) => {
mod = result.module;
inst = result.instance;
let loader = document.getElementById("loader");
loader.remove();
go.run(inst);
}).catch((err) => {
console.error(err);
});
</script>
</body>
</html>
|