Interact with browser from Go. Manually-crafted WebAPI interoperation library.
gweb -- strictly typed WebAPI library on top of syscall/js. Like flow or TypeScript but for Go. You need it if you want to interact with browser from wasm-compiled Go program.
See examples on gweb.orsinium.dev.
syscall/jsthat helps you to avoid runtime errors (you'll get them a lot with raw
syscall/js).
js.Value. So if something missed, you can always fall back to the classic
syscall/jscalls.
GOOS=js GOARCH=wasm go get github.com/life4/gweb
If you're using VSCode, it's recommend to create a
.vscode/settings.jsonfile in your project with the following content:
{ "go.toolsEnvVars": { "GOARCH": "wasm", "GOOS": "js", }, "go.testEnvVars": { "GOARCH": "wasm", "GOOS": "js", }, }
In the beautiful JS world anything at any time can be
nullor
undefined. Check it when you're not sure:
doc := web.GetWindow().Document() el := doc.Element("some-element-id") if el.Type() == js.TypeNull { // handle error }
If something is missed, use
syscall/js-like methods (
Get,
Set,
Calletc):
doc := web.GetWindow().Document() el := doc.Element("some-element-id") name = el.Get("name").String()
GWeb is a collection of a few packages:
web(docs) -- window, manipulations with DOM.
audio(docs) -- Web Audio API. Use
web.GetWindow().AudioContext()as an entry point.
canvas(docs) -- canvas-related objects. Use
web.GetWindow().Document().CreateCanvas()to get started.
css(docs) -- manage styles for HTML elements.
Contributions are welcome! GWeb is a Open-Source project and you can help to make it better. Some ideas what can be improved:
And even if you don't have spare time for making PRs, you still can help by talking to your friends and subscribers about GWeb. Thank you :heart: