browseruse

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSystemPrompt

func DefaultSystemPrompt(maxActions int) string

func DefaultTools

func DefaultTools() []responses.ToolUnionParam

func DetectAnthropic45Model

func DetectAnthropic45Model(model string) bool

func DetectAnthropicModel

func DetectAnthropicModel(model string) bool

func DetectBrowserUseModel

func DetectBrowserUseModel(model string) bool

func SystemPrompt

func SystemPrompt(cfg PromptConfig) (string, error)

Types

type Action

type Action struct {
	Name       string         `json:"name"`
	Parameters map[string]any `json:"parameters"`
}

type ActionContext

type ActionContext struct {
	Session    *BrowserSession
	FileSystem *FileSystem
	Client     *openai.Client
	Model      string
}

type ActionResult

type ActionResult struct {
	ExtractedContent string         `json:"extracted_content,omitempty"`
	Error            string         `json:"error,omitempty"`
	Metadata         map[string]any `json:"metadata,omitempty"`
	LongTermMemory   string         `json:"long_term_memory,omitempty"`
	Screenshot       string         `json:"screenshot,omitempty"`
	FilesToDisplay   []string       `json:"files_to_display,omitempty"`
}

func ExecuteAction

func ExecuteAction(ctx context.Context, action Action, actionCtx ActionContext) (ActionResult, error)

type Agent

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

func NewAgent

func NewAgent(cfg AgentConfig) (*Agent, error)

func (*Agent) Run

func (a *Agent) Run(ctx context.Context) (string, error)

type AgentConfig

type AgentConfig struct {
	Task              string
	Model             string
	Session           *BrowserSession
	Client            *openai.Client
	Tools             []responses.ToolUnionParam
	MaxSteps          int
	MaxActionsPerStep int
	SystemPrompt      string
	PromptStyle       PromptStyle
	UseToolCalls      bool
	UseVision         string
	LogRequests       bool
	LogResponses      bool
	Reasoning         *shared.ReasoningParam
	Logger            *log.Logger
}

type BoundingBox

type BoundingBox struct {
	X      float64 `json:"x"`
	Y      float64 `json:"y"`
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
}

type BrowserSession

type BrowserSession struct {
	CDPURL  string
	Headers map[string]string

	AgentFocusTarget string
	// contains filtered or unexported fields
}

func NewBrowserSession

func NewBrowserSession(cdpURL string, headers map[string]string) *BrowserSession

func (*BrowserSession) BrowserStateText

func (bs *BrowserSession) BrowserStateText() string

func (*BrowserSession) Close

func (bs *BrowserSession) Close() error

func (*BrowserSession) ClosePage

func (bs *BrowserSession) ClosePage(ctx context.Context, targetID string) error

func (*BrowserSession) Connect

func (bs *BrowserSession) Connect(ctx context.Context) error

func (*BrowserSession) FileSystem

func (bs *BrowserSession) FileSystem() *FileSystem

func (*BrowserSession) GetBrowserStateSummary

func (bs *BrowserSession) GetBrowserStateSummary(ctx context.Context, includeScreenshot bool) (*BrowserStateSummary, error)

func (*BrowserSession) GetCurrentPage

func (bs *BrowserSession) GetCurrentPage() *Page

func (*BrowserSession) GetOrCreateSession

func (bs *BrowserSession) GetOrCreateSession(ctx context.Context, targetID string, focus bool) (*CDPSession, error)

func (*BrowserSession) GetPages

func (bs *BrowserSession) GetPages() []*Page

func (*BrowserSession) Kill

func (bs *BrowserSession) Kill() error

func (*BrowserSession) NewPage

func (bs *BrowserSession) NewPage(ctx context.Context, url string) (*Page, error)

func (*BrowserSession) SelectorForIndex

func (bs *BrowserSession) SelectorForIndex(index int) (string, bool)

func (*BrowserSession) SetFileSystem

func (bs *BrowserSession) SetFileSystem(fs *FileSystem)

type BrowserStateSummary

type BrowserStateSummary struct {
	URL        string
	Title      string
	Tabs       []Target
	Elements   []IndexedElement
	PageText   string
	Screenshot string
}

type CDPClient

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

func NewCDPClient

func NewCDPClient(url string, headers http.Header) *CDPClient

func (*CDPClient) Register

func (c *CDPClient) Register(method string, handler EventHandler)

func (*CDPClient) Send

func (c *CDPClient) Send(ctx context.Context, method string, params map[string]any, sessionID string) (map[string]any, error)

func (*CDPClient) SendWithTimeout

func (c *CDPClient) SendWithTimeout(method string, params map[string]any, sessionID string, timeout time.Duration) (map[string]any, error)

func (*CDPClient) Start

func (c *CDPClient) Start(ctx context.Context) error

func (*CDPClient) Stop

func (c *CDPClient) Stop() error

type CDPError

type CDPError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type CDPEvent

type CDPEvent struct {
	Method    string          `json:"method"`
	Params    json.RawMessage `json:"params"`
	SessionID string          `json:"sessionId"`
}

type CDPResponse

type CDPResponse struct {
	ID        int64           `json:"id"`
	Result    json.RawMessage `json:"result"`
	Error     *CDPError       `json:"error"`
	SessionID string          `json:"sessionId"`
}

type CDPSession

type CDPSession struct {
	TargetID  string
	SessionID string
}

type Element

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

func NewElement

func NewElement(browser *BrowserSession, backendNodeID int, sessionID string) *Element

func (*Element) Click

func (e *Element) Click(ctx context.Context) error

func (*Element) Evaluate

func (e *Element) Evaluate(ctx context.Context, function string, args ...any) (string, error)

func (*Element) Fill

func (e *Element) Fill(ctx context.Context, text string, clear bool) error

func (*Element) Focus

func (e *Element) Focus(ctx context.Context) error

func (*Element) GetAttribute

func (e *Element) GetAttribute(ctx context.Context, name string) (string, error)

func (*Element) GetBoundingBox

func (e *Element) GetBoundingBox(ctx context.Context) (*BoundingBox, error)

func (*Element) Hover

func (e *Element) Hover(ctx context.Context) error

func (*Element) ScrollIntoView

func (e *Element) ScrollIntoView(ctx context.Context) error

func (*Element) SetFileInputFiles

func (e *Element) SetFileInputFiles(ctx context.Context, paths []string) error

type EventHandler

type EventHandler func(event CDPEvent)

type FileSystem

type FileSystem struct {
	Root string
}

FileSystem provides a minimal, sandboxed filesystem similar to browser_use.

func NewFileSystem

func NewFileSystem(root string) (*FileSystem, error)

func (*FileSystem) ListFiles

func (fs *FileSystem) ListFiles() ([]string, error)

func (*FileSystem) Open

func (fs *FileSystem) Open(name string) (io.ReadCloser, error)

func (*FileSystem) ReadFile

func (fs *FileSystem) ReadFile(name string) (string, error)

func (*FileSystem) ReplaceFile

func (fs *FileSystem) ReplaceFile(name, oldStr, newStr string) error

func (*FileSystem) WriteFile

func (fs *FileSystem) WriteFile(name, content string, appendMode, trailingNewline, leadingNewline bool) error

type IndexedElement

type IndexedElement struct {
	Index    int               `json:"index"`
	Selector string            `json:"selector"`
	Tag      string            `json:"tag"`
	Text     string            `json:"text"`
	Depth    int               `json:"depth"`
	Attrs    map[string]string `json:"attrs"`
	Bounding BoundingBox       `json:"rect"`
	IsNew    bool              `json:"is_new"`
}

type Mouse

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

func (*Mouse) Click

func (m *Mouse) Click(ctx context.Context, x, y int, button string, clickCount int) error

func (*Mouse) Down

func (m *Mouse) Down(ctx context.Context, button string, clickCount int) error

func (*Mouse) Move

func (m *Mouse) Move(ctx context.Context, x, y int) error

func (*Mouse) Scroll

func (m *Mouse) Scroll(ctx context.Context, x, y int, deltaX, deltaY int) error

func (*Mouse) Up

func (m *Mouse) Up(ctx context.Context, button string, clickCount int) error

type Page

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

func (*Page) DevicePixelRatio

func (p *Page) DevicePixelRatio(ctx context.Context) float64

func (*Page) Evaluate

func (p *Page) Evaluate(ctx context.Context, pageFunction string, args ...any) (string, error)

func (*Page) GetElementByCSSSelector

func (p *Page) GetElementByCSSSelector(ctx context.Context, selector string) (*Element, error)

func (*Page) GetElementsByCSSSelector

func (p *Page) GetElementsByCSSSelector(ctx context.Context, selector string) ([]*Element, error)

func (*Page) GetTitle

func (p *Page) GetTitle(ctx context.Context) (string, error)

func (*Page) GetURL

func (p *Page) GetURL(ctx context.Context) (string, error)

func (*Page) GoBack

func (p *Page) GoBack(ctx context.Context) error

func (*Page) Goto

func (p *Page) Goto(ctx context.Context, url string) error

func (*Page) InsertText

func (p *Page) InsertText(ctx context.Context, text string) error

func (*Page) Mouse

func (p *Page) Mouse(ctx context.Context) (*Mouse, error)

func (*Page) Press

func (p *Page) Press(ctx context.Context, key string) error

func (*Page) Reload

func (p *Page) Reload(ctx context.Context) error

func (*Page) Screenshot

func (p *Page) Screenshot(ctx context.Context, format string, quality *int, maxWidth, maxHeight int) (string, error)

func (*Page) SetViewportSize

func (p *Page) SetViewportSize(ctx context.Context, width, height int) error

func (*Page) WaitForReadyState

func (p *Page) WaitForReadyState(ctx context.Context, timeout time.Duration) error

func (*Page) WaitForSelector

func (p *Page) WaitForSelector(ctx context.Context, selector string, timeout time.Duration) (*Element, error)

type PromptConfig

type PromptConfig struct {
	Style             PromptStyle
	MaxActionsPerStep int
	IsAnthropic       bool
	IsBrowserUseModel bool
	ModelName         string
}

type PromptStyle

type PromptStyle string
const (
	PromptStyleDefault    PromptStyle = "default"
	PromptStyleNoThinking PromptStyle = "no_thinking"
	PromptStyleFlash      PromptStyle = "flash"
)

type SessionManager

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

func NewSessionManager

func NewSessionManager(client *CDPClient) *SessionManager

func (*SessionManager) GetAllPageTargets

func (sm *SessionManager) GetAllPageTargets() []*Target

func (*SessionManager) GetSessionForTarget

func (sm *SessionManager) GetSessionForTarget(targetID string) *CDPSession

func (*SessionManager) GetTarget

func (sm *SessionManager) GetTarget(targetID string) *Target

func (*SessionManager) StartMonitoring

func (sm *SessionManager) StartMonitoring(ctx context.Context) error

func (*SessionManager) WaitForSession

func (sm *SessionManager) WaitForSession(targetID string, timeout time.Duration) (*CDPSession, error)

type Target

type Target struct {
	TargetID   string `json:"targetId"`
	TargetType string `json:"type"`
	URL        string `json:"url"`
	Title      string `json:"title"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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