Skip to content

Latest commit

 

History

History
87 lines (55 loc) · 1.6 KB

README.md

File metadata and controls

87 lines (55 loc) · 1.6 KB

Use Goja JS VM to send HTTP(s) requests from inside WASM

Instructions for this devcontainer

Tested with Go 1.21.6, Bun 1.0.25, Deno 1.40.0, Goja v0.0.0-20231027, goja_nodejs v0.0.0-20231122.

Preparation

  1. Open this repo in devcontainer, e.g. using Github Codespaces. Type or copy/paste following commands to devcontainer's terminal.

Building

  1. cd into the folder of this example:
cd browser-and-deno-goja
  1. Install Goja and goja_nodejs as libraries:
go get "github.com/dop251/goja"
go get "github.com/dop251/goja_nodejs"
  1. Compile the example:
GOOS=js GOARCH=wasm go build -o main.wasm main.go
  1. Copy the glue JS from Golang distribution to example's folder:
cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .

Test with browser

  1. Run simple HTTP server to temporarily publish project to Web:
python3 -m http.server

Codespace will show you "Open in Browser" button. Just click that button or obtain web address from "Forwarded Ports" tab.

  1. As index.html and a 24M-sized main.wasm are loaded into browser, refer to browser developer console to see the results.

Test with Node.js

Impossible yet due to golang/go#59605.

Test with Bun

  1. Install Bun:
curl -fsSL https://bun.sh/install | bash
  1. Run with Bun:
~/.bun/bin/bun bun.js

Test with Deno

  1. Install Deno:
curl -fsSL https://deno.land/x/install/install.sh | sh
  1. Run with Deno:
~/.deno/bin/deno run --allow-read --allow-net deno.js

Finish

Perform your own experiments if desired.