Documentation
¶
Overview ¶
Package webkit provides a WebKit2GTK-backed browser view and window.
Index ¶
- Variables
- func GenerateCodecControlScript(prefs CodecPreferencesConfig) string
- func InitWebKitLogCapture() error
- func IsNativeAvailable() bool
- func IsWebKitLogCaptureActive() bool
- func LogMemoryConfiguration(config *Config)
- func QuitMainLoop()
- func RunMainLoop()
- func SetURISchemeResolver(r SchemeResolver)
- func SetupWebKitDebugLogging(cfg *config.Config)
- func StartWebKitOutputCapture()
- func StopWebKitLogCapture()
- func ValidateMemoryConfig(config *MemoryConfig) error
- type CacheModel
- type CodecPreferencesConfig
- type Config
- type MemoryConfig
- 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) Destroy() error
- func (w *WebView) FindQuery(q string) error
- func (w *WebView) GetCurrentURL() string
- func (w *WebView) GetZoom() (float64, error)
- func (w *WebView) GoBack() error
- func (w *WebView) GoForward() error
- func (w *WebView) Hide() error
- func (w *WebView) InjectScript(js string) error
- func (w *WebView) LoadURL(rawURL string) error
- func (w *WebView) LogDebugInfo()
- func (w *WebView) OpenFind(initial string) error
- func (w *WebView) RegisterKeyboardShortcut(accel string, callback func()) error
- 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) SetZoom(level float64) error
- func (w *WebView) Show() error
- func (w *WebView) ShowDevTools() error
- func (w *WebView) Window() *Window
- type Window
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 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 SetURISchemeResolver ¶
func SetURISchemeResolver(r SchemeResolver)
SetURISchemeResolver is a no-op in non-CGO 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
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 ¶
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 (*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) 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) InjectScript ¶
InjectScript evaluates JavaScript in the active WebView context.
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
OpenFind opens the in-page find overlay (reusing omnibox) with an optional initial query.
func (*WebView) RegisterKeyboardShortcut ¶
RegisterKeyboardShortcut binds a global or window-scoped accelerator to a callback.
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) ShowDevTools ¶
ShowDevTools is a no-op in the non-CGO build.