Help us shape the future of Go! Take the 2026 Go Developer Survey

browser

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ToolSession  = "browser_session"
	ToolAct      = "browser_act"
	ToolSnapshot = "browser_snapshot"
)
View Source
const (
	ErrNotFound        = "BROWSER_NOT_FOUND"
	ErrLaunchFailed    = "LAUNCH_FAILED"
	ErrProfileInUse    = "PROFILE_IN_USE"
	ErrSessionNotFound = "SESSION_NOT_FOUND"
	ErrPageNotFound    = "PAGE_NOT_FOUND"
	ErrActionInvalid   = "ACTION_INVALID"
	ErrActionFailed    = "ACTION_FAILED"
	ErrTimeout         = "TIMEOUT"
	ErrCDPFailed       = "CDP_FAILED"
	ErrCDPAmbiguous    = "CDP_AMBIGUOUS"
)

Variables

This section is empty.

Functions

func InputSchema added in v0.8.2

func InputSchema(name string) (map[string]any, bool)

func OutputSchema added in v0.8.2

func OutputSchema(name string) (map[string]any, bool)

Types

type ActRequest

type ActRequest struct {
	SessionID              string
	PageID                 string
	Actions                []Action
	CloseAfter             bool
	FullPage               bool
	MaxTextChars           int
	MaxInteractiveElements int
	Timeout                time.Duration
}

type Action

type Action struct {
	Kind         string
	Goto         *GotoAction
	Click        *ClickAction
	Fill         *FillAction
	Press        *PressAction
	Wait         *WaitAction
	WaitSelector *WaitSelectorAction
	WaitURL      *WaitURLAction
	WaitText     *WaitTextAction
	WaitResponse *WaitResponseAction
	Select       *SelectAction
	Scroll       *ScrollAction
	Navigation   *NavigationAction
}

type CleanupRequest

type CleanupRequest struct {
	MaxAge time.Duration
}

type CleanupResult

type CleanupResult struct {
	RemovedCount    int      `json:"removed_count"`
	RemovedSessions []string `json:"removed_sessions"`
}

type ClickAction

type ClickAction struct{ Selector string }

type CloseRequest

type CloseRequest struct {
	SessionID string
}

type CloseResult

type CloseResult struct {
	SessionID string `json:"session_id"`
	Closed    bool   `json:"closed"`
}

type Config

type Config struct {
	AgentDockHome    string
	ExecutablePath   string
	CDPURL           string
	ReuseExistingCDP bool
}

type ConsoleError

type ConsoleError struct {
	Message string `json:"message"`
}
type Cookie struct {
	Name     string  `json:"name"`
	Value    string  `json:"value"`
	URL      string  `json:"url,omitempty"`
	Domain   string  `json:"domain,omitempty"`
	Path     string  `json:"path,omitempty"`
	Expires  float64 `json:"expires,omitempty"`
	HTTPOnly bool    `json:"http_only,omitempty"`
	Secure   bool    `json:"secure,omitempty"`
	SameSite string  `json:"same_site,omitempty"`
}

type ElementState

type ElementState string
const (
	StateVisible  ElementState = "visible"
	StateHidden   ElementState = "hidden"
	StateAttached ElementState = "attached"
	StateDetached ElementState = "detached"
)

type Error

type Error struct {
	Code    string
	Message string
	Phase   string
	Details *ErrorDetails
	Cause   error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorDetails

type ErrorDetails struct {
	Path             string    `json:"path,omitempty"`
	Browser          Kind      `json:"browser,omitempty"`
	ProfileID        string    `json:"profile_id,omitempty"`
	SessionID        string    `json:"session_id,omitempty"`
	PageID           string    `json:"page_id,omitempty"`
	AvailablePageIDs []string  `json:"available_page_ids,omitempty"`
	ActionIndex      *int      `json:"action_index,omitempty"`
	Action           string    `json:"action,omitempty"`
	WaitUntil        WaitUntil `json:"wait_until,omitempty"`
	Direction        int64     `json:"direction,omitempty"`
	URL              string    `json:"url,omitempty"`
	URLPattern       string    `json:"url_pattern,omitempty"`
	Method           string    `json:"method,omitempty"`
	Status           int       `json:"status,omitempty"`
	Field            string    `json:"field,omitempty"`
	Reason           string    `json:"reason,omitempty"`
	Selector         string    `json:"selector,omitempty"`
	ItemIndex        *int      `json:"index,omitempty"`
	Count            int       `json:"count,omitempty"`
}

ErrorDetails is deliberately typed so dynamic maps never cross the browser service boundary. The app protocol layer converts it to MCP/JSON output.

type Executable

type Executable struct {
	Path string
	Kind Kind
}

func FindExecutable

func FindExecutable(configured string, requested Kind) (Executable, error)

type FillAction

type FillAction struct {
	Selector string
	Value    string
}

type FocusedElement

type FocusedElement struct {
	Tag        string `json:"tag"`
	ID         string `json:"id,omitempty"`
	Name       string `json:"name,omitempty"`
	Type       string `json:"type,omitempty"`
	Text       string `json:"text,omitempty"`
	Value      string `json:"value,omitempty"`
	ARIAName   string `json:"aria_name,omitempty"`
	Selector   string `json:"selector,omitempty"`
	IsEditable bool   `json:"is_editable,omitempty"`
}

type GotoAction

type GotoAction struct {
	URL       string
	WaitUntil WaitUntil
	Timeout   time.Duration
}

type InteractiveElement

type InteractiveElement struct {
	Tag      string `json:"tag"`
	Type     string `json:"type,omitempty"`
	Text     string `json:"text,omitempty"`
	ARIAName string `json:"aria_name,omitempty"`
	Href     string `json:"href,omitempty"`
	Selector string `json:"selector,omitempty"`
}

type Kind

type Kind string
const (
	BrowserAuto     Kind = "auto"
	BrowserChrome   Kind = "chrome"
	BrowserChromium Kind = "chromium"
	BrowserEdge     Kind = "edge"
)
type NavigationAction struct {
	WaitUntil WaitUntil
	Timeout   time.Duration
}

type NetworkError

type NetworkError struct {
	URL       string `json:"url,omitempty"`
	Method    string `json:"method,omitempty"`
	ErrorText string `json:"error_text"`
}

type PageError

type PageError struct {
	Message string `json:"message"`
}

type PageSummary

type PageSummary struct {
	PageID string `json:"page_id"`
	URL    string `json:"url"`
	Title  string `json:"title"`
	Active bool   `json:"active"`
}

type PressAction

type PressAction struct {
	Selector string
	Key      string
}

type ScreenshotPublisher added in v0.8.2

type ScreenshotPublisher func(context.Context, []byte, int) (map[string]any, error)

type ScrollAction

type ScrollAction struct {
	DeltaX int64
	DeltaY int64
}

type SelectAction

type SelectAction struct {
	Selector string
	Value    string
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(cfg Config, publishScreenshot ScreenshotPublisher) *Service

func (*Service) Close

func (s *Service) Close() error

func (*Service) HandleAct added in v0.8.2

func (s *Service) HandleAct(ctx context.Context, args map[string]any) (toolcore.Result, error)

func (*Service) HandleSession added in v0.8.2

func (s *Service) HandleSession(ctx context.Context, args map[string]any) (toolcore.Result, error)

func (*Service) HandleSnapshot added in v0.8.2

func (s *Service) HandleSnapshot(ctx context.Context, args map[string]any) (toolcore.Result, error)

type Size

type Size struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

type Snapshot

type Snapshot struct {
	SessionID           string               `json:"session_id"`
	PageID              string               `json:"page_id"`
	Pages               []PageSummary        `json:"pages"`
	URL                 string               `json:"url"`
	Title               string               `json:"title"`
	Text                string               `json:"text"`
	Viewport            Viewport             `json:"viewport"`
	PageSize            Size                 `json:"page_size"`
	FocusedElement      *FocusedElement      `json:"focused_element,omitempty"`
	InteractiveElements []InteractiveElement `json:"interactive_elements"`
	ConsoleErrors       []ConsoleError       `json:"console_errors"`
	NetworkErrors       []NetworkError       `json:"network_errors"`
	PageErrors          []PageError          `json:"page_errors"`
	PNG                 []byte               `json:"-"`
}

type SnapshotRequest

type SnapshotRequest struct {
	SessionID              string
	PageID                 string
	CloseAfter             bool
	FullPage               bool
	MaxTextChars           int
	MaxInteractiveElements int
	Timeout                time.Duration
}

type StartRequest

type StartRequest struct {
	URL                     string
	Browser                 Kind
	Headless                bool
	Viewport                Viewport
	ProfileID               string
	CDPURL                  string
	Cookies                 []Cookie
	LocalStorage            map[string]map[string]string
	ReloadAfterLocalStorage bool
	Timeout                 time.Duration
}

type StartResult

type StartResult struct {
	SessionID      string        `json:"session_id"`
	PageID         string        `json:"page_id"`
	Pages          []PageSummary `json:"pages"`
	URL            string        `json:"url"`
	Title          string        `json:"title"`
	ProfileID      string        `json:"profile_id,omitempty"`
	ConnectionMode string        `json:"connection_mode"`
}

type Viewport

type Viewport struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

type WaitAction

type WaitAction struct{ Duration time.Duration }

type WaitResponseAction

type WaitResponseAction struct {
	URL        string
	URLPattern string
	Method     string
	Status     int
	Timeout    time.Duration
}

type WaitSelectorAction

type WaitSelectorAction struct {
	Selector string
	State    ElementState
	Timeout  time.Duration
}

type WaitTextAction

type WaitTextAction struct {
	Text    string
	Exact   bool
	State   ElementState
	Timeout time.Duration
}

type WaitURLAction

type WaitURLAction struct {
	URL     string
	Timeout time.Duration
}

type WaitUntil

type WaitUntil string
const (
	WaitDOMContentLoaded WaitUntil = "domcontentloaded"
	WaitLoad             WaitUntil = "load"
)

Jump to

Keyboard shortcuts

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