Brazilcrgimenes/glaze
Glaze: a CGo-free desktop WebView toolkit for Go
Featured achievements
The project's latest awards
#1 Repository of the week
#1 Repository of the week
#2 Repository of the week
Glaze
Glaze is a desktop WebView binding for Go. It is a pure-Go port of webview/webview built on purego, keeping CGo out of the picture. Each backend talks to the WebView framework the OS already ships -- WKWebView on macOS, WebKitGTK on Linux, WebView2 on Windows -- so nothing native is bundled.
It started as a fork of go-webview but has diverged enough to live as a separate codebase with its own goals and API.
Why no CGo
Dragging a C toolchain into a Go project just to open a window with HTML breaks too much of what I like about the Go ecosystem -- easy cross-compilation, reproducible builds, go install that works for whoever clones the repo. With purego glaze calls the WebView framework already present on the system via dlopen / LoadLibrary, so the binary stays self-contained with no C toolchain and no bundled native library.
What's in the box
- No CGo
- Windows, macOS, and Linux
- Zero bundled native libraries -- binds the OS WebView directly (WKWebView / WebKitGTK / WebView2)
- JavaScript to Go binding
- Helpers for common desktop patterns:
BindMethods,RenderHTML,AppWindow - Native file dialogs (
OpenFile/OpenFiles/SaveFile/OpenDirectory) and a reusable native menu bar (glaze/menu) - Plays nicely with
go.workmulti-module setups
Related: native
Glaze stays focused on the window and the WebView. OS features that aren't window-bound -- and especially the more platform-specific or less standardized ones, like desktop notifications and the system tray -- live in native, a sibling collection of small, cgo-free packages on the same purego foundation: clipboard, single-instance locks, opening a URL or revealing a file, memory-mapped files, keeping the machine awake, and more. Glaze imports what it needs from there; where a platform can't support something cleanly, the native package returns a clear ErrUnsupported instead of shipping something flaky.
Examples
| Desktop | Game of Life | Starfield |
|---|---|---|
![]() | ![]() | ![]() |
| Doom Fire | Mandelbrot | Falling Sand |
|---|---|---|
![]() | ![]() | ![]() |
| Raycasting | Filo REPL | |
|---|---|---|
![]() | ![]() |
Install
go get github.com/crgimenes/glaze@latest
Requirements
Glaze binds the WebView the operating system already provides; there is nothing to bundle, but that runtime must be present:
- macOS -- nothing extra. The Cocoa/WebKit frameworks ship with the OS.
- Linux -- a system WebKitGTK, GTK4 or GTK3; glaze detects which at runtime. The exact libraries and how to install or debug them are in Linux shared libraries below.
- Windows -- the Microsoft Edge WebView2 Runtime (preinstalled on current Windows 10/11; otherwise install the Evergreen Runtime). It is located via the registry, and
Newreturns an error if it is missing. To bundle zero native DLLs, glaze calls the runtime's internal environment-creation export directly instead of shippingWebView2Loader.dll; that export is undocumented and could change in a future Edge runtime (in which caseNewreturns a clear error). See the note oncreateEnvironmentin webview2_windows.go.
Linux shared libraries
Linux is the hard case. Every distro packages WebKitGTK a little differently and glaze can't paper over all of it -- but what it needs is concrete. These are the exact sonames it tries to dlopen at startup. They have to be loadable by the dynamic linker (on the default search path or in the ldconfig cache, or in LD_LIBRARY_PATH) and the same architecture as your binary -- a 64-bit Go build needs 64-bit libraries.
Always loaded:
libglib-2.0.so.0libgobject-2.0.so.0
libwebkitgtk-6.0.so.4 decides the stack: if it loads, glaze uses GTK4; otherwise GTK3. It never loads both -- most desktops have GTK3 and GTK4 installed side by side, and pulling both into one process corrupts GTK's type system and crashes gtk_init.
- GTK4:
libgtk-4.so.1,libwebkitgtk-6.0.so.4,libjavascriptcoregtk-6.0.so.1 - GTK3:
libgtk-3.so.0,libwebkit2gtk-4.1.so.0(orlibwebkit2gtk-4.0.so.37),libjavascriptcoregtk-4.1.so.0(orlibjavascriptcoregtk-4.0.so.18)
Installing the WebKitGTK package pulls GTK and GLib in as dependencies:
- Debian / Ubuntu:
apt install libwebkit2gtk-4.1-0(GTK3) orlibwebkitgtk-6.0-4(GTK4) - Fedora:
dnf install webkit2gtk4.1orwebkitgtk6.0 - Arch:
pacman -S webkit2gtk-4.1orwebkitgtk-6.0 - Nix / NixOS: these libraries are not on the default loader path, so a bare
go runoutside a shell that provides them fails to load. Addwebkitgtk_4_1(orwebkitgtk_6_0) to yourbuildInputs/ dev shell, or expose them throughLD_LIBRARY_PATHornix-ld.
If New returns webview: none of [...] could be loaded, the linker can't find that soname. See what's actually visible to it:
ldconfig -p | grep -E 'libwebkit(2)?gtk|libjavascriptcoregtk|libgtk-[34]'
wrong ELF class: ELFCLASS32 means the library was found but in the wrong architecture -- a 64-bit binary was pointed at 32-bit libraries (check your LD_LIBRARY_PATH).
The test suite reflects this: the GUI tests skip themselves when none of these libraries can load, so go test ./... stays green on a box without WebKitGTK instead of failing.
Hello world
package main
import (
"log"
"github.com/crgimenes/glaze"
)
func main() {
w, err := glaze.New(true)
if err != nil {
log.Fatal(err)
}
defer w.Destroy()
w.SetTitle("Glaze")
w.SetSize(800, 600, glaze.HintNone)
w.SetHtml("<h1>Hello from Glaze</h1>")
w.Run()
}
Glaze pins the goroutine that creates the first window to its current OS thread. Keep direct window calls on that goroutine, and use Dispatch to re-enter the UI thread from background work.
Desktop helpers
BindMethods
A convenience layer over Bind that exposes every exported method of a Go value as a JavaScript-callable function.
What it does:
- Reflects over the exported methods of a struct or pointer receiver.
- Builds JavaScript names with a prefix and snake_case conversion.
- Example:
GetUserByIDwith prefixapibecomesapi_get_user_by_id.
- Example:
- Applies the same signature rules as
Bind: no return, value, error, value and error. - Returns the list of registered names so you can log or verify them.
Useful when you have a service object and want to expose a consistent JavaScript API without writing one Bind call per method.
type Store struct{}
func (s *Store) GetItems() []string { return []string{"a", "b"} }
bound, err := glaze.BindMethods(w, "store", &Store{})
RenderHTML
Renders a named Go html/template to a string you can pass to SetHtml.
What it does:
- Runs a specific template (nested calls included).
- Returns the final HTML string.
- Wraps execution errors with template context.
Useful when you want server-style template rendering in a local desktop app without running an HTTP server for that page.
html, err := glaze.RenderHTML(tpl, "page", data)
if err != nil {
return err
}
w.SetHtml(html)
AppWindow
Wraps an http.Handler inside a native desktop window backed by a local loopback HTTP server.
What it does:
- Selectable transport with platform-aware default:
auto(default):unixon macOS/Linux,tcpon Windowstcp: direct loopback HTTP (127.0.0.1)unix: handler served on a Unix socket with a lightweight loopback HTTP gateway for browser navigation
- Starts listeners on random free ports/paths by default (or a custom
Addr/UnixSocketPath). - Creates a native window and navigates it to that local URL.
- Runs the UI loop and shuts down the HTTP server when the window exits.
- Supports window sizing, title, debug mode, and an optional readiness callback.
OnReadyreceives the browser URL (loopback;http://127.0.0.1:..., orhttp://[::1]:...if you pass an IPv6Addr).OnReadyInforeceives the resolved backend details (Transport,Backend,Gateway) so you can verify unix vs tcp from logs.
The shortest path from an existing net/http app to a desktop app, with minimal changes to routing, templates, and assets.
err := glaze.AppWindow(glaze.AppOptions{
Title: "My App",
Width: 1280,
Height: 800,
Transport: glaze.AppTransportAuto,
Handler: mux,
OnReadyInfo: func(info glaze.AppReadyInfo) {
log.Printf("transport=%s backend=%s gateway=%s", info.Transport, info.Backend, info.Gateway)
},
})
File dialogs
Native open/save/directory dialogs, exposed on the WebView interface (a glaze
extension; upstream webview has none):
path, _ := w.OpenFile(glaze.FileDialogOptions{
Title: "Open an image",
Filters: []glaze.FileFilter{{Name: "Images", Extensions: []string{"png", "jpg"}}},
})
paths, _ := w.OpenFiles(glaze.FileDialogOptions{}) // multi-select
saveTo, _ := w.SaveFile(glaze.FileDialogOptions{Filename: "untitled.txt"})
dir, _ := w.OpenDirectory(glaze.FileDialogOptions{})
Backends: NSOpenPanel/NSSavePanel (macOS), IFileOpenDialog/IFileSaveDialog
(Windows), GtkFileChooserNative (Linux). Each shows the modal dialog, blocks the
calling goroutine, and returns the chosen path(s) or "" on cancel. Call them
from Bind callbacks (a background goroutine), never from the UI thread. See
examples/filedialog.
Native menus
github.com/crgimenes/glaze/menu installs a native menu bar. It depends
only on purego, not on the WebView, so a game or any other window-owning app can
use it the same way.
menu.Set([]menu.Item{
{Title: "App", Submenu: []menu.Item{
{Title: "About", OnClick: showAbout},
{Separator: true},
{Title: "Quit", Shortcut: "cmd+q", OnClick: w.Terminate},
}},
{Title: "Edit", Submenu: []menu.Item{
{Title: "Copy", Shortcut: "cmd+c", OnClick: doCopy},
}},
}, menu.Options{Window: w.Window()})
macOS (NSMenu) and Windows (Win32 menu bar) are implemented; Linux returns
ErrUnsupported. See examples/menu.
Running the examples
From the repository root:
go run ./examples/simple
go run ./examples/bind
go run ./examples/zero_tcp
From each example directory:
cd examples/appwindow && go run .
cd examples/desktop && go run .
cd examples/filorepl && go run .
examples/zero_tcp shows a local-first UI built with SetHtml + BindMethods only -- no HTTP server, no loopback TCP gateway.
Testing
go test ./...
This runs the pure-logic unit tests (binding marshalling, transport selection) plus the per-platform GUI smoke tests, which drive a real WebView (WKWebView / WebKitGTK / WebView2). Those GUI tests skip themselves when the system WebView can't run here -- no display, or the libraries aren't installed (WebKitGTK on Linux, the Edge WebView2 Runtime on Windows) -- so the command above stays green on a headless or minimal box instead of failing.
For a fast, headless run, -short skips the GUI scenarios on every platform
(each drives a real run loop and can take a few seconds):
go test -short ./...
To actually exercise the GUI tests on Linux, install WebKitGTK and run under a virtual display:
xvfb-run -a go test ./...
Building on Windows
Use windowsgui to hide the console window:
go build -ldflags="-H windowsgui" .
Project layout
webview_common.go-- theWebViewinterface, function-wrapper, and JS marshallingwebview_bridge.go/webview_bridge_webkit.go-- the injected JS bridge (init/bind scripts)webview_darwin.go/webview_linux.go/webview_windows.go(+webview2_windows.go,putbounds_amd64.go,putbounds_arm64.go) -- the per-OS pure-Go backendsappwindow.go-- desktop window + local HTTP server helperdialog.go/dialog_darwin.go/dialog_windows.go/dialog_linux.go-- native file dialogshelpers.go-- utility helpers (BindMethods,RenderHTML)menu/-- the standalone native menu-bar package (github.com/crgimenes/glaze/menu)examples/-- runnable sample applications (their own Go module)
Glaze loads the OS WebView framework directly and bundles or extracts no native library, so there is no extracted file to verify or swap.
Acknowledgments
- abemedia/go-webview for the original Go binding base
- webview/webview for the original C++ WebView implementation this is ported from
- purego for dynamic linking without CGo
Similar Projects
Discover other similar projects and AI models.
Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
Get up and running with Inkling, Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.
✨ Zero-config AI chat assistant. No API key needed — sign up and instantly chat with GPT-5, Claude 4, Gemini 2.5, DeepSeek & 100+ top models. Pay-as-you-go saves you more. Available on Web, iOS, macOS, Android, Linux, Windows.
"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files







