Documentation
¶
Overview ¶
Author: HyperparameterSI
Package chromium runs the optional CEF browser host in its own process. It provides a complete Chromium window, not a system-WebView fallback. The native host owns CEF's UI thread; Go controls it over private stdio pipes.
Author: HyperparameterSI
Author: HyperparameterSI
Index ¶
- Variables
- func DefaultHostPath() (string, error)
- type Browser
- func (b *Browser) Back(ctx context.Context) error
- func (b *Browser) Close(ctx context.Context) error
- func (b *Browser) CloseTab(ctx context.Context, id int) error
- func (b *Browser) DevTools(ctx context.Context, tab int, method string, params any) (json.RawMessage, error)
- func (b *Browser) Done() <-chan struct{}
- func (b *Browser) Evaluate(ctx context.Context, tab int, expression string, out any) error
- func (b *Browser) Events() <-chan State
- func (b *Browser) Forward(ctx context.Context) error
- func (b *Browser) Navigate(ctx context.Context, target string) error
- func (b *Browser) NewTab(ctx context.Context, target string) error
- func (b *Browser) Reload(ctx context.Context) error
- func (b *Browser) SelectTab(ctx context.Context, id int) error
- func (b *Browser) State() State
- func (b *Browser) Stop(ctx context.Context) error
- func (b *Browser) Wait() error
- type BrowserStyle
- type Options
- type State
- type Tab
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("chromium: browser closed")
Functions ¶
func DefaultHostPath ¶
DefaultHostPath returns the optional host's installation location. GOLET_CHROMIUM_HOST can point to a host shipped alongside an application.
Types ¶
type Browser ¶
type Browser struct {
// contains filtered or unexported fields
}
Browser owns a host process. Methods are safe to call concurrently. Call Close or cancel the context passed to Launch to release the host and its children.
func Launch ¶
Launch starts the CEF host and waits for its first browser. ctx controls the entire session. It never downloads binaries implicitly.
func (*Browser) Close ¶
Close asks CEF to close all tabs and flush its profile. If ctx expires the host is killed. Close may be called more than once.
func (*Browser) DevTools ¶
func (b *Browser) DevTools(ctx context.Context, tab int, method string, params any) (json.RawMessage, error)
DevTools executes a privileged CDP command on an explicit tab over the private host pipe. Embedders must authorize callers; never expose this to web pages.
func (*Browser) Done ¶
func (b *Browser) Done() <-chan struct{}
Done closes once the host has exited and its pipes have been released.
func (*Browser) Evaluate ¶
Evaluate runs trusted JavaScript and decodes its by-value result. This is a privileged API, not an AI tool: assistant actions use fixed scripts instead.
func (*Browser) Events ¶
Events returns a bounded stream of the newest focused-tab state. Slow readers skip intermediate states. The channel closes after the host exits.
func (*Browser) NewTab ¶
NewTab creates and selects a tab. An empty URL opens the bundled new-tab page. Observe Events for its BrowserID and loading completion.
func (*Browser) SelectTab ¶
SelectTab focuses an existing tab using the BrowserID from State or Events.
type BrowserStyle ¶
type BrowserStyle string
BrowserStyle selects the window implementation for a host process. Choose it at launch; changing style requires closing and relaunching the host.
const ( // StyleAlloy uses Golet's custom window, tabs, and address bar (the default). // It supports the assistant and Golet user scripts, but not Chrome extensions. StyleAlloy BrowserStyle = "alloy" // StyleChrome uses the standard Chrome window and supports Chrome extensions. StyleChrome BrowserStyle = "chrome" )
type Options ¶
type Options struct {
// EphemeralDemo creates a disposable development profile. On macOS it uses
// a mock keychain to suppress authorization prompts. Data is not protected
// by Keychain; do not use for real credentials. Normal exit removes the profile.
// It cannot be combined with ProfileDir. The default remains secure storage.
EphemeralDemo bool
// Style selects the window implementation. The zero value uses StyleAlloy.
Style BrowserStyle
// ChromeStyle enables the standard Chrome window.
// Deprecated: use Style: StyleChrome instead.
ChromeStyle bool
// AppMode uses a single content-only Alloy window with a native title bar.
// It hides browser controls and rejects new tabs and popups.
// It cannot be combined with StyleChrome, Extensions, or AssistantURL.
AppMode bool
// Extensions contains explicitly trusted unpacked extension directories.
Extensions []string
// AssistantURL is a local assistant page exposed by the embedding application.
AssistantURL string
HostPath string
URL string
ProfileDir string
// Stderr receives CEF diagnostics; nil uses os.Stderr.
Stderr io.Writer
}
Options selects a separately installed CEF host and a persistent profile. A profile directory must not be shared by simultaneously running hosts.
type State ¶
type State struct {
Tabs []Tab `json:"tabs"`
BrowserID int `json:"browserId"`
URL string `json:"url"`
Title string `json:"title"`
Loading bool `json:"loading"`
CanGoBack bool `json:"canGoBack"`
CanGoForward bool `json:"canGoForward"`
}
State describes the focused tab and open tabs. Events are snapshots, not a durable log.