browser

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBrowserPanic = errors.New("browser panic recovered")

ErrBrowserPanic is returned when a rod/CDP panic is recovered.

Functions

This section is empty.

Types

type Config

type Config struct {
	Headless       bool
	BrowserBin     string
	SessionTimeout time.Duration
}

Config holds browser tool configuration

type ElementInfo

type ElementInfo struct {
	TagName   string `json:"tagName"`
	ID        string `json:"id,omitempty"`
	ClassName string `json:"className,omitempty"`
	InnerText string `json:"innerText,omitempty"`
	InnerHTML string `json:"innerHTML,omitempty"`
	Href      string `json:"href,omitempty"`
	Value     string `json:"value,omitempty"`
}

ElementInfo holds element information

type ScreenshotResult

type ScreenshotResult struct {
	Data     string `json:"data"` // base64 encoded
	MimeType string `json:"mimeType"`
	Width    int    `json:"width"`
	Height   int    `json:"height"`
}

ScreenshotResult holds screenshot data

type Session

type Session struct {
	ID        string
	Page      *rod.Page
	CreatedAt time.Time
}

Session represents a browser session with a page

type SessionManager

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

SessionManager provides implicit session management. It auto-creates a session on first use and reuses it for subsequent calls.

func NewSessionManager

func NewSessionManager(tool *Tool) *SessionManager

NewSessionManager creates a SessionManager that wraps the given Tool.

func (*SessionManager) Close

func (sm *SessionManager) Close() error

Close closes the underlying browser tool and clears the session.

func (*SessionManager) EnsureSession

func (sm *SessionManager) EnsureSession() (string, error)

EnsureSession returns the active session ID, creating one if none exists. On ErrBrowserPanic, it closes and reconnects once before returning an error.

func (*SessionManager) Tool

func (sm *SessionManager) Tool() *Tool

Tool returns the underlying browser Tool.

type Tool

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

Tool provides browser automation

func New

func New(cfg Config) (*Tool, error)

New creates a new browser tool

func (*Tool) Click

func (t *Tool) Click(ctx context.Context, sessionID, selector string) error

Click clicks on an element

func (*Tool) Close

func (t *Tool) Close() error

Close closes all sessions and the browser

func (*Tool) CloseSession

func (t *Tool) CloseSession(sessionID string) error

CloseSession closes a browser session

func (*Tool) Eval

func (t *Tool) Eval(sessionID, script string) (interface{}, error)

Eval executes JavaScript on the page

func (*Tool) GetElementInfo

func (t *Tool) GetElementInfo(sessionID, selector string) (*ElementInfo, error)

GetElementInfo gets information about an element

func (*Tool) GetSnapshot

func (t *Tool) GetSnapshot(sessionID string) (map[string]string, error)

GetSnapshot returns basic page info (title and snippet)

func (*Tool) GetText

func (t *Tool) GetText(sessionID, selector string) (string, error)

GetText gets text content of an element

func (*Tool) HasSession

func (t *Tool) HasSession(sessionID string) bool

HasSession reports whether a session with the given ID exists.

func (*Tool) Navigate

func (t *Tool) Navigate(ctx context.Context, sessionID, url string) error

Navigate navigates to a URL

func (*Tool) NewSession

func (t *Tool) NewSession() (string, error)

NewSession creates a new browser session

func (*Tool) Screenshot

func (t *Tool) Screenshot(sessionID string, fullPage bool) (*ScreenshotResult, error)

Screenshot captures a screenshot

func (*Tool) Type

func (t *Tool) Type(ctx context.Context, sessionID, selector, text string) error

Type types text into an element

func (*Tool) WaitForSelector

func (t *Tool) WaitForSelector(ctx context.Context, sessionID, selector string, timeout time.Duration) error

WaitForSelector waits for an element to appear

Jump to

Keyboard shortcuts

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