Documentation
¶
Overview ¶
Package browser provides Chrome browser management for automation.
Index ¶
- Variables
- type Browser
- func (b *Browser) Done() <-chan struct{}
- func (b *Browser) Error() error
- func (b *Browser) ID() string
- func (b *Browser) Info() Info
- func (b *Browser) PID() int
- func (b *Browser) Path() string
- func (b *Browser) Start(ctx context.Context) error
- func (b *Browser) State() State
- func (b *Browser) Stop(ctx context.Context) error
- type Config
- type Discoverer
- type Info
- type Manager
- func (m *Manager) ActiveCount() int
- func (m *Manager) Get(id string) (*Browser, error)
- func (m *Manager) GetWithPathFilter(id, pathFilter string) (*Browser, error)
- func (m *Manager) List() []Info
- func (m *Manager) ListByPath(pathFilter string) []Info
- func (m *Manager) Shutdown(ctx context.Context) error
- func (m *Manager) Start(ctx context.Context, id string, config Config) (*Browser, error)
- func (m *Manager) Stop(ctx context.Context, id string) error
- func (m *Manager) StopAll(ctx context.Context) ([]string, error)
- func (m *Manager) StopByProjectPath(ctx context.Context, projectPath string) ([]string, error)
- func (m *Manager) TotalStarted() int64
- type State
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBrowserExists is returned when trying to create a browser with an existing ID. ErrBrowserExists = errors.New("browser already exists") // ErrBrowserNotFound is returned when a browser ID is not found. ErrBrowserNotFound = errors.New("browser not found") // ErrBrowserAmbiguous is returned when a fuzzy lookup matches multiple browsers. ErrBrowserAmbiguous = errors.New("browser ID is ambiguous - multiple matches") )
Functions ¶
This section is empty.
Types ¶
type Browser ¶
type Browser struct {
// contains filtered or unexported fields
}
Browser represents a running browser instance.
func (*Browser) Done ¶
func (b *Browser) Done() <-chan struct{}
Done returns a channel that's closed when the browser exits.
type Config ¶
type Config struct {
ID string // Browser instance ID
URL string // Initial URL to open
Headless bool // Run in headless mode (default: true)
BinaryPath string // Path to Chrome binary (auto-detected if empty)
ProxyURL string // Proxy server URL (optional)
Path string // Project path for session scoping
WindowSize string // Window size (default: "1920,1080")
}
Config holds browser configuration.
type Discoverer ¶
type Discoverer interface {
// Find returns the path to a Chrome/Chromium binary, or empty string if not found.
Find() string
}
Discoverer finds Chrome/Chromium browser binaries on the system.
func DefaultDiscoverer ¶
func DefaultDiscoverer() Discoverer
DefaultDiscoverer returns the platform-specific discoverer.
type Info ¶
type Info struct {
ID string `json:"id"`
State string `json:"state"`
PID int `json:"pid,omitempty"`
URL string `json:"url,omitempty"`
Headless bool `json:"headless"`
BinaryPath string `json:"binary_path,omitempty"`
ProxyURL string `json:"proxy_url,omitempty"`
Path string `json:"path,omitempty"`
StartedAt string `json:"started_at,omitempty"`
Error string `json:"error,omitempty"`
}
Info contains information about a browser instance.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages browser instances.
func (*Manager) ActiveCount ¶
ActiveCount returns the number of active browsers.
func (*Manager) Get ¶
Get returns a browser by ID with fuzzy matching support. First tries exact match, then looks for browsers where the ID contains the search string as a component (for compound IDs).
func (*Manager) GetWithPathFilter ¶
GetWithPathFilter retrieves a browser by ID with fuzzy matching, filtered by path. If pathFilter is non-empty, only browsers with matching Path are considered for fuzzy lookup. Exact matches are always returned regardless of path filter.
func (*Manager) ListByPath ¶
ListByPath returns browsers filtered by project path. If pathFilter is empty, returns all browsers.
func (*Manager) StopAll ¶
StopAll stops all running browsers. Unlike Shutdown, this does NOT set shuttingDown flag, allowing new browsers to be started afterward. This is used for cleanup when the last client disconnects.
func (*Manager) StopByProjectPath ¶
StopByProjectPath stops all browsers for a specific project path. This is used for session-scoped cleanup when a client disconnects. Returns the list of stopped browser IDs.
func (*Manager) TotalStarted ¶
TotalStarted returns the total number of browsers started.