browser

package
v0.11.6 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package browser provides Chrome browser management for automation.

Index

Constants

This section is empty.

Variables

View Source
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 New

func New(config Config) *Browser

New creates a new browser instance with the given configuration.

func (*Browser) Done

func (b *Browser) Done() <-chan struct{}

Done returns a channel that's closed when the browser exits.

func (*Browser) Error

func (b *Browser) Error() error

Error returns the last error if any.

func (*Browser) ID

func (b *Browser) ID() string

ID returns the browser ID.

func (*Browser) Info

func (b *Browser) Info() Info

Info returns information about the browser.

func (*Browser) PID

func (b *Browser) PID() int

PID returns the process ID if running.

func (*Browser) Path

func (b *Browser) Path() string

Path returns the project path for this browser.

func (*Browser) Start

func (b *Browser) Start(ctx context.Context) error

Start starts the browser.

func (*Browser) State

func (b *Browser) State() State

State returns the current browser state.

func (*Browser) Stop

func (b *Browser) Stop(ctx context.Context) error

Stop stops the browser.

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 NewManager

func NewManager() *Manager

NewManager creates a new browser manager.

func (*Manager) ActiveCount

func (m *Manager) ActiveCount() int

ActiveCount returns the number of active browsers.

func (*Manager) Get

func (m *Manager) Get(id string) (*Browser, error)

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

func (m *Manager) GetWithPathFilter(id, pathFilter string) (*Browser, error)

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) List

func (m *Manager) List() []Info

List returns information about all browsers.

func (*Manager) ListByPath

func (m *Manager) ListByPath(pathFilter string) []Info

ListByPath returns browsers filtered by project path. If pathFilter is empty, returns all browsers.

func (*Manager) Shutdown

func (m *Manager) Shutdown(ctx context.Context) error

Shutdown stops all browsers.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context, id string, config Config) (*Browser, error)

Start starts a browser with the given configuration.

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context, id string) error

Stop stops a browser by ID.

func (*Manager) StopAll

func (m *Manager) StopAll(ctx context.Context) ([]string, error)

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

func (m *Manager) StopByProjectPath(ctx context.Context, projectPath string) ([]string, error)

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

func (m *Manager) TotalStarted() int64

TotalStarted returns the total number of browsers started.

type State

type State uint32

State represents the browser state.

const (
	StateIdle State = iota
	StateStarting
	StateRunning
	StateStopping
	StateStopped
	StateFailed
)

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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