webkit

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package webkit provides a WebKit2GTK-backed browser view and window.

Index

Constants

This section is empty.

Variables

View Source
var ErrContentManagerNotFound = errors.New("webkit: user content manager not found")

ErrContentManagerNotFound is returned when WebKit user content manager cannot be retrieved

View Source
var ErrNotImplemented = errors.New("webkit: not implemented")

ErrNotImplemented is returned by stub implementations pending WebKit2GTK migration.

View Source
var ErrWebViewNotInitialized = errors.New("webkit: webview not initialized")

ErrWebViewNotInitialized is returned when WebView operations are attempted on uninitialized WebView

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 QuitMainLoop

func QuitMainLoop()

QuitMainLoop is a no-op in non-CGO builds.

func RunMainLoop

func RunMainLoop()

RunMainLoop is a no-op in non-CGO builds.

func SetURISchemeResolver

func SetURISchemeResolver(r SchemeResolver)

SetURISchemeResolver is a no-op in non-CGO builds.

func SetupWebKitDebugLogging added in v0.7.0

func SetupWebKitDebugLogging(cfg *config.Config)

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

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 {
	// 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
}

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 RenderingConfig

type RenderingConfig struct {
	Mode     string
	DebugGPU bool
}

RenderingConfig controls hardware acceleration preferences. Mode accepts: "auto" (default), "gpu", or "cpu". DebugGPU enables compositing indicators if supported.

type SchemeResolver

type SchemeResolver func(uri string) (mime string, data []byte, ok bool)

SchemeResolver provides bytes and mime for a given custom URI.

type ValidationError added in v0.3.0

type ValidationError struct {
	Field   string
	Message string
}

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

func NewWebView(cfg *Config) (*WebView, error)

NewWebView constructs a new WebView instance.

func (*WebView) CheckWebViewState added in v0.7.0

func (w *WebView) CheckWebViewState() bool

CheckWebViewState always returns false in stub builds

func (*WebView) CloseDevTools

func (w *WebView) CloseDevTools() error

CloseDevTools is a no-op in the non-CGO build.

func (*WebView) CloseFind added in v0.3.0

func (w *WebView) CloseFind() error

CloseFind closes the find overlay and clears highlights.

func (*WebView) Destroy

func (w *WebView) Destroy() error

Destroy releases native resources.

func (*WebView) FindQuery added in v0.3.0

func (w *WebView) FindQuery(q string) error

FindQuery sets or updates the current find query and applies highlighting.

func (*WebView) GetCurrentURL

func (w *WebView) GetCurrentURL() string

GetCurrentURL returns the last requested URL (non-CGO build approximation).

func (*WebView) GetZoom

func (w *WebView) GetZoom() (float64, error)

GetZoom returns the current zoom factor.

func (*WebView) GoBack

func (w *WebView) GoBack() error

GoBack is not supported in the non-CGO stub.

func (*WebView) GoForward

func (w *WebView) GoForward() error

GoForward is not supported in the non-CGO stub.

func (*WebView) Hide

func (w *WebView) Hide() error

Hide hides the WebView window.

func (*WebView) InjectScript

func (w *WebView) InjectScript(js string) error

InjectScript evaluates JavaScript in the active WebView context.

func (*WebView) LoadURL

func (w *WebView) LoadURL(rawURL string) error

LoadURL navigates the webview to the specified URL.

func (*WebView) LogDebugInfo added in v0.7.0

func (w *WebView) LogDebugInfo()

LogDebugInfo is a stub for non-CGO builds

func (*WebView) OpenFind added in v0.3.0

func (w *WebView) OpenFind(initial string) error

OpenFind opens the in-page find overlay (reusing omnibox) with an optional initial query.

func (*WebView) RegisterKeyboardShortcut

func (w *WebView) RegisterKeyboardShortcut(accel string, callback func()) error

RegisterKeyboardShortcut binds a global or window-scoped accelerator to a callback.

func (*WebView) RegisterScriptMessageHandler

func (w *WebView) RegisterScriptMessageHandler(cb func(payload string))

RegisterScriptMessageHandler registers a callback invoked when the content script posts a message.

func (*WebView) RegisterTitleChangedHandler

func (w *WebView) RegisterTitleChangedHandler(cb func(title string))

RegisterTitleChangedHandler registers a callback invoked when the page title changes.

func (*WebView) RegisterURIChangedHandler

func (w *WebView) RegisterURIChangedHandler(cb func(uri string))

RegisterURIChangedHandler registers a callback invoked when the current page URI changes.

func (*WebView) RegisterZoomChangedHandler added in v0.3.0

func (w *WebView) RegisterZoomChangedHandler(cb func(level float64))

RegisterZoomChangedHandler registers a callback invoked when zoom level changes.

func (*WebView) Reload added in v0.6.0

func (w *WebView) Reload() error

Reload is not supported in the non-CGO stub.

func (*WebView) ReloadBypassCache added in v0.6.0

func (w *WebView) ReloadBypassCache() error

ReloadBypassCache is not supported in the non-CGO stub.

func (*WebView) SetZoom

func (w *WebView) SetZoom(level float64) error

SetZoom sets the current zoom factor for the WebView.

func (*WebView) Show

func (w *WebView) Show() error

Show makes the WebView visible.

func (*WebView) ShowDevTools

func (w *WebView) ShowDevTools() error

ShowDevTools is a no-op in the non-CGO build.

func (*WebView) Window

func (w *WebView) Window() *Window

Window returns the associated native window wrapper (non-nil).

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

func NewWindow(title string) (*Window, error)

NewWindow constructs a Window. In real implementation, this would create a GTK window.

func (*Window) SetTitle

func (w *Window) SetTitle(title string)

SetTitle updates the window title (no-op in non-CGO build).

Jump to

Keyboard shortcuts

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