engine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyStealth

func ApplyStealth(page *rod.Page) error

ApplyStealth applies anti-detection patches to a page via CDP. These hide common headless Chrome fingerprints that anti-bot systems check.

func ClickRef

func ClickRef(page *rod.Page, ref string) error

ClickRef clicks the element at the given ref.

func CloseTab

func CloseTab(browser *rod.Browser, index int) error

CloseTab closes the tab at the given index.

func DismissCookieBanner

func DismissCookieBanner(page *rod.Page) bool

DismissCookieBanner attempts to find and click a cookie accept button. Returns true if a banner was found and dismissed.

func EvalJS

func EvalJS(page *rod.Page, expr string, elementRef string) (string, error)

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

func HandleNextDialog(page *rod.Page, accept bool, promptText string)

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 HoverRef

func HoverRef(page *rod.Page, ref string) error

HoverRef hovers over the element at the given ref.

func PressKey

func PressKey(page *rod.Page, key string, ref string) error

PressKey sends a keyboard key press. If ref is non-empty, focuses the element first.

func ResolveRef

func ResolveRef(page *rod.Page, ref string) (*rod.Element, error)

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

func SelectOption(page *rod.Page, ref string, values []string) error

SelectOption selects option(s) in a <select> element by visible text.

func SetViewport

func SetViewport(page *rod.Page, width, height int) error

SetViewport overrides the page viewport dimensions.

func SwitchTab

func SwitchTab(browser *rod.Browser, index int) (*rod.Page, error)

SwitchTab activates the tab at the given index and returns its page.

func TakeScreenshot

func TakeScreenshot(page *rod.Page, fullPage bool, elementRef string, quality int) ([]byte, error)

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.

func TypeRef

func TypeRef(page *rod.Page, ref string, text string) error

TypeRef types text into the element at the given ref. Uses focus + select all + keyboard typing to work with React/Vue/Angular.

func WaitForSelector

func WaitForSelector(page *rod.Page, selector string, timeoutSec int) error

WaitForSelector waits for a CSS selector to appear in the DOM.

Types

type Browser

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

Browser wraps a Rod browser with connect/launch logic.

func NewBrowser

func NewBrowser(connectURL string, headless bool, timeoutSec int) (*Browser, error)

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

func (b *Browser) Connected() bool

Connected returns true if connected to external Chrome (not launched by us).

func (*Browser) Page

func (b *Browser) Page() (*rod.Page, error)

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

func (b *Browser) RawBrowser() *rod.Browser

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.

func Navigate(page *rod.Page, rawURL string, waitStrategy string) (*PageInfo, error)

Navigate goes to the given URL and returns page info. waitStrategy: "load" (default), "stable", "idle", "none". HTTP status is captured via CDP Network events on the main frame document request.

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.

type PreviewSummary

type PreviewSummary struct {
	TotalRequests    int `json:"total_requests"`
	FailedRequests   int `json:"failed_requests"`
	ErrorCount       int `json:"error_count"`
	WarningCount     int `json:"warning_count"`
	InteractiveCount int `json:"interactive_count"`
}

PreviewSummary provides quick stats.

type TabInfo

type TabInfo struct {
	Index int    `json:"index"`
	URL   string `json:"url"`
	Title string `json:"title"`
}

TabInfo holds metadata about a browser tab.

func ListTabs

func ListTabs(browser *rod.Browser) ([]TabInfo, error)

ListTabs returns info for every open tab in the browser.

Jump to

Keyboard shortcuts

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