Documentation
¶
Overview ¶
Package webkit provides a WebKit2GTK-backed browser view and window.
Index ¶
- Variables
- func AddCSSProvider(css string)
- func AddShortcutToController(controller uintptr, key string, handle uintptr) error
- func CreateGlobalShortcutController(window uintptr) uintptr
- func GenerateCodecControlScript(prefs CodecPreferencesConfig) string
- func IdleAdd(fn func() bool)
- func InitWebKitLogCapture() error
- func IsNativeAvailable() bool
- func IsWebKitLogCaptureActive() bool
- func LogMemoryConfiguration(config *Config)
- func NewPaned(orientation Orientation) uintptr
- func NewTestWidget() uintptr
- func PanedSetEndChild(paned uintptr, child uintptr)
- func PanedSetPosition(paned uintptr, pos int)
- func PanedSetResizeEnd(paned uintptr, resize bool)
- func PanedSetResizeStart(paned uintptr, resize bool)
- func PanedSetStartChild(paned uintptr, child uintptr)
- func QuitMainLoop()
- func ResetWidgetStubsForTesting()
- func RunMainLoop()
- func SetURISchemeResolver(r SchemeResolver)
- func SetWidgetBoundsForTesting(widget uintptr, bounds WidgetBounds)
- func SetupWebKitDebugLogging(cfg *config.Config)
- func StartWebKitOutputCapture()
- func StopWebKitLogCapture()
- func ValidateMemoryConfig(config *MemoryConfig) error
- func WidgetAddCSSClass(widget uintptr, class string)
- func WidgetAddHoverHandler(widget uintptr, fn func()) uintptr
- func WidgetGetParent(widget uintptr) uintptr
- func WidgetGrabFocus(widget uintptr)
- func WidgetHookDestroy(widget uintptr)
- func WidgetIsValid(widget uintptr) bool
- func WidgetQueueAllocate(widget uintptr)
- func WidgetRealizeInContainer(widget uintptr)
- func WidgetRef(widget uintptr) bool
- func WidgetRefCount(widget uintptr) uint
- func WidgetRemoveCSSClass(widget uintptr, class string)
- func WidgetRemoveHoverHandler(widget uintptr, token uintptr)
- func WidgetSetHExpand(widget uintptr, expand bool)
- func WidgetSetVExpand(widget uintptr, expand bool)
- func WidgetShow(widget uintptr)
- func WidgetUnparent(widget uintptr)
- func WidgetUnref(widget uintptr)
- type CacheModel
- type CodecPreferencesConfig
- type Config
- type MemoryConfig
- type Orientation
- type RenderingConfig
- type SchemeResolver
- type ValidationError
- type VideoAccelerationConfig
- type WebView
- func (w *WebView) CheckWebViewState() bool
- func (w *WebView) CloseDevTools() error
- func (w *WebView) CloseFind() error
- func (w *WebView) CreateRelatedView() *WebView
- func (w *WebView) Destroy() error
- func (w *WebView) DestroyWindow()
- func (w *WebView) DispatchCustomEvent(eventName string, detail map[string]any) error
- func (w *WebView) FindQuery(q string) error
- func (w *WebView) GetCurrentURL() string
- func (w *WebView) GetNativePointer() unsafe.Pointer
- func (w *WebView) GetZoom() (float64, error)
- func (w *WebView) GoBack() error
- func (w *WebView) GoForward() error
- func (w *WebView) Hide() error
- func (w *WebView) ID() string
- func (w *WebView) InitializeContentBlocking(filterManager interface{}) error
- func (w *WebView) InjectScript(js string) error
- func (w *WebView) IsActive() bool
- func (w *WebView) LoadURL(rawURL string) error
- func (w *WebView) LogDebugInfo()
- func (w *WebView) OnNavigate(url string, filterManager interface{})
- func (w *WebView) OnWindowTypeDetected(callback func(WindowType, *WindowFeatures))
- func (w *WebView) OpenFind(initial string) error
- func (w *WebView) PrepareForReparenting()
- func (w *WebView) RefreshAfterReparenting()
- func (w *WebView) RegisterCloseHandler(cb func())
- func (w *WebView) RegisterKeyboardShortcut(accel string, callback func()) error
- func (w *WebView) RegisterPopupHandler(cb func(string) *WebView)
- func (w *WebView) RegisterScriptMessageHandler(cb func(payload string))
- func (w *WebView) RegisterTitleChangedHandler(cb func(title string))
- func (w *WebView) RegisterURIChangedHandler(cb func(uri string))
- func (w *WebView) RegisterZoomChangedHandler(cb func(level float64))
- func (w *WebView) Reload() error
- func (w *WebView) ReloadBypassCache() error
- func (w *WebView) RootWidget() uintptr
- func (w *WebView) RunOnMainThread(fn func())
- func (w *WebView) SeedDomZoom(level float64)
- func (w *WebView) SetActive(active bool)
- func (w *WebView) SetWindowFeatures(features *WindowFeatures)
- func (w *WebView) SetZoom(level float64) error
- func (w *WebView) Show() error
- func (w *WebView) ShowDevTools() error
- func (w *WebView) UpdateContentFilters(filterManager interface{}) error
- func (w *WebView) UsesDomZoom() bool
- func (w *WebView) Widget() uintptr
- func (w *WebView) Window() *Window
- type WidgetBounds
- type Window
- type WindowFeatures
- type WindowShortcuts
- type WindowType
Constants ¶
This section is empty.
Variables ¶
var ErrContentManagerNotFound = errors.New("webkit: user content manager not found")
ErrContentManagerNotFound is returned when WebKit user content manager cannot be retrieved
var ErrNotImplemented = errors.New("webkit: not implemented")
ErrNotImplemented is returned by stub implementations pending WebKit2GTK migration.
var ErrWebViewNotInitialized = errors.New("webkit: webview not initialized")
ErrWebViewNotInitialized is returned when WebView operations are attempted on uninitialized WebView
Functions ¶
func AddCSSProvider ¶ added in v0.9.0
func AddCSSProvider(css string)
func AddShortcutToController ¶ added in v0.9.0
func CreateGlobalShortcutController ¶ added in v0.9.0
Stub implementations for Go wrapper functions
func GenerateCodecControlScript ¶ added in v0.6.0
func GenerateCodecControlScript(prefs CodecPreferencesConfig) string
GenerateCodecControlScript creates JavaScript code to control codec preferences This script overrides MediaCapabilities API and platform-specific player configurations
func InitWebKitLogCapture ¶ added in v0.5.0
func InitWebKitLogCapture() error
InitWebKitLogCapture initializes the WebKit log capture system (stub version)
func IsNativeAvailable ¶
func IsNativeAvailable() bool
IsNativeAvailable reports whether the native WebKit2GTK backend is compiled in. In non-CGO builds, this returns false and WebView methods are logical no-ops.
func IsWebKitLogCaptureActive ¶ added in v0.5.0
func IsWebKitLogCaptureActive() bool
IsWebKitLogCaptureActive returns whether WebKit log capture is active (stub version)
func LogMemoryConfiguration ¶ added in v0.3.0
func LogMemoryConfiguration(config *Config)
LogMemoryConfiguration logs the current memory configuration for debugging
func NewPaned ¶ added in v0.9.0
func NewPaned(orientation Orientation) uintptr
func NewTestWidget ¶ added in v0.9.0
func NewTestWidget() uintptr
NewTestWidget returns a unique widget handle for tests.
func PanedSetEndChild ¶ added in v0.9.0
func PanedSetPosition ¶ added in v0.9.0
PanedSetPosition is a no-op in stub builds.
func PanedSetResizeEnd ¶ added in v0.9.0
func PanedSetResizeStart ¶ added in v0.9.0
func PanedSetStartChild ¶ added in v0.9.0
func ResetWidgetStubsForTesting ¶ added in v0.9.0
func ResetWidgetStubsForTesting()
ResetWidgetStubsForTesting clears widget stub state for deterministic tests.
func SetURISchemeResolver ¶
func SetURISchemeResolver(r SchemeResolver)
SetURISchemeResolver is a no-op in non-CGO builds.
func SetWidgetBoundsForTesting ¶ added in v0.9.0
func SetWidgetBoundsForTesting(widget uintptr, bounds WidgetBounds)
SetWidgetBoundsForTesting assigns bounds for the widget in stub builds.
func SetupWebKitDebugLogging ¶ added in v0.7.0
SetupWebKitDebugLogging is a stub for non-CGO builds
func StartWebKitOutputCapture ¶ added in v0.5.0
func StartWebKitOutputCapture()
StartWebKitOutputCapture starts capturing webkit stdout/stderr (stub version)
func StopWebKitLogCapture ¶ added in v0.5.0
func StopWebKitLogCapture()
StopWebKitLogCapture stops the WebKit log capture (stub version)
func ValidateMemoryConfig ¶ added in v0.3.0
func ValidateMemoryConfig(config *MemoryConfig) error
ValidateMemoryConfig validates memory configuration parameters
func WidgetAddCSSClass ¶ added in v0.9.0
func WidgetAddHoverHandler ¶ added in v0.9.0
func WidgetGetParent ¶ added in v0.9.0
func WidgetGrabFocus ¶ added in v0.9.0
func WidgetGrabFocus(widget uintptr)
func WidgetHookDestroy ¶ added in v0.9.0
func WidgetHookDestroy(widget uintptr)
func WidgetIsValid ¶ added in v0.9.0
func WidgetQueueAllocate ¶ added in v0.9.0
func WidgetQueueAllocate(widget uintptr)
func WidgetRealizeInContainer ¶ added in v0.9.0
func WidgetRealizeInContainer(widget uintptr)
func WidgetRefCount ¶ added in v0.9.0
func WidgetRemoveCSSClass ¶ added in v0.9.0
func WidgetRemoveHoverHandler ¶ added in v0.9.0
func WidgetSetHExpand ¶ added in v0.9.0
func WidgetSetVExpand ¶ added in v0.9.0
func WidgetShow ¶ added in v0.9.0
func WidgetShow(widget uintptr)
func WidgetUnparent ¶ added in v0.9.0
func WidgetUnparent(widget uintptr)
func WidgetUnref ¶ added in v0.9.0
func WidgetUnref(widget uintptr)
Types ¶
type CacheModel ¶ added in v0.3.0
type CacheModel string
CacheModel represents WebKit cache model options for memory optimization.
const ( CacheModelDocumentViewer CacheModel = "document_viewer" // Minimal caching, lowest memory CacheModelWebBrowser CacheModel = "web_browser" // Default, balanced caching CacheModelPrimaryWebBrowser CacheModel = "primary_web_browser" // Maximum caching, highest memory )
type CodecPreferencesConfig ¶ added in v0.6.0
type CodecPreferencesConfig struct {
PreferredCodecs []string
BlockedCodecs []string
ForceAV1 bool
CustomUserAgent string
DisableTwitchCodecControl bool
}
CodecPreferencesConfig holds codec preferences for WebKit media playback
type Config ¶
type Config struct {
// Assets provides access to embedded GUI files
Assets interface{ ReadFile(string) ([]byte, error) }
// InitialURL is the first URL to load when creating a WebView.
InitialURL string
// UserAgent allows overriding the default user agent string.
UserAgent string
// EnableDeveloperExtras enables devtools/inspector.
EnableDeveloperExtras bool
// ZoomDefault sets an initial zoom factor (1.0 = 100%).
ZoomDefault float64
// DataDir is the base directory for persistent website data (cookies, localStorage, etc.).
DataDir string
// CacheDir is the base directory for cache data.
CacheDir string
// Fonts apply to pages that don't specify fonts (browser defaults).
DefaultSansFont string
DefaultSerifFont string
DefaultMonospaceFont string
DefaultFontSize int // CSS px (~points)
// Rendering controls GPU/CPU selection and debug options
Rendering RenderingConfig
// VideoAcceleration controls video hardware acceleration settings
VideoAcceleration VideoAccelerationConfig
// Memory controls memory optimization settings
Memory MemoryConfig
// CodecPreferences for media playback
CodecPreferences CodecPreferencesConfig
// APIToken holds the per-session token used to authenticate dumb://api requests
// It's optional; if empty, API token enforcement may be disabled by the app.
APIToken string
// UseDomZoom toggles CSS/DOM-based zoom instead of WebKit's native zoom.
UseDomZoom bool
// CreateWindow controls whether to create a window during WebView initialization.
// Set to false when creating WebViews for workspace panes that will be reparented.
CreateWindow bool
}
Config holds initialization settings for the WebKit-based browser components. This will map to WebKit2GTK and GTK settings in the real implementation.
func GetBalancedConfig ¶ added in v0.3.0
func GetBalancedConfig() *Config
GetBalancedConfig returns a Config with moderate memory optimizations This configuration aims to reduce memory usage by 20-30% with minimal performance impact
func GetHighPerformanceConfig ¶ added in v0.3.0
func GetHighPerformanceConfig() *Config
GetHighPerformanceConfig returns a Config optimized for performance over memory This uses default/high memory settings for maximum performance
func GetMemoryOptimizedConfig ¶ added in v0.3.0
func GetMemoryOptimizedConfig() *Config
GetMemoryOptimizedConfig returns a Config optimized for low memory usage This configuration aims to reduce memory usage by 40-60% compared to defaults
type MemoryConfig ¶ added in v0.3.0
type MemoryConfig struct {
// MemoryLimitMB sets the maximum memory limit per WebView in MB (0 = unlimited)
MemoryLimitMB int
// ConservativeThreshold triggers early memory cleanup (0.0-1.0, default 0.33)
ConservativeThreshold float64
// StrictThreshold triggers aggressive memory cleanup (0.0-1.0, default 0.5)
StrictThreshold float64
// KillThreshold kills processes at this memory usage (0.0-1.0, 0 = disabled)
KillThreshold float64
// PollIntervalSeconds sets how often to check memory usage (default 2.0)
PollIntervalSeconds float64
// CacheModel determines caching strategy (default: web_browser)
CacheModel CacheModel
// EnablePageCache enables back/forward page caching (default: true)
EnablePageCache bool
// EnableOfflineAppCache enables offline application caching (default: true)
EnableOfflineAppCache bool
// ProcessRecycleThreshold recycles WebView after N page loads (0 = disabled)
ProcessRecycleThreshold int
// EnableGCInterval enables periodic JS garbage collection in seconds (0 = disabled)
EnableGCInterval int
// EnableMemoryMonitoring logs memory usage and pressure events
EnableMemoryMonitoring bool
}
MemoryConfig controls memory optimization settings.
type Orientation ¶ added in v0.9.0
type Orientation int
Orientation mirrors GtkOrientation in stub builds.
const ( OrientationHorizontal Orientation = 0 OrientationVertical Orientation = 1 )
type RenderingConfig ¶
RenderingConfig controls hardware acceleration preferences. Mode accepts: "auto" (default), "gpu", or "cpu". DebugGPU enables compositing indicators if supported.
type SchemeResolver ¶
SchemeResolver provides bytes and mime for a given custom URI.
type ValidationError ¶ added in v0.3.0
ValidationError represents a configuration validation error
func (*ValidationError) Error ¶ added in v0.3.0
func (e *ValidationError) Error() string
type VideoAccelerationConfig ¶ added in v0.5.0
type VideoAccelerationConfig struct {
EnableVAAPI bool
AutoDetectGPU bool
VAAPIDriverName string
EnableAllDrivers bool
LegacyVAAPI bool
}
VideoAccelerationConfig controls video hardware acceleration settings.
type WebView ¶
type WebView struct {
// contains filtered or unexported fields
}
WebView represents a browser view powered by WebKit2GTK. Methods are currently stubs returning ErrNotImplemented to satisfy TDD ordering.
func NewWebView ¶
NewWebView constructs a new WebView instance.
func NewWebViewWithRelated ¶ added in v0.9.0
NewWebViewWithRelated creates a new WebView related to an existing one (non-CGO stub)
func (*WebView) CheckWebViewState ¶ added in v0.7.0
CheckWebViewState always returns false in stub builds
func (*WebView) CloseDevTools ¶
CloseDevTools is a no-op in the non-CGO build.
func (*WebView) CloseFind ¶ added in v0.3.0
CloseFind closes the find overlay and clears highlights.
func (*WebView) CreateRelatedView ¶ added in v0.9.0
CreateRelatedView returns a new WebView (stub creates independent)
func (*WebView) DestroyWindow ¶ added in v0.9.0
func (w *WebView) DestroyWindow()
DestroyWindow is a no-op in stub builds.
func (*WebView) DispatchCustomEvent ¶ added in v0.9.0
DispatchCustomEvent sends a CustomEvent into the page world with the provided detail payload.
func (*WebView) FindQuery ¶ added in v0.3.0
FindQuery sets or updates the current find query and applies highlighting.
func (*WebView) GetCurrentURL ¶
GetCurrentURL returns the last requested URL (non-CGO build approximation).
func (*WebView) GetNativePointer ¶ added in v0.9.0
GetNativePointer returns nil for non-CGO build (stub implementation)
func (*WebView) ID ¶ added in v0.9.0
ID returns the unique identifier for this WebView as a string (stub)
func (*WebView) InitializeContentBlocking ¶ added in v0.8.0
InitializeContentBlocking initializes WebKit content blocking with filter manager (stub)
func (*WebView) InjectScript ¶
InjectScript evaluates JavaScript in the active WebView context.
func (*WebView) IsActive ¶ added in v0.9.0
IsActive returns whether this WebView is currently active/focused (stub)
func (*WebView) LogDebugInfo ¶ added in v0.7.0
func (w *WebView) LogDebugInfo()
LogDebugInfo is a stub for non-CGO builds
func (*WebView) OnNavigate ¶ added in v0.8.0
OnNavigate sets up domain-specific cosmetic filtering on navigation (stub)
func (*WebView) OnWindowTypeDetected ¶ added in v0.9.0
func (w *WebView) OnWindowTypeDetected(callback func(WindowType, *WindowFeatures))
OnWindowTypeDetected registers a callback (stored but never invoked in stub)
func (*WebView) OpenFind ¶ added in v0.3.0
OpenFind opens the in-page find overlay (reusing omnibox) with an optional initial query.
func (*WebView) PrepareForReparenting ¶ added in v0.9.0
func (w *WebView) PrepareForReparenting()
PrepareForReparenting is a no-op in stub builds.
func (*WebView) RefreshAfterReparenting ¶ added in v0.9.0
func (w *WebView) RefreshAfterReparenting()
RefreshAfterReparenting is a no-op in stub builds.
func (*WebView) RegisterCloseHandler ¶ added in v0.9.0
func (w *WebView) RegisterCloseHandler(cb func())
func (*WebView) RegisterKeyboardShortcut ¶
RegisterKeyboardShortcut binds a global or window-scoped accelerator to a callback.
func (*WebView) RegisterPopupHandler ¶ added in v0.9.0
func (*WebView) RegisterScriptMessageHandler ¶
RegisterScriptMessageHandler registers a callback invoked when the content script posts a message.
func (*WebView) RegisterTitleChangedHandler ¶
RegisterTitleChangedHandler registers a callback invoked when the page title changes.
func (*WebView) RegisterURIChangedHandler ¶
RegisterURIChangedHandler registers a callback invoked when the current page URI changes.
func (*WebView) RegisterZoomChangedHandler ¶ added in v0.3.0
RegisterZoomChangedHandler registers a callback invoked when zoom level changes.
func (*WebView) ReloadBypassCache ¶ added in v0.6.0
ReloadBypassCache is not supported in the non-CGO stub.
func (*WebView) RootWidget ¶ added in v0.9.0
RootWidget returns the container widget handle in CGO builds. Stub returns 0.
func (*WebView) RunOnMainThread ¶ added in v0.9.0
func (w *WebView) RunOnMainThread(fn func())
RunOnMainThread executes fn immediately in non-CGO builds.
func (*WebView) SeedDomZoom ¶ added in v0.9.0
SeedDomZoom stores the desired DOM zoom level for the next navigation (stub implementation).
func (*WebView) SetActive ¶ added in v0.9.0
SetActive sets whether this WebView is currently active/focused (stub)
func (*WebView) SetWindowFeatures ¶ added in v0.9.0
func (w *WebView) SetWindowFeatures(features *WindowFeatures)
SetWindowFeatures sets the window features for this WebView (stub)
func (*WebView) ShowDevTools ¶
ShowDevTools is a no-op in the non-CGO build.
func (*WebView) UpdateContentFilters ¶ added in v0.8.0
UpdateContentFilters updates the content filters dynamically (stub)
func (*WebView) UsesDomZoom ¶ added in v0.9.0
UsesDomZoom reports whether DOM-based zoom is enabled in this WebView.
type WidgetBounds ¶ added in v0.9.0
WidgetBounds mirrors the CGO struct for stub builds.
func WidgetGetBounds ¶ added in v0.9.0
func WidgetGetBounds(widget uintptr) (WidgetBounds, bool)
type Window ¶
type Window struct {
Title string
}
Window represents a top-level application window hosting a WebView. Stub for future GTK application window management.
func NewWindow ¶
NewWindow constructs a Window. In real implementation, this would create a GTK window.
func (*Window) InitializeGlobalShortcuts ¶ added in v0.9.0
func (w *Window) InitializeGlobalShortcuts() *WindowShortcuts
InitializeGlobalShortcuts returns a stub implementation for non-CGO builds
type WindowFeatures ¶ added in v0.9.0
type WindowFeatures struct {
Width int
Height int
ToolbarVisible bool
LocationbarVisible bool
MenubarVisible bool
Resizable bool
}
WindowFeatures describes the window features detected from WebKitWindowProperties
type WindowShortcuts ¶ added in v0.9.0
type WindowShortcuts struct {
// contains filtered or unexported fields
}
WindowShortcuts stub implementation for non-CGO builds
func (*WindowShortcuts) Cleanup ¶ added in v0.9.0
func (ws *WindowShortcuts) Cleanup()
Cleanup stub implementation
func (*WindowShortcuts) RegisterGlobalShortcut ¶ added in v0.9.0
func (ws *WindowShortcuts) RegisterGlobalShortcut(key string, callback func()) error
RegisterGlobalShortcut stub - always returns nil for non-CGO builds
type WindowType ¶ added in v0.9.0
type WindowType int
WindowType indicates how a new WebView should be treated
const ( // WindowTypeTab represents an independent WebView (future: tab) WindowTypeTab WindowType = iota // WindowTypePopup represents a related WebView (shares process/context) WindowTypePopup // WindowTypeUnknown indicates type not detected yet WindowTypeUnknown )