Documentation
¶
Index ¶
- Variables
- type Config
- type ElementInfo
- type ScreenshotResult
- type Session
- type SessionManager
- type Tool
- func (t *Tool) Click(ctx context.Context, sessionID, selector string) error
- func (t *Tool) Close() error
- func (t *Tool) CloseSession(sessionID string) error
- func (t *Tool) Eval(sessionID, script string) (interface{}, error)
- func (t *Tool) GetElementInfo(sessionID, selector string) (*ElementInfo, error)
- func (t *Tool) GetSnapshot(sessionID string) (map[string]string, error)
- func (t *Tool) GetText(sessionID, selector string) (string, error)
- func (t *Tool) HasSession(sessionID string) bool
- func (t *Tool) Navigate(ctx context.Context, sessionID, url string) error
- func (t *Tool) NewSession() (string, error)
- func (t *Tool) Screenshot(sessionID string, fullPage bool) (*ScreenshotResult, error)
- func (t *Tool) Type(ctx context.Context, sessionID, selector, text string) error
- func (t *Tool) WaitForSelector(ctx context.Context, sessionID, selector string, timeout time.Duration) error
Constants ¶
This section is empty.
Variables ¶
var ErrBrowserPanic = errors.New("browser panic recovered")
ErrBrowserPanic is returned when a rod/CDP panic is recovered.
Functions ¶
This section is empty.
Types ¶
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 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 (*Tool) CloseSession ¶
CloseSession closes a browser session
func (*Tool) GetElementInfo ¶
func (t *Tool) GetElementInfo(sessionID, selector string) (*ElementInfo, error)
GetElementInfo gets information about an element
func (*Tool) GetSnapshot ¶
GetSnapshot returns basic page info (title and snippet)
func (*Tool) HasSession ¶
HasSession reports whether a session with the given ID exists.
func (*Tool) NewSession ¶
NewSession creates a new browser session
func (*Tool) Screenshot ¶
func (t *Tool) Screenshot(sessionID string, fullPage bool) (*ScreenshotResult, error)
Screenshot captures a screenshot