webview

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: BSD-3-Clause Imports: 22 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package webview embeds a web engine in a bellui layout.

It spans two hosting models, chosen per platform by NewHost. On macOS, iOS, Android, Windows and the web target the engine is an OS view drawn *over* bellui's surface through widget.NativeViewHost, with every one of that host's documented limitations — nothing bellui draws can appear above the content, and core.Canvas.Capture does not see it; read the widget.NativeViewHost documentation before designing around those targets. On Linux the engine (CEF) renders offscreen and the content is composited *inside* bellui's canvas: overlays, dialogs and menus draw above it, Capture sees it, clipping and opacity apply, and the host is a Tab stop, because bellui owns the keyboard rather than the OS.

The package is an optional import: the web engine binding is only linked into binaries that import it, so an app that embeds no web content pays nothing.

Support is per-platform — see Supported. On an unsupported platform New still returns a usable value whose WebView.Attach fails, leaving the host inert (it occupies its space and draws nothing) rather than panicking, so a cross-platform app compiles and runs everywhere.

Platforms

macOS      WKWebView, hosted in the GLFW content view
iOS        WKWebView, hosted in the app window beside the GLKView
Android    android.webkit.WebView, hosted on the decor view
Windows    WebView2, hosted in a child window of the app window
Web        an <iframe> positioned over the canvas
Linux      CEF, bundled by the app, rendered offscreen and composited

Every backend except Linux uses the platform's **own** engine, so no web engine is bundled into those binaries and security updates stay with the OS vendor; Windows's engine is a separate OS component rather than part of the OS image — see ErrRuntimeMissing.

Linux is the deliberate exception to that policy, because it is the one target with no engine an app can lean on: WebKitGTK is LGPL (outside this project's allowed dependency set) and needs a GTK main loop, WPE — measured in #60 — is unbundled, ABI-coupled to the distro and absent from Ubuntu since 22.04, and no distribution packages CEF. So on Linux **the application bundles the engine**: `bellui package` lays the pinned CEF payload out beside the binary, this package finds it at run time (BELLUI_CEF_DIR overrides the search), and a binary running without it reports ErrRuntimeMissing and degrades to an inert host. The app owner accepts the payload size and the Chromium update cadence — that trade was made knowingly (#60, #105), and what it buys is the composited model described above.

The browsing profile — cookies, localStorage, the HTTP cache — persists by default at "webview-cef" under the app's bellui.Storage root, matching what every other backend's engine does in its own platform-managed location, so a login survives a restart everywhere. SetCEFProfileDir moves it; SetCEFProfileInMemory opts out and discards it on exit. Both must run before the first WebView.Attach, which is when the engine initializes, once per process.

Supplying a Linux backend yourself

The built-in backend is not the only option. widget.NativeView is a public interface with no unexported methods, so an application — or a third-party module — that wants a different engine can implement one and host it with widget.NewNativeViewHost, with no change to bellui:

view := myengine.New(...)       // implements widget.NativeView
host := widget.NewNativeViewHost(view)

Whoever supplies it pins their own engine version, owns their own update cadence, and ships it in their own Flatpak/AppImage/tarball. Such a backend must satisfy the whole widget.NativeView contract — including a native clip in SetGeometry, or the view will overflow an enclosing [container.Scroll] — and should implement widget.NativeViewFocuser as well, or bellui's focus and the OS keyboard focus will drift apart. This package is not involved: a supplied backend is used through the host directly, and being window-hosted it carries the hole punch's limitations, not the composited model's.

Each platform bends the API where its engine does. Every such difference is documented on the backend that has it, and the ones worth knowing before choosing a design are:

  • On the web target the bridge, WebView.Eval and WebView.Call reach same-origin content only, WebView.OnNavigate sees only the navigations this package starts, and WebView.CanGoBack always reports false. All three are browser policy for framed content.
  • On the web target and Android the page-side bridge is injected when the document loads rather than before it runs, so a page's own first lines may not see window.bellui. WebView.LoadHTML on the web target is the exception: the shim travels in the content itself.
  • On Android and Windows a script that throws reports a null result rather than an error, because neither evaluateJavascript nor ExecuteScript has a channel for an exception. A WebView.Call made against a page with no shim therefore stays pending on those two until the view is destroyed, instead of failing at once.
  • On Windows and Linux WebView.LoadHTML ignores its baseURL — WebView2's NavigateToString takes no base, and CEF has no literal-content API at all so the content travels as a data: URL — so the content's relative references do not resolve and its origin is always OriginOpaque.
  • On Windows a navigation the user started is reported as NavigationLinkClicked whatever they did to start it, including submitting a form: WebView2 reports that the user initiated it, not how.
  • On Linux the host is a Tab stop, and while the page is focused plain Tab / Shift+Tab traverse the page's own tab order; Ctrl+Tab / Ctrl+Shift+Tab leave it and continue in bellui's focus ring (#126). IME composition is forwarded like any other text input (#121): the OS preedit renders inline in the page and the candidate window follows the page's caret.

Talking to the page

Two channels connect bellui logic and page logic, and neither hosting model constrains them: the models differ in what can be drawn over the view and who owns the keyboard, not in what can be exchanged with it.

The bridge is **off until it is enabled**, and enabling it takes an OriginPolicy naming the content that may use it. See WebView.EnableBridge for why untrusted remote content must not be handed a message channel.

Navigation

WebView.LoadURL, WebView.LoadHTML, WebView.GoBack, WebView.GoForward, WebView.Reload and WebView.StopLoading drive the engine; WebView.OnLoadChanged reports progress and failure, and WebView.OnNavigate can veto a navigation before it starts.

Threading

Every method must be called on the main goroutine, and every callback this package makes — messages, results, load events, navigation decisions — runs on it too.

Since: 1.0

Index

Constants

View Source
const OriginOpaque = "null"

OriginOpaque is the origin reported for page content that has no origin of its own — a data: URL, about:blank, or a sandboxed frame. It matches the HTML specification's serialization of an opaque origin.

Content served from a file: URL reports "file://" instead, and ordinary web content reports scheme, host and non-default port, e.g. "https://example.com" or "http://localhost:8080".

Since: 1.0

View Source
const Supported = true

Supported reports whether this platform has a web engine binding.

Since: 1.0

Variables

View Source
var (
	// ErrNotAttached is reported when the view has no native web engine —
	// either it has not been attached to a window yet, or it has been
	// destroyed, or the platform has no web engine binding at all
	// ([Supported] is false).
	ErrNotAttached = errors.New("webview: not attached to a window")

	// ErrBridgeDisabled is reported when a bridge operation is attempted on a
	// view whose bridge was never enabled with [WebView.EnableBridge].
	ErrBridgeDisabled = errors.New("webview: bridge is not enabled")
)

Errors reported to a bridge or eval callback instead of leaving it pending. A callback this package accepts is always called exactly once, so a caller never has to distinguish "failed" from "never answered".

Since: 1.0

View Source
var ErrNavigationCancelled = errors.New("webview: navigation cancelled")

ErrNavigationCancelled is the LoadEvent.Err of a navigation that WebView.OnNavigate refused, and of one stopped with WebView.StopLoading.

Since: 1.0

View Source
var ErrRuntimeMissing = errors.New("webview: the web engine runtime is not installed")

ErrRuntimeMissing is reported by WebView.Attach when the platform's web engine exists as a separate component and that component is not there. Two platforms report it, for different reasons:

  • On Windows it means no WebView2 Evergreen Runtime is installed, or the installed one is older than this package requires. The runtime ships with Windows 11 and with Microsoft Edge, but a Windows Server or LTSC image may not have one — an app that must work everywhere should ship the Evergreen Bootstrapper alongside it (https://developer.microsoft.com/microsoft-edge/webview2/).
  • On Linux it means no bundled CEF payload was found. CEF is not a system component on any distribution — it travels with the application (`bellui package` lays it out; BELLUI_CEF_DIR overrides the search), so this is the error an unpackaged binary reports on a machine that never received the payload.

Either way Attach failing leaves the host inert — it occupies its space and draws nothing — exactly as on a platform with no binding at all, so handling the error is a chance to offer the content another way, not a requirement for the app to keep running.

It is declared on every platform so that a cross-platform app can test for it with errors.Is without a build tag; no other platform reports it.

Since: 1.0

Functions

func NewHost

func NewHost(url string) (*Host, *WebView)

NewHost returns a Host embedding a new web view for url, and the view for driving it. It is the one-call form of wrapping New in a host.

Since: 1.0

func SetCEFProfileDir

func SetCEFProfileDir(dir string) error

SetCEFProfileDir tells the Linux (CEF) backend to persist its browsing profile — cookies, localStorage, the HTTP cache — at dir. The directory is created by the engine as needed and should be an absolute path; a relative one is resolved against the working directory when the engine starts. An empty dir restores the default.

The profile persists by default, at "webview-cef" under the running app's bellui.Storage root, so this call is for apps that want it somewhere specific. Call SetCEFProfileInMemory to discard it on exit instead.

CEF is initialized once per process, on the first WebView.Attach, and the profile location is fixed from then on: call this before that first Attach, on the main goroutine. Afterwards it changes nothing and reports an error.

CEF guards a profile directory with a process-singleton lock. When a second app instance reaches its first Attach while another holds the same directory, the engine fails to initialize and every web view in that instance stays inert, reporting the failure from Attach. An app expecting concurrent instances should give each its own directory, keep the profile in memory, or use single-instance mode.

Only the Linux backend has a profile of its own to place — everywhere else the platform engine manages it — so on other platforms this reports nil and changes nothing.

Since: 1.0

func SetCEFProfileInMemory

func SetCEFProfileInMemory() error

SetCEFProfileInMemory tells the Linux (CEF) backend to keep its browsing profile in memory, discarded when the process exits — the explicit opt-out from the persistence described on SetCEFProfileDir. Web views then behave like an incognito window: no cookie, localStorage value or cached response survives a restart.

The engine still writes a little installation-specific data (its process-singleton lock among it); that goes to a fresh directory under os.TempDir, so concurrent instances never contend and nothing durable is left behind.

The same restrictions as SetCEFProfileDir apply: call it before the first WebView.Attach, on the main goroutine; it has no effect off Linux.

Since: 1.0

Types

type Args

type Args map[string]any

Args are the named arguments of WebView.EvalFunc, marshalled to JSON and passed to the script as data. Each name must be a JavaScript identifier; it becomes a parameter of the function the body runs as.

Since: 1.0

type Handler

type Handler func(Message) (any, error)

Handler answers a request the page made with window.bellui.call. Its result is marshalled to JSON and resolves the page's promise; a non-nil error rejects that promise with the error's message, so failure is reported to the page rather than swallowed.

It runs on the main goroutine, with the engine's own callback waiting behind it, so it must return promptly. Hand slow work to a goroutine and report it later with WebView.Post.

Since: 1.0

type Host

type Host struct {
	widget.BaseWidget
	// contains filtered or unexported fields
}

Host places a WebView in a bellui layout. Create one with NewHost.

It exists because the package spans two hosting models and an app should not have to know which one it got. On macOS, iOS, Android, Windows and the web target the engine is an OS view positioned over the canvas, hosted by a widget.NativeViewHost with all of that host's documented limitations. On Linux the engine (CEF) renders offscreen and the content is composited *inside* bellui's canvas — overlays draw above it, core.Canvas.Capture sees it, clipping and opacity apply, and the host is a Tab stop, because bellui owns the keyboard rather than the OS. While the page is focused, Tab traverses the page's own tab order; Ctrl+Tab / Ctrl+Shift+Tab return to bellui's focus ring (#126).

All methods must be called on the main goroutine.

Since: 1.0

func (*Host) CreateRenderer

func (h *Host) CreateRenderer() core.WidgetRenderer

CreateRenderer returns a renderer showing the platform hosting widget — the widget itself, by identity, per the hostImpl.object contract.

func (*Host) FocusNativeView

func (h *Host) FocusNativeView() bool

FocusNativeView hands the keyboard to the web content — the OS focus on a hole-punch platform, canvas focus on the composited Linux host — and reports whether it was accepted.

func (*Host) NativeViewFocused

func (h *Host) NativeViewFocused() bool

NativeViewFocused reports whether keystrokes currently go to the web content rather than to another bellui widget.

func (*Host) SetMinSize

func (h *Host) SetMinSize(min geo.Size)

SetMinSize sets the smallest size this host should be laid out at, in device-independent points. Web content has no intrinsic size bellui can measure, so the default is 0x0 and the host takes whatever the layout gives it.

func (*Host) SyncStats

func (h *Host) SyncStats() (syncs, applies uint64)

SyncStats reports the per-frame geometry sync counters of a hole-punch host — see widget.NativeViewHost.SyncStats. The composited Linux host runs no geometry sync (the content is a widget, layout reaches it like any other), so both counters stay zero there.

func (*Host) WebView

func (h *Host) WebView() *WebView

WebView returns the view this host places.

type LoadEvent

type LoadEvent struct {
	// State is the state the view has just entered.
	State LoadState

	// URL is the address being loaded, as the engine resolved it. It may
	// differ from the URL that was requested, after a redirect.
	URL string

	// Err says why a load failed, and is nil for every other state. A
	// navigation the app itself cancelled from [WebView.OnNavigate] is
	// reported as a failure with [ErrNavigationCancelled], so a cancel is
	// never mistaken for a network problem.
	Err error
}

LoadEvent reports a change of WebView.LoadState, delivered to WebView.OnLoadChanged on the main goroutine.

Since: 1.0

type LoadState

type LoadState int

LoadState is what the view's main frame is doing. It changes only for main frame navigations; a sub-frame loading its own content does not move it.

Since: 1.0

const (
	// LoadStateIdle is a view that has not been asked to load anything yet.
	LoadStateIdle LoadState = iota
	// LoadStateLoading is a navigation in progress.
	LoadStateLoading
	// LoadStateComplete is a navigation that finished.
	LoadStateComplete
	// LoadStateFailed is a navigation that did not finish. The reason is in
	// [LoadEvent.Err].
	LoadStateFailed
)

func (LoadState) String

func (s LoadState) String() string

String returns the state's name, for logs and debugging.

type Message

type Message struct {
	// Name is the handler the page addressed, for a request made with
	// window.bellui.call. It is empty for a posted notification.
	Name string

	// Payload is the value the page sent, still encoded. Read it with
	// [Message.Decode]. It is the JSON null literal when the page sent
	// nothing, never nil.
	Payload json.RawMessage

	// Origin is the serialized security origin of the frame that sent the
	// message — see [OriginOpaque]. It has already been accepted by the
	// view's [OriginPolicy]; it is reported so a handler shared between
	// several trusted origins can still tell them apart.
	Origin string
}

Message is one inbound communication from the page: a notification posted with window.bellui.post, or a request made with window.bellui.call.

Since: 1.0

func (Message) Decode

func (m Message) Decode(v any) error

Decode unmarshals the message payload into v, which must be a pointer.

Since: 1.0

type NavigationKind int

NavigationKind says what started a navigation, so a policy can treat a link the user clicked differently from one the page started on its own.

Since: 1.0

const (
	// NavigationOther is a navigation with no more specific cause — most
	// often one the page started with script, or the initial load.
	NavigationOther NavigationKind = iota
	// NavigationLinkClicked is the user activating a link.
	NavigationLinkClicked
	// NavigationFormSubmitted is a form submission.
	NavigationFormSubmitted
	// NavigationBackForward is a move through session history.
	NavigationBackForward
	// NavigationReload is a reload.
	NavigationReload
)
func (k NavigationKind) String() string

String returns the kind's name, for logs and debugging.

type NavigationRequest struct {
	// URL is where the engine is about to go.
	URL string

	// Kind is what started it.
	Kind NavigationKind

	// MainFrame reports whether this is the view's own navigation rather than
	// one inside an embedded frame.
	MainFrame bool

	// NewWindow reports a navigation the page asked to open elsewhere —
	// target="_blank" or window.open. This package has no second window to
	// open it in, so an allowed one is loaded in this view instead; deny it
	// to keep such links from replacing the current page.
	NewWindow bool
}

NavigationRequest is a navigation the engine is about to start, offered to WebView.OnNavigate before it does.

Since: 1.0

type OriginPolicy

type OriginPolicy func(origin string) bool

OriginPolicy reports whether page content served from origin may use the bridge. It is consulted for every inbound message, including messages from sub-frames, so a page that navigates or embeds a third-party frame cannot widen its own access.

Since: 1.0

func TrustAllOrigins

func TrustAllOrigins() OriginPolicy

TrustAllOrigins allows every page loaded in the view to use the bridge.

Use it only for content the app itself controls end to end. A view that can reach the open web — because it loads a remote URL, follows a link, or hosts a third-party frame — must not be given this policy: it would hand any page that turns up the same access to the app's WebView.Handle functions as the app's own content. Constrain what may be loaded with WebView.OnNavigate as well if the answer is not obviously "nothing else can be".

Since: 1.0

func TrustOrigins

func TrustOrigins(origins ...string) OriginPolicy

TrustOrigins allows only the listed origins, compared exactly against the serialization described on OriginOpaque. Pass OriginOpaque to trust content loaded from a data: URL or about:blank, and "file://" to trust content the app loaded from disk.

Since: 1.0

type WebView

type WebView struct {

	// OnMessage is called when the page posts a one-way notification:
	//
	//	window.bellui.post({hello: "world"})
	//
	// It runs on the main goroutine. It is only ever called while the bridge
	// is enabled and the sending page passed the [OriginPolicy]; a message
	// that arrives with no OnMessage set is dropped.
	//
	// Use [WebView.Handle] instead when the page expects an answer.
	OnMessage func(Message)

	// OnLoadChanged reports every change of [WebView.LoadState] for the main
	// frame: a navigation starting, finishing, or failing. It runs on the
	// main goroutine.
	OnLoadChanged func(LoadEvent)

	// OnNavigate is consulted before each navigation the engine is about to
	// start, and cancels it by returning false. A nil hook allows everything.
	//
	// It is the place to keep a view pinned to content you trust — pair it
	// with the bridge's [OriginPolicy], which decides who may *talk* to
	// bellui, where this decides who may be *shown*. It runs on the main
	// goroutine and must return promptly: the engine is waiting on it.
	OnNavigate func(NavigationRequest) bool
	// contains filtered or unexported fields
}

WebView is a platform web engine hosted in a bellui layout. Create one with New and place it with NewHost (or hand it to widget.NewNativeViewHost yourself).

All methods must be called on the main goroutine.

Since: 1.0

func New

func New(url string) *WebView

New returns a web view that will load url once it is attached to a window. An empty url leaves the engine on a blank page.

Since: 1.0

func (*WebView) Attach

func (w *WebView) Attach(win bellui.Window) error

Attach creates the platform web view inside the given window and loads the URL the view was created with, if any.

The bridge is installed here, so WebView.EnableBridge has to have been called first: a view attached with the bridge off has no page-side `window.bellui` object and no message channel behind it at all.

func (*WebView) BridgeEnabled

func (w *WebView) BridgeEnabled() bool

BridgeEnabled reports whether WebView.EnableBridge has been called.

Since: 1.0

func (*WebView) Call

func (w *WebView) Call(name string, arg any, onResult func(json.RawMessage, error))

Call invokes the page function registered with window.bellui.handle(name, fn) and reports its result to onResult, on the main goroutine. arg is marshalled to JSON, so values from outside the app cross as data and cannot become executable source in the page — prefer this to building a script with WebView.Eval.

onResult may be nil to ignore the answer. When it is not, it is called exactly once: with the page's resolved value, or with an error if the page rejected, has no handler by that name, or the view is not attached (ErrNotAttached) or has no bridge (ErrBridgeDisabled).

A page handler that never settles its promise leaves the callback pending until the view is destroyed, which fails it — the correlation is honoured, but the page's own liveness is the page's responsibility.

Since: 1.0

func (*WebView) CanGoBack

func (w *WebView) CanGoBack() bool

CanGoBack reports whether there is an earlier entry in session history.

Since: 1.0

func (*WebView) CanGoForward

func (w *WebView) CanGoForward() bool

CanGoForward reports whether there is a later entry in session history.

Since: 1.0

func (*WebView) Destroy

func (w *WebView) Destroy()

Destroy removes the native view from the window and releases it.

Work still in flight is not left hanging: every pending WebView.Call and WebView.EvalResult callback is invoked with ErrNotAttached rather than never being called at all. Registered WebView.Handle functions are kept, so a view can be attached to another window and keep working; further calls into a destroyed view fail immediately with the same error.

func (*WebView) EnableBridge

func (w *WebView) EnableBridge(policy OriginPolicy)

EnableBridge installs the page-side bridge, admitting only content that policy accepts. It must be called before WebView.Attach: the bridge is part of the web view's configuration, and a view attached without it has no window.bellui object and no message channel behind it — a page cannot reach bellui at all, rather than reaching it and being ignored. Calling it on an attached view is a logged no-op.

The bridge is off by default, and deliberately so. This package can show content the app did not write, and a message channel installed for a local trusted page is the same channel a remote page inherits when the user follows a link — the same stance widget.RichText takes with AllowRemoteContent, where parsed content is not trusted merely because it was rendered. A nil policy trusts nothing, which leaves the bridge present in the page but silent; use TrustAllOrigins or TrustOrigins to say what is trusted.

Since: 1.0

func (*WebView) Eval

func (w *WebView) Eval(js string)

Eval runs JavaScript inside the page and discards its result.

js is source, so a caller that builds it by concatenating values from outside the app has an injection hole — a string with a quote in it becomes code. Prefer WebView.EvalFunc, which passes values as data, or WebView.Call, which hands them to a function the page registered.

It is a no-op when the view is not attached; use WebView.EvalResult to learn that instead.

func (*WebView) EvalFunc

func (w *WebView) EvalFunc(body string, args Args)

EvalFunc runs body as the body of a JavaScript function whose parameters are named by args, discarding the result.

The values in args are marshalled to JSON and passed to that function as data, never spliced into the source, so content from outside the app cannot become executable code in the page:

view.EvalFunc("document.title = title;", webview.Args{"title": userInput})

This is the injection-safe form of WebView.Eval and needs no cooperation from the page, unlike WebView.Call.

Since: 1.0

func (*WebView) EvalFuncResult

func (w *WebView) EvalFuncResult(body string, args Args, onResult func(json.RawMessage, error))

EvalFuncResult is WebView.EvalFunc reporting the function's return value, with the result and error contract of WebView.EvalResult.

Since: 1.0

func (*WebView) EvalResult

func (w *WebView) EvalResult(js string, onResult func(json.RawMessage, error))

EvalResult runs JavaScript inside the page and reports the value of its last expression to onResult, on the main goroutine.

The value arrives as JSON: a script evaluating to a number gives "42", to a string gives "\"hi\"", and to nothing gives "null". Decode it with encoding/json. onResult is called exactly once — with an error if the script threw, if its value cannot be represented as JSON, or if the view is not attached (ErrNotAttached).

The injection caveat on WebView.Eval applies here too.

Since: 1.0

func (*WebView) GoBack

func (w *WebView) GoBack() bool

GoBack moves to the previous entry in session history, reporting whether there was one to move to.

Since: 1.0

func (*WebView) GoForward

func (w *WebView) GoForward() bool

GoForward moves to the next entry in session history, reporting whether there was one to move to.

Since: 1.0

func (*WebView) Handle

func (w *WebView) Handle(name string, fn Handler)

Handle registers fn as the answer to window.bellui.call(name, arg) in the page. Registering a nil function removes the handler. Handlers can be registered at any time; a request that arrives for a name with no handler rejects the page's promise with an error rather than hanging it.

Since: 1.0

func (*WebView) HasFocus

func (w *WebView) HasFocus() bool

HasFocus reports whether keys are currently being forwarded to the page.

func (*WebView) LoadHTML

func (w *WebView) LoadHTML(html, baseURL string)

LoadHTML displays html directly, resolving the page's relative references against baseURL. An empty baseURL leaves the content with no origin of its own, which the bridge reports as OriginOpaque.

It is a no-op until the view is attached — unlike WebView.LoadURL, there is no pending-content slot; load the content from WebView.OnLoadChanged or after WebView.Attach returns.

Content loaded this way may not become a session history entry, so WebView.CanGoBack can still report false afterwards. That is the engine's own behaviour for literal content with no base URL — measured on WebKit — not something this package can arrange around; give the content a real baseURL, or serve it, if it has to be navigable.

Since: 1.0

func (*WebView) LoadState

func (w *WebView) LoadState() LoadState

LoadState reports what the view's main frame is currently doing.

Since: 1.0

func (*WebView) LoadURL

func (w *WebView) LoadURL(url string)

LoadURL navigates the view to url.

Before the view is attached the URL is only remembered, and is loaded as soon as it attaches; WebView.URL reports it either way.

func (*WebView) Post

func (w *WebView) Post(payload any)

Post sends a one-way notification to the page, delivered to whatever the page assigned to window.bellui.onMessage. payload is marshalled to JSON, so it crosses as data and can never become executable source in the page.

It is the counterpart of WebView.OnMessage. Use WebView.Call when an answer is wanted.

Since: 1.0

func (*WebView) Reload

func (w *WebView) Reload()

Reload loads the current page again.

Since: 1.0

func (*WebView) ResignFocus

func (w *WebView) ResignFocus() bool

ResignFocus unfocuses the host, so keys stop reaching the page.

func (*WebView) SetGeometry

func (w *WebView) SetGeometry(rect, clip geo.Rectangle, scale float32)

SetGeometry is a no-op: the composited host is a real widget, so layout, clipping and scrolling reach the content without a platform call.

func (*WebView) SetVisible

func (w *WebView) SetVisible(visible bool)

SetVisible drives CEF's WasHidden, which stops compositing while hidden.

func (*WebView) StopLoading

func (w *WebView) StopLoading()

StopLoading stops a navigation in progress. A load stopped this way is reported to WebView.OnLoadChanged as failed with ErrNavigationCancelled.

Since: 1.0

func (*WebView) TakeFocus

func (w *WebView) TakeFocus() bool

TakeFocus focuses the composited host in bellui's own canvas — on this backend bellui owns the keyboard, so "native focus" is canvas focus on the widget that forwards keys to the page. Unhosted views just tell Blink.

func (*WebView) URL

func (w *WebView) URL() string

URL returns the URL the view was last asked to load. It is stored with the platform state, since a backend loads it as soon as it attaches.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL