Documentation
¶
Overview ¶
Package webview shows web pages in native windows, with a tray icon, from a pure Go program: WebView2 on Windows (through the COM interface, see github.com/jchv/go-webview2), WKWebView on macOS and WebKitGTK on Linux (both through purego, without cgo). See docs/desktop-app.md for why and for what each platform can do.
Only the RemoHop desktop app (cmd/remohop-quick) links this package. On Linux purego makes a CGO_ENABLED=0 binary dynamically linked against the C library (it has to load GTK), so the remohop command line tool, which must stay a static binary, never imports it; cmd/remohop's tests check that.
Threads ¶
Every windowing system here wants its windows created and driven from one thread, and macOS insists on the process's first thread. Importing this package locks the main goroutine to that thread (an init function calling runtime.LockOSThread), so Run must be called from the main goroutine: cli.Main runs commands there. Everything an App does must run on that thread too: in Run's setup function or in a function given to App.Dispatch, which may be called from any goroutine.
Index ¶
Constants ¶
This section is empty.
Variables ¶
ErrUnavailable means this system has no usable native web view.
Functions ¶
func Run ¶
Run starts the native application, calls setup on the UI thread and runs the event loop until App.Quit. It must be called from the main goroutine (see the package comment). If the system has no native web view it returns an error wrapping ErrUnavailable without calling setup.
func SelfTest ¶
SelfTest opens a native window with a page that probes WebCodecs and decodes clip (an H.264 Annex B stream with access unit delimiters; "" skips the decode), and returns what the page reported. The window stays open for hold after the report, so that a test can take a screenshot. Like Run, it must be called from the main goroutine.
func SelfTestBrowser ¶
func SelfTestBrowser(clip string, timeout time.Duration, start func(url string) (stop func(), err error)) (map[string]any, error)
SelfTestBrowser runs the same page in a browser instead: start is called with the page's address and must open it (and may return a process to end afterwards). It is the comparison for SelfTest.