Documentation
¶
Index ¶
- func ApplyStealth(page *rod.Page) error
- func ClickRef(page *rod.Page, ref string) error
- func CloseTab(browser *rod.Browser, index int) error
- func DismissCookieBanner(page *rod.Page) bool
- func EvalJS(page *rod.Page, expr string, elementRef string) (string, error)
- func FormatErrors(errors []ErrorEntry) string
- func FormatPreview(r *PreviewResult) string
- func FormatText(result *ExtractionResult) string
- func HandleNextDialog(page *rod.Page, accept bool, promptText string)
- func HoverRef(page *rod.Page, ref string) error
- func PressKey(page *rod.Page, key string, ref string) error
- func ResolveRef(page *rod.Page, ref string) (*rod.Element, error)
- func SelectOption(page *rod.Page, ref string, values []string) error
- func SetViewport(page *rod.Page, width, height int) error
- func SwitchTab(browser *rod.Browser, index int) (*rod.Page, error)
- func TakeScreenshot(page *rod.Page, fullPage bool, elementRef string, quality int) ([]byte, error)
- func TypeRef(page *rod.Page, ref string, text string) error
- func WaitForSelector(page *rod.Page, selector string, timeoutSec int) error
- type Browser
- type ErrorCollector
- type ErrorEntry
- type ExtractLevel
- type ExtractedNode
- type ExtractionResult
- type ExtractionStats
- type NetworkEntry
- type PageInfo
- type PreviewResult
- type PreviewSummary
- type TabInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyStealth ¶
ApplyStealth applies anti-detection patches to a page via CDP. These hide common headless Chrome fingerprints that anti-bot systems check.
func DismissCookieBanner ¶
DismissCookieBanner attempts to find and click a cookie accept button. Returns true if a banner was found and dismissed.
func EvalJS ¶
EvalJS evaluates JavaScript on the page or in an element context. If elementRef is non-empty, the JS runs with `this` bound to that element.
func FormatErrors ¶
func FormatErrors(errors []ErrorEntry) string
FormatErrors formats errors as compact text lines.
func FormatPreview ¶
func FormatPreview(r *PreviewResult) string
FormatPreview renders a compact text report.
func FormatText ¶
func FormatText(result *ExtractionResult) string
FormatText renders the extraction result as compact text.
func HandleNextDialog ¶
HandleNextDialog sets up a one-shot handler for the next JavaScript dialog (alert, confirm, prompt). It returns immediately; the handler fires when the dialog appears.
func PressKey ¶
PressKey sends a keyboard key press. If ref is non-empty, focuses the element first.
func ResolveRef ¶
ResolveRef finds an element by its ref (@1, @2, etc.). Refs are assigned in DOM order to interactive elements, so @N means the Nth element matching the interactive selector.
func SelectOption ¶
SelectOption selects option(s) in a <select> element by visible text.
func SetViewport ¶
SetViewport overrides the page viewport dimensions.
func TakeScreenshot ¶
TakeScreenshot captures the page or a specific element. If elementRef is non-empty, captures only that element. If fullPage is true, captures the full scrollable page. quality controls JPEG quality (1-100); PNG is used if quality <= 0.
Types ¶
type Browser ¶
type Browser struct {
// contains filtered or unexported fields
}
Browser wraps a Rod browser with connect/launch logic.
func NewBrowser ¶
NewBrowser creates a browser instance. If connectURL is set, connects to an existing Chrome via CDP. Otherwise, auto-launches a new Chrome process.
func (*Browser) Close ¶
func (b *Browser) Close()
Close cleans up the browser resources. When connected to an external Chrome, only disconnects (doesn't kill it).
func (*Browser) Connected ¶
Connected returns true if connected to external Chrome (not launched by us).
func (*Browser) Page ¶
Page returns the active page or creates a new one. When connected to an existing Chrome, it gets the first existing page.
func (*Browser) RawBrowser ¶
RawBrowser returns the underlying rod.Browser instance. Needed for commands that operate on browser-level (tabs, etc).
type ErrorCollector ¶
type ErrorCollector struct {
// contains filtered or unexported fields
}
ErrorCollector collects console and network errors from a page via CDP events.
func NewErrorCollector ¶
func NewErrorCollector(page *rod.Page) *ErrorCollector
NewErrorCollector creates a collector and starts listening on the page. It hooks into RuntimeConsoleAPICalled, RuntimeExceptionThrown, and NetworkResponseReceived.
func (*ErrorCollector) Errors ¶
func (c *ErrorCollector) Errors() []ErrorEntry
Errors returns all collected errors (snapshot).
type ErrorEntry ¶
type ErrorEntry struct {
Type string `json:"type"` // "console" or "network"
Level string `json:"level"` // "error", "warning", "4xx", "5xx"
Message string `json:"message"` // error message or URL
Source string `json:"source"` // file:line for console, URL for network
Status int `json:"status,omitempty"` // HTTP status for network errors
Method string `json:"method,omitempty"` // HTTP method for network
TimeMs int64 `json:"time_ms"` // timestamp relative to collector start
}
ErrorEntry represents a single console or network error.
type ExtractLevel ¶
type ExtractLevel string
ExtractLevel controls how much of the accessibility tree is returned.
const ( LevelSkeleton ExtractLevel = "skeleton" LevelContent ExtractLevel = "content" LevelFull ExtractLevel = "full" )
type ExtractedNode ¶
type ExtractedNode struct {
Ref string `json:"ref,omitempty"`
Role string `json:"role"`
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
Level int `json:"level,omitempty"`
Href string `json:"href,omitempty"`
Type string `json:"type,omitempty"`
Checked *bool `json:"checked,omitempty"`
Disabled bool `json:"disabled,omitempty"`
Children []ExtractedNode `json:"children,omitempty"`
}
ExtractedNode represents a filtered accessibility node.
type ExtractionResult ¶
type ExtractionResult struct {
Nodes []ExtractedNode `json:"nodes"`
Refs map[string]ExtractedNode `json:"refs"`
Stats ExtractionStats `json:"stats"`
}
ExtractionResult holds the extraction output.
func Extract ¶
func Extract(page *rod.Page, level ExtractLevel, selector string) (*ExtractionResult, error)
Extract retrieves the accessibility tree from the page and filters it.
type ExtractionStats ¶
type ExtractionStats struct {
TotalNodes int `json:"total_nodes"`
FilteredNodes int `json:"filtered_nodes"`
InteractiveCount int `json:"interactive_count"`
}
ExtractionStats provides extraction metrics.
type NetworkEntry ¶
type NetworkEntry struct {
Method string `json:"method"`
URL string `json:"url"`
Status int `json:"status"`
Size int `json:"size_bytes"`
TimeMs int64 `json:"time_ms"`
MimeType string `json:"mime_type,omitempty"`
}
NetworkEntry represents a captured network request.
type PageInfo ¶
type PageInfo struct {
URL string `json:"url"`
Title string `json:"title"`
Status int `json:"status"`
TimeMs int64 `json:"time_ms"`
}
PageInfo holds the result of a navigation.
type PreviewResult ¶
type PreviewResult struct {
PageInfo *PageInfo `json:"page"`
Errors []ErrorEntry `json:"errors"`
Network []NetworkEntry `json:"network"`
DOM *ExtractionResult `json:"dom"`
Summary PreviewSummary `json:"summary"`
}
PreviewResult is the all-in-one dev report for a page.
func Preview ¶
func Preview(page *rod.Page, url string, waitStrategy string, extractLevel ExtractLevel) (*PreviewResult, error)
Preview performs a full page analysis: navigate + collect errors + collect network + extract DOM.