GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - life4/gweb: 🌐 Interact with browser from Go. Manually crafted WebAPI interoperation library.

BranchesTags
Open more actions menu

Latest commit

 

History

233 Commits
233 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
.vscode
.vscode
 
 
audio
audio
 
 
canvas
canvas
 
 
css
css
 
 
examples
examples
 
 
web
web
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.markdownlint.yaml
.markdownlint.yaml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
Taskfile.yml
Taskfile.yml
 
 
generate_refs.py
generate_refs.py
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
netlify.toml
netlify.toml
 
 
refs.md
refs.md
 
 
requirements.txt
requirements.txt
 
 
tools.go
tools.go
 
 

Repository files navigation

GWeb: golang + js + wasm

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.

  • Examples: gweb.orsinium.dev
  • Mapping of JS Web API to GWeb functions: refs.md

Features

  • Strictly typed. It's a wrapper around syscall/js that helps you to avoid runtime errors (you'll get them a lot with raw syscall/js).
  • Backward compatible. Almost every type is a wrapper around js.Value. So if something missed, you can always fall back to the classic syscall/js calls.
  • Hand crafted. It's hard to make a usable autogeneration of WebAPI since Go is a strictly typed language without union types. So we carefully translated everything while applying Go best practices.
  • Cleaned up. The library provides only useful methods and attributes from WebAPI. No obsolete and deprecated methods, no experimental APIs that are only supported by a few engines. Only what we really need right now.
  • Almost the same API as in JS. If you have experience with vanilla JS, you have almost learnt everything about the libray.
  • But better. WebAPI has a long history of incremental changes and spaces for unimplemented dreams. However, we can see the full picture to provide a better experience and more namespaces.
  • Documented. Every method is documented to save your time and reduce googling.

Installation

GOOS=js GOARCH=wasm go get github.com/life4/gweb

If you're using VSCode, it's recommend to create a .vscode/settings.json file in your project with the following content:

{
    "go.toolsEnvVars": {
        "GOARCH": "wasm",
        "GOOS": "js",
    },
    "go.testEnvVars": {
        "GOARCH": "wasm",
        "GOOS": "js",
    },
}

Error handling

In the beautiful JS world anything at any time can be null or 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
}

Missed API

If something is missed, use syscall/js-like methods (Get, Set, Call etc):

doc := web.GetWindow().Document()
el := doc.Element("some-element-id")
name = el.Get("name").String()

Packages

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.

Contributing

Contributions are welcome! GWeb is a Open-Source project and you can help to make it better. Some ideas what can be improved:

  • Every function and object should have short description based on MDN Web API docs. Some descriptions are missed.
  • Also, every function that calls a Web API method should have a link in docs for that method.
  • Typos are very possible, don't be shy to fix it if you've spotted one.
  • More objects and methods? Of course! Our goal is to cover everything in WebAPI! Well, excluding deprecated things. See Features section to get feeling what should be there.
  • Found a bug? Fix it!

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 ❤️

Similar projects

  • webapi -- bindings that autogenerated from WebIDL.
  • godom -- bindings on top of gopherjs.

About

🌐 Interact with browser from Go. Manually crafted WebAPI interoperation library.

gweb.orsinium.dev/

Topics

frontendgogolangjqueryjsreactsyscallsvuewasmwebweb-assemblywebapi

Resources

Readme
MIT license
Activity
Custom properties

Stars

227 stars

Watchers

8 watching

Forks

17 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.