import "github.com/lexesv/go-webview-gui"const (
// Width and height are default size
HintNone = C.WEBVIEW_HINT_NONE
// Window size can not be changed by a user
HintFixed = C.WEBVIEW_HINT_FIXED
// Width and height are minimum bounds
HintMin = C.WEBVIEW_HINT_MIN
// Width and height are maximum bounds
HintMax = C.WEBVIEW_HINT_MAX
//--------------------------------------------------------- MacOS Linux Windows
WindowClose = C.WEBVIEW_WINDOW_CLOSE // 0 + + +
WindowFocus = C.WEBVIEW_WINDOW_FOCUS // 1 + + +
WindowBlur = C.WEBVIEW_WINDOW_BLUR // 2 + + +
WindowMove = C.WEBVIEW_WINDOW_MOVE // 3 + + +
WindowResize = C.WEBVIEW_WINDOW_RESIZE // 4 + + +
WindowFullScreen = C.WEBVIEW_WINDOW_FULLSCREEN // 5 + + +
WindowExitFullScreen = C.WEBVIEW_WINDOW_EXITFULLSCREEN // 6 + + +
WindowMaximize = C.WEBVIEW_WINDOW_MAXIMIZE // 7 - + +
WindowUnmaximize = C.WEBVIEW_WINDOW_UNMAXIMIZE // 8 - + -
WindowMinimize = C.WEBVIEW_WINDOW_MINIMIZE // 9 + + +
WindowUnminimize = C.WEBVIEW_WINDOW_UNMINIMIZE // 10 + + -
)var EF embed.FSHint are used to configure window sizing and resizing
type Hint inttype WebView interface {
// Run runs the main loop until it's terminated. After this function exits -
// you must destroy the webview.
Run()
// Terminate stops the main loop. It is safe to call this function from
// a background thread.
Terminate()
// Dispatch posts a function to be executed on the main thread. You normally
// do not need to call this function, unless you want to tweak the native
// window.
Dispatch(f func())
// Destroy destroys a webview and closes the native window.
Destroy()
// Window returns a native window handle pointer. When using GTK backend the
// pointer is GtkWindow pointer, when using Cocoa backend the pointer is
// NSWindow pointer, when using Win32 backend the pointer is HWND pointer.
Window() unsafe.Pointer
// SetTitle updates the title of the native window. Must be called from the UI
// thread.
SetTitle(title string)
// SetSize updates native window size. See Hint constants.
SetSize(w int, h int, hint Hint)
// Navigate navigates webview to the given URL. URL may be a properly encoded data.
// URI. Examples:
// w.Navigate("https://github.com/webview/webview")
// w.Navigate("data:text/html,%3Ch1%3EHello%3C%2Fh1%3E")
// w.Navigate("data:text/html;base64,PGgxPkhlbGxvPC9oMT4=")
Navigate(url string)
// SetHtml sets the webview HTML directly.
// Example: w.SetHtml(w, "<h1>Hello</h1>");
SetHtml(html string)
// Init injects JavaScript code at the initialization of the new page. Every
// time the webview will open a new page - this initialization code will
// be executed. It is guaranteed that code is executed before window.onload.
Init(js string)
// Eval evaluates arbitrary JavaScript code. Evaluation happens asynchronously,
// also the result of the expression is ignored. Use RPC bindings if you want
// to receive notifications about the results of the evaluation.
Eval(js string)
// Bind binds a callback function so that it will appear under the given name
// as a global JavaScript function. Internally it uses webview_init().
// Callback receives a request string and a user-provided argument pointer.
// Request string is a JSON array of all the arguments passed to the
// JavaScript function.
//
// f must be a function
// f must return either value and error or just error
Bind(name string, f interface{}) error
// SetUserAgent sets a custom user agent string for the webview.
SetUserAgent(userAgent string)
// SetWindowEventsHandler sets the window status change event handling function
// Should be called before calling the "Run" method
// Example:
// w.SetWindowEventsHandler("test", func(state webview.WindowState) {
// switch state {
// case webview.WindowClose:
// w.Hide()
// case webview.WindowResize:
// // Example: save window size for restore in next launch
// case webview.WindowMove:
// // Example: save window position for restore in next launch
// }
// })
SetWindowEventsHandler(key string, f func(state WindowState))
// UnSetWindowEventsHandler unsets the window status change event handling function
UnSetWindowEventsHandler(key string)
// IsExistWindowEventsHandler checks if this event handler exists
IsExistWindowEventsHandler(key string) bool
// GetTitle gets the title of the native window.
GetTitle() string
// Hide hides the native window.
Hide()
// Show shows the native window.
Show()
// SetBorderless activates the borderless mode.
SetBorderless()
// SetBordered activates the bordered mode.
SetBordered()
// IsMaximized If the native window is maximized it returns true, otherwise false.
IsMaximized() bool
// Maximize maximizes the native window.
Maximize()
// Unmaximize unmaximizes the native window.
Unmaximize()
// IsMinimized If the native window is minimized it returns true, otherwise false.
// IsMinimized Does not work with Stage Manager (MacOS)
IsMinimized() bool
// Minimize minimizes the native window.
Minimize()
// Unminimize unminimizes the native window.
Unminimize()
// IsVisible If the native window is visible it returns true, otherwise false.
IsVisible() bool
// SetFullScreen activates the full-screen mode.
SetFullScreen()
// ExitFullScreen exits full-screen mode.
ExitFullScreen()
// IsFullScreen If the native window is in full-screen mode it returns true, otherwise false.
IsFullScreen() bool
// SetIcon sets the application icon (from filename).
// Example:
// w.SetIcon("icon.png")
SetIcon(icon string) error
// SetIconBites sets the application icon (from []byte).
// Example:
// iconData, err = os.ReadFile("icon.png")
// w.SetIconBites(iconData, len(iconData))
SetIconBites(b []byte, size int)
// SetAlwaysOnTop activates (=true) / deactivates(=false) the top-most mode.
SetAlwaysOnTop(onTop bool)
// GetSize gets the size of the native window.
GetSize() (width int, height int, hint Hint)
// GetPosition gets the coordinates of the native window.
GetPosition() (x, y int)
// Move moves the native window to the specified coordinates.
Move(x, y int)
// Focus set the focus on the native window.
Focus()
// SetContentStateHandler sets the document status change event handling function
// Should be called before calling the "Run" method
// Example:
// w.SetContentStateHandler("test", func(state string) {
// fmt.Printf("document content state: %s\n", state)
// })
// Status of the document:
// uninitialized - Has not started loading
// loading - Is loading
// loaded - Has been loaded
// interactive - Has loaded enough to interact with
// complete - Fully loaded
SetContentStateHandler(key string, f func(state string))
// UnSetContentStateHandler unsets the document status change event handling function
UnSetContentStateHandler(key string)
// IsExistContentStateHandler checks if this event handler exists
IsExistContentStateHandler(key string) bool
// SetDraggable converts a given DOM element to a draggable region. The user will be able to drag the native window by dragging the given DOM element.
// This feature is suitable to make custom window bars along with the borderless mode.
SetDraggable(id string)
// UnSetDraggable converts a draggable region to a normal DOM elements by removing drag event handlers.
UnSetDraggable(id string)
// Just for an example of using the Bind function. See js.go and init.js
GetHtml() (s string)
GetUrl() string
GetPageTitle() string
}func New(debug, exitOnClose bool) WebViewNew calls NewWindow to create a new window and a new webview instance. If debug is non-zero - developer tools will be enabled (if the platform supports them).
WindowState used when changing the native window status
type WindowState intGenerated by gomarkdoc