Go Lang Web Assembly bindings for DOM, HTML etc

Overview

WebAPI

Go Language Web Assembly bindings for DOM, HTML etc

GoDoc

WARNING: The current API is in very early state and should be consider to be expremental. There is upcommig changed like moving types into multiple packages.

This library is trying to be feature complete and up to date with current standard to let everything a browser having to offect be available in WebAssembly in a Go API accessable. To achive this most of the code is generated from WebIDL files. WebIDL files can be found in different standard making it easiser to be up to date than handwritten binding code.

Example:

func main() {
    element := webapiall.GetWindow().Document().GetElementById("foo")
    // NOTE: After Go 1.12, the extra call to JSValue() will no loger   be needed
    button := webapiall.HTMLButtonElementFromJS(element.JSValue())
    button.SetValue("Hello World")
}

Roadmap

Milestone Status Description
1 Ongoing Be abto to read and and understand all of WebIDL syntax. Notible missing thing are namespace and union
2 Planned Easy up the syntax. Promise will be refactor and other places where simplifications can be done. Classes can be renamed like clipboard.ClipboardPermission to clipboard.Permission.
3 Planned API Stability with a predefined release schedule. Documentation and added examples

More infomation of missing stuff can be found on the generator status info.

Comments
  • Example_buttonTest() in example_test.go panics when button is clicked

    Example_buttonTest() in example_test.go panics when button is clicked

    Tested in both FF 83 and Chromium 86 with the following Go environment:

    GO111MODULE=""
    GOARCH="amd64"
    GOBIN=""
    GOCACHE="/home/smoyer1/.cache/go-build"
    GOENV="/home/smoyer1/.config/go/env"
    GOEXE=""
    GOFLAGS=""
    GOHOSTARCH="amd64"
    GOHOSTOS="linux"
    GOINSECURE=""
    GOMODCACHE="/home/smoyer1/go/pkg/mod"
    GONOPROXY=""
    GONOSUMDB=""
    GOOS="linux"
    GOPATH="/home/smoyer1/go:/usr/share/go-tools"
    GOPRIVATE=""
    GOPROXY="https://proxy.golang.org,direct"
    GOROOT="/opt/go/1.15.4"
    GOSUMDB="sum.golang.org"
    GOTMPDIR=""
    GOTOOLDIR="/opt/go/1.15.4/pkg/tool/linux_amd64"
    GCCGO="gccgo"
    AR="ar"
    CC="gcc"
    CXX="g++"
    CGO_ENABLED="1"
    GOMOD="/home/smoyer1/git/hnjobs/go.mod"
    CGO_CFLAGS="-g -O2"
    CGO_CPPFLAGS=""
    CGO_CXXFLAGS="-g -O2"
    CGO_FFLAGS="-g -O2"
    CGO_LDFLAGS="-g -O2"
    PKG_CONFIG="pkg-config"
    GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build286617590=/tmp/go-build -gno-record-gcc-switches"
    

    Compiled with:

    RUN GOOS=js GOARCH=wasm go build -o /app cmd/ui/ui.go
    

    The console provides the following call stack when the button is clicked:

    panic: ValueOf: invalid value wasm_exec.js:50:14
    <empty string> wasm_exec.js:50:14
    goroutine 6 [running]: wasm_exec.js:50:14
    syscall/js.ValueOf(0x1e5e0, 0x5ab88, 0x6, 0x7ff800010000000f) wasm_exec.js:50:14
    	/usr/local/go/src/syscall/js/js.go:219 +0x106 wasm_exec.js:50:14
    syscall/js.Value.Set(0x7ff8000100000012, 0x41a078, 0x52ef6, 0x6, 0x1e5e0, 0x5ab88) wasm_exec.js:50:14
    	/usr/local/go/src/syscall/js/js.go:314 +0x7 wasm_exec.js:50:14
    syscall/js.handleEvent() wasm_exec.js:50:14
    	/usr/local/go/src/syscall/js/func.go:97 +0x25
    

    I'd be happy to help track this down ... it appears that the JS value passed to the syscall/js ValueOf() function is perhaps a wrapped type and doesn't match any of the types in the case statement included there (see https://github.com/golang/go/blob/0e953add9656c32a788e06438cd7b533e968b7f8/src/syscall/js/js.go#L162). I've looked through the webapi code and all the JS values appear to (properly) be aliases which I would expect to match a case, so I'm at a loss for where to continue looking.

    opened by smoyer64 10
  • Is the repository / account abandoned ?

    Is the repository / account abandoned ?

    It's currently broken (at least partially) for current version of Go. I have a fixing PR since March, that has not been approved/responded: https://github.com/gowebapi/webapi/pull/11

    I'm happy to help support, if you add me as a member of gowebapi.

    cheers

    opened by janpfeifer 7
  • RFE Include WebVR

    RFE Include WebVR

    I'm very happy to find your project here. I was just about to try and write myself a WebIDL parser to do exactly this, so well done and thanks.

    Anyway I'm not sure the best way to provide feedback? Basically I'm wanting to do some WebGL (v1) via Go/WASM, and hopefully from that also include WebVR support. I can see that you have WebXR support, but there are not many browsers supporting that so far. Do you have any plans to add WebVR?

    So far I managed to get my Go WASM creating a 'canvas' element:

    	canvas := webapi.GetWindow().Document().CreateElement("canvas", &webapi.Union{js.ValueOf("dom.Node")})
    	canvas.SetId("mycanvas")
    app.AppendChild(&canvas.Node)
    

    And finally, I can see that you have some full screen support in dom.go, but I cant see a method to requestFullscreen() or am I missing something obvious there?

    Sorry to ask so many questions, and keep up the good work!

    macos10.12.4 go1.12

    opened by WhiteHexagon 7
  • Go 1.18 drops syscall.js.Wrapper

    Go 1.18 drops syscall.js.Wrapper

    Because of performance reasons Go is dropping js.Wrapper. I noticed this today, as I was trying out the 1.18.1 beta.

    I suspect it should be an easy fix, but I haven't yet dived into it. Hopefully the fix will be backwards compatible -- since it only removed functionality.

    I'll try to do post benchmarking in a wasm game I occasionally develop.

    opened by janpfeifer 2
  • Fix invalid comparison to js.Undefined() in go1.14.

    Fix invalid comparison to js.Undefined() in go1.14.

    After the go 1.14 update the file dom/helper.go was failing to compile for wasm (it would still compiles if not wasm). the underlying syscall/js Value type must have changed, is my guess.

    But in any case, it now offers the safer IsUndefined() method. So I added it to the core/js/js.go wrappers and changed helper.go to use it.

    opened by janpfeifer 2
  • TypedArray Unavailable (Go 1.13)

    TypedArray Unavailable (Go 1.13)

    Error trying to build using Go v1.13:

    "/go/src/github.com/gowebapi/webapi/core/js/js_js.go:56:19: undefined: js.TypedArray"

    I commented out the references to this type in your code to get it building. Is that appropriate?

    opened by rshaalan 2
  • Pointers to scalar values (*string, *int, *bool) fail ValueOf

    Pointers to scalar values (*string, *int, *bool) fail ValueOf

    Functions that get a pointer to a string/int/bool should dereference the pointers before passing them to any js functions

    For example

    // SetTextContent setting attribute 'textContent' with
    // type string (idl: DOMString).
    func (_this *Node) SetTextContent(value *string) {
    	input := value
    	_this.Value_JS.Set("textContent", input)
    }
    

    could be

    // SetTextContent setting attribute 'textContent' with
    // type string (idl: DOMString).
    func (_this *Node) SetTextContent(value *string) {
    	if value != nil {
    		input := *value
    		_this.Value_JS.Set("textContent", input)
    	}
    }
    

    otherwise it panics panic: ValueOf: invalid value

    Similar,

    func (_this *Node) CloneNode(deep *bool) (_result *Node) {
    	var (
    		_args [1]interface{}
    		_end  int
    	)
    	if deep != nil {
    		_p0 := deep
    		_args[0] = _p0
    		_end++
    	}
    	_returned := _this.Value_JS.Call("cloneNode", _args[0:_end]...)
    	var (
    		_converted *Node // javascript: Node _what_return_name
    	)
    	_converted = NodeFromJS(_returned)
    	_result = _converted
    	return
    }
    

    could be

    func (_this *Node) CloneNode(deep *bool) (_result *Node) {
    	var (
    		_args [1]interface{}
    		_end  int
    	)
    	if deep != nil {
    		_p0 := *deep
    		_args[0] = _p0
    		_end++
    	}
    	_returned := _this.Value_JS.Call("cloneNode", _args[0:_end]...)
    	var (
    		_converted *Node // javascript: Node _what_return_name
    	)
    	_converted = NodeFromJS(_returned)
    	_result = _converted
    	return
    }
    
    opened by thegrumpylion 1
  • How to use indexeddb?

    How to use indexeddb?

    Would you mind to create an example how to use indexeddb? I managed to open a db request but have no clue to get db instance from event like below. request := webapi.GetWindow().IndexedDB().Open("test", nil) request.SetOnupgradeneeded(domcore.EventHandlerToJS(func(event *domcore.Event) interface{} { /* javascript version is: var db = event.target.result; var objStore = db.createObjectStore("names", { autoIncrement : true }); */ return nil })) `

    opened by ghost 1
  • Problematic to bind NULL values in webgl

    Problematic to bind NULL values in webgl

    A typical pattern in WebGL is to bind a "null" value.

    E.g.

    gl.bindFramebuffer(gl.FRAMEBUFFER, null);

    According to the documentation, this is how to reset the current FBO back to the canvas:

    framebuffer A WebGLFramebuffer object to bind, or null for binding the Canvas or OffscreenCanvas object associated with the rendering context.

    Because of how the types are implemented in WebGL, this is not elegant to do

    Preferred pattern:

    gl.BindFramebuffer(webgl.FRAMEBUFFER, webgl.FramebufferFromJS(js.Null()))
    

    Unfortunately this will panic

    Problem

    From webgl_js.go:

    // FramebufferFromJS is casting a js.Value into Framebuffer.
    func FramebufferFromJS(value js.Value) *Framebuffer {
    	if typ := value.Type(); typ == js.TypeNull || typ == js.TypeUndefined {
    		return nil
    	}
    	ret := &Framebuffer{}
    	ret.Value_JS = value
    	return ret
    }
    

    In the case of js.Null() this returns a nil pointer, which we try to pass to BindFramebuffer

    func (_this *RenderingContext) BindFramebuffer(target uint, framebuffer *Framebuffer) {
    	var (
    		_args [2]interface{}
    		_end  int
    	)
    	_p0 := target
    	_args[0] = _p0
    	_end++
    	_p1 := framebuffer.JSValue()
    	_args[1] = _p1
    	_end++
    	_this.Value_JS.Call("bindFramebuffer", _args[0:_end]...)
    	return
    }
    

    Unfortunately, this code expected a non-nil Framebuffer, and will panic

    Workaround

    It's possible to work around it by manually creating the Framebuffer object, but it's not elegant:

    nullFBO := &webgl.Framebuffer{Object: webgl.Object{
    	Value_JS: js.Null(),
    }}
    gl.BindFramebuffer(webgl.FRAMEBUFFER, nullFBO)
    

    Solutions

    I can think of a couple of solutions:

    1. Simple remove the IsNull check from the *FromJS methods and allow the creation of null objects. gl.BindFramebuffer(webgl.FRAMEBUFFER, webgl.FramebufferFromJS(js.Null()))
    2. Create global Null versions of objects. gl.BindFramebuffer(webgl.FRAMEBUFFER, webgl.NullFramebuffer)
    3. Change the bind methods and convert nil to js.Null gl.BindFramebuffer(webgl.FRAMEBUFFER, nil)

    Notes

    From my OpenGL understanding this pattern is used for all objects. I.e. all Bind* and Use* methods (gl.bindTexture/gl.useProgram/gl.bindBuffer etc)

    The mozdev webgl documentation is unfortunately a little lacking, and only framebuffers are explicitly mentioned to be null - but I assume it also holds true for any other objects

    opened by ptxmac 8
  • adding examples in the readme file

    adding examples in the readme file

    Great project πŸ‘ Wasm is the future of webdev and go is an awesome langage.

    Could be interesting to add a chapter in the readme file with examples of projects using this webapi in go. The syntax to call some html / js is not trivial.

    For all purpose, I'm currently working on an HTML5 interactive chart, 100% in go, based on canvas and wasm via this webapi: https://github.com/sunraylab/gowebstockchart

    opened by lolorenzo777 1
  • Video  / Audio via https://developer.mozilla.org/en-US/docs/Web/API/WebCodecs_API

    Video / Audio via https://developer.mozilla.org/en-US/docs/Web/API/WebCodecs_API

    Thank You for this awesome project..

    I dont see https://developer.mozilla.org/en-US/docs/Web/API/WebCodecs_API in the code generated golang.

    Here is what i am up to:

    I want to make a Video player using golang wasm, and customise how the player looks and feels using GIO ( https://github.com/gioui) Gio can compile to web, desktop and mobile.

    The WebCodecs_API will allow me to build a custom player feeding the frames into it.

    Then i am thinking of using a webview for Desktop and Mobile using https://github.com/Inkeliz/gowebview, so that it also works on those targets.

    Please let me know if you have support for the webCodecs...

    opened by gedw99 0
Owner
Go Web API
Go Web API
Framework for building distributed services with Web Assembly

Tarmac Framework for building distributed services with Web Assembly Tarmac is a unique framework designed for the next generation of distributed syst

Benjamin Cane 225 Dec 31, 2022
DOM library for Go and WASM

Go DOM binding (and more) for WebAssembly This library provides a Go API for different Web APIs for WebAssembly target. It's in an active development,

Denys Smirnov 469 Dec 23, 2022
βš™οΈ Concept of Golang HTML render engine with frontend components and dynamic behavior

An HTML render engine concept that brings frontend-like components experience to the server side with native html/template on steroids. Supports any s

Yurii Zinets 543 Nov 25, 2022
Golang-WASM provides a simple idiomatic, and comprehensive API and bindings for working with WebAssembly for Go and JavaScript developers

A bridge and bindings for JS DOM API with Go WebAssembly. Written by Team Ortix - Hamza Ali and Chan Wen Xu. GOOS=js GOARCH=wasm go get -u github.com/

TeamOrtix 93 Dec 22, 2022
A package to build progressive web apps with Go programming language and WebAssembly.

Go-app is a package for building progressive web apps (PWA) with the Go programming language (Golang) and WebAssembly (Wasm). Shaping a UI is done by

Maxence Charriere 6.7k Dec 30, 2022
A package to build progressive web apps with Go programming language and WebAssembly.

Go-app is a package for building progressive web apps (PWA) with the Go programming language (Golang) and WebAssembly (Wasm). Shaping a UI is done by

Maxence Charriere 6.7k Jan 2, 2023
Bed and Breakfast web app written in Go

BOOKINGS AND RESERVATIONS This repository contains the files for my RareBnB application RareBnB is an "AirBnB" style clone providing a user the abilit

null 0 Jan 11, 2022
hdq - HTML DOM Query Language for Go+

hdq - HTML DOM Query Language for Go+ Summary about hdq hdq is a Go+ package for processing HTML documents. Tutorials Collect links of a html page How

Qiniu Cloud 29 Dec 13, 2022
Dom - A Go API for different Web APIs for WebAssembly target

Go DOM binding (and more) for WebAssembly This library provides a Go API for dif

Denys Smirnov 472 Jan 7, 2023
based on go lang build WEB development framework for go lang beginners .

based on go lang build WEB development framework for go lang beginners .

zhenfan.yu 1 Oct 31, 2021
Framework for building distributed services with Web Assembly

Tarmac Framework for building distributed services with Web Assembly Tarmac is a unique framework designed for the next generation of distributed syst

Benjamin Cane 225 Dec 31, 2022
DOM library for Go and WASM

Go DOM binding (and more) for WebAssembly This library provides a Go API for different Web APIs for WebAssembly target. It's in an active development,

Denys Smirnov 469 Dec 23, 2022
domui: DOM UI framework for Go

domui: DOM UI framework for Go

null 97 Jul 23, 2022
Gom: DOM building using Go

gom DOM building using Go Usage package main import "github.com/hadihammurabi/gom" func main() { dom := gom.H("html").Children( gom.H("head").Chi

Hadi Hidayat Hammurabi 0 Dec 16, 2021
A Simple Application written in go-lang that serves the index.html

go-web server A Simple Application written in go-lang that serves the index.html Running the Application, Well, make sure you have go installed to con

Aelpxy 1 Nov 24, 2021
Machine Learning libraries for Go Lang - Linear regression, Logistic regression, etc.

package ml - Machine Learning Libraries ###import "github.com/alonsovidales/go_ml" Package ml provides some implementations of usefull machine learnin

Alonso Vidales 196 Nov 10, 2022
bluemonday: a fast golang HTML sanitizer (inspired by the OWASP Java HTML Sanitizer) to scrub user generated content of XSS

bluemonday bluemonday is a HTML sanitizer implemented in Go. It is fast and highly configurable. bluemonday takes untrusted user generated content as

Microcosm 2.6k Jan 4, 2023
Simple system for writing HTML/XML as Go code. Better-performing replacement for html/template and text/template

Simple system for writing HTML as Go code. Use normal Go conditionals, loops and functions. Benefit from typing and code analysis. Better performance than templating. Tiny and dependency-free.

Nelo Mitranim 5 Dec 5, 2022
VMail - check the markup (HTML, CSS) of HTML email template compatibility with email clients

VMail - check the markup (HTML, CSS) of HTML email template compatibility with email clients Email clients use different rendering standards. This is

Alexey Vasiliev 22 Dec 17, 2022
This command line converts .html file into .html with images embed.

embed-html This command line converts .html file into .html with images embed. Install > go get github.com/gonejack/embed-html Usage > embed-html *.ht

δΌšζœ‰ηŒ«ηš„ 1 Oct 6, 2022