如何在 chrome 扩展中包含 golang 编译的 wasm 文件?

And*_*row 10 javascript go google-chrome-extension webassembly chrome-extension-manifest-v3

我已经尝试过这里的一切:

Golang 到 wasm 编译

我无法过去:

WebAssembly.instantiate(buffer, {wasi_snapshot_preview1: ""})
WebAssembly.instantiate(buffer, {go: {debug: ""}})

// (i'm making them empty strings just to show I need to add the key but obviously they are not strings.)
Run Code Online (Sandbox Code Playgroud)

即我收到如下错误:

Failed to load WebAssembly module: TypeError: WebAssembly.instantiate(): Import #0 module="wasi_snapshot_preview1" error: module is not an object or function
Run Code Online (Sandbox Code Playgroud)

或模块debugruntime.resetMemoryDataView或所有内容wasm_exec.js

但如果我使用simple.wasm来自:

https://github.com/inflatablegrade/Extension-with-WASM

有用!那 wasm 一定是用 c 或 rust 编译的而不是 golang 吗?有没有办法让这项工作从 go 开始?

PS,这Extension-with-WASM是清单 2.0,但我让它与 3.0 一起工作:

https://github.com/inflatablegrade/Extension-with-WASM/issues/1

Rob*_*nas 0

尝试使用 -Oz 标志进行编译GOOS=js GOARCH=wasm go build -o main.wasm -ldflags="-s -w" -gcflags="-trimpath=${PWD}" -trimpath .

并建立GOOS=js GOARCH=wasm go build -o main.wasm -tags=js_wasm_profiling -ldflags="-s -w" -gcflags="-trimpath=${PWD}" -trimpath .