Skip to content

malivvan/webkitgtk

Repository files navigation

webkitgtk Go Reference Release Go Report Card License

Pure Go WebKitGTK binding for Linux and FreeBSD.

This is pre release software so expect bugs and potentially API breaking changes but each release will be tagged to avoid breaking people's code.

Installation

# go 1.21.5+
go get github.com/malivvan/webkitgtk@latest

Example

The following example shows how to create a simple GTK window with a button that closes the application when clicked.

package main

import ui "github.com/malivvan/webkitgtk"

type API struct {
	app *ui.App
}

func (a *API) Quit() error {
	a.app.Quit()
	return nil
}

func main() {
	app := ui.New(ui.AppOptions{
		Name: "example",
	})
	app.Open(ui.WindowOptions{
		Title: "example",
		HTML:  `<button onclick="app.quit()">quit</button>`,
		Define: map[string]interface{}{
			"app": &API{app: app},
		},
	})
	if err := app.Run(); err != nil {
		panic(err)
	}
}

Running / Building

Running / building defaults to debug mode outputting logs to stderr. To build in release mode use the release build tag.

go build -tags release -ldflags "-s -w" -trimpath

The resulting release binary will be about ~6MB in size and cam be compressed further with UPX to about ~2.5MB.

Examples

  • echo - call go functions from javascript
  • dialog - application spawning different types of dialog windows
  • handle - handle requests on the app:// uri scheme to serve embedded files
  • notify - application sending different types of notifications
  • systray - example application showing how to use the systray

Dependencies

Either webkit2gtk-4.1 (stable) or webkitgtk-6.0 (unstable) is required at runtime. If both are installed the stable version will be used.

Debian / Ubuntu apt install libwebkit2gtk-4.1 apt install libwebkitgtk-6.0
RHEL / Fedora dnf install webkitgtk4 dnf install webkitgtk3
Arch pacman -S webkit2gtk-4.1 pacman -S webkitgtk-6.0
Alpine apk add webkit2gtk apk add webkit2gtk-6.0
Gentoo emerge -av net-libs/webkit-gtk
FreeBSD pkg install webkit2-gtk3 pkg install webkit2-gtk4

License

This project is licensed under the MIT License.