Go WebAssembly 在输入 http://localhost:8080/wasm_exec.html 时无法点击 运行

Go Web Assembly cannot Click Run when enter http://localhost:8080/wasm_exec.html

我是 Whosebug 和 golang web assembly 的新手

我在纠结这个问题:我写了一个测试代码

main.go

package main

func main(){
    println("hello world")
}

并且我生成了 main.wasm 并将 wasm_exec.js 和 wasm_exec.html 导入到工作目录

我也写一个网络服务器

package main

import (
    "flag"
    "log"
    "net/http"
)

var (
    listen = flag.String("listen", ":8080", "listen address")
    dir    = flag.String("dir", ".", "directory to serve")
)

func main() {
    flag.Parse()
    log.Printf("listening on %q...", *listen)
    err := http.ListenAndServe(*listen, http.FileServer(http.Dir(*dir)))
    log.Fatalln(err)
}

我用Chrome输入http://localhost:8080/wasm_exec.html

根据网上的资料,有一个"Run"按钮可以点击

但是,实际上我不能点击这个按钮

我真的很困惑

这是我关于 Whosebug 的第一个问题。

抱歉英语不好

从 Go WebAssembly 逐步 Hello World
web/main.go 文件:

package main

import (
    "log"
    "net/http"
)

func main() {
    http.Handle("/", http.FileServer(http.Dir(".")))
    err := http.ListenAndServe(":8080", nil)
    if err != nil {
        log.Fatal("ListenAndServe: ", err)
    }
}

main.go 文件:

package main

import "fmt"

func main() {
    fmt.Println("Hello World")
}

运行 Linux 终端中的以下命令(对于 Windows OS 将 cp 替换为 copy$GOROOT %GOROOT%):

GOOS=js GOARCH=wasm go build -o test.wasm
cp $GOROOT/misc/wasm/wasm_exec.html ./
cp $GOROOT/misc/wasm/wasm_exec.js ./

go run web/main.go

打开http://127.0.0.1:8080/wasm_exec.html

现在在浏览器中右键单击浏览器内部然后 select Inspect 然后 select Console 选项卡,现在是时候单击 Run 按钮,然后您将在浏览器控制台中看到 Hello World