browser

package
v0.0.0-...-2fe4d4b Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStealthLaunchFlags

func GetStealthLaunchFlags() []string

GetStealthLaunchFlags returns Chrome flags for stealth mode.

Types

type Browser

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

Browser wraps rod.Browser with enhanced functionality.

func New

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

New creates a new browser instance.

func (*Browser) ActivePage

func (b *Browser) ActivePage() *rod.Page

ActivePage returns the currently active page.

func (*Browser) ClearAndType

func (b *Browser) ClearAndType(ctx context.Context, elementIndex int, text string, elementMap *dom.ElementMap) error

ClearAndType clears an input and types new text.

func (*Browser) Click

func (b *Browser) Click(ctx context.Context, elementIndex int, elementMap *dom.ElementMap) error

Click clicks on an element by index.

func (*Browser) ClickAt

func (b *Browser) ClickAt(ctx context.Context, x, y float64) error

ClickAt clicks at specific coordinates.

func (*Browser) Close

func (b *Browser) Close() error

Close shuts down the browser and cleans up resources.

func (*Browser) CloseTab

func (b *Browser) CloseTab(tabID string) error

CloseTab closes a tab by ID.

func (*Browser) DoubleClick

func (b *Browser) DoubleClick(ctx context.Context, elementIndex int, elementMap *dom.ElementMap) error

DoubleClick double-clicks on an element by index.

func (*Browser) EvaluateJS

func (b *Browser) EvaluateJS(ctx context.Context, script string) (string, error)

EvaluateJS evaluates JavaScript code on the page.

func (*Browser) ExtractContent

func (b *Browser) ExtractContent(ctx context.Context) (string, error)

ExtractContent extracts text content from the page.

func (*Browser) Focus

func (b *Browser) Focus(ctx context.Context, elementIndex int, elementMap *dom.ElementMap) error

Focus focuses on an element.

func (*Browser) GetElementMap

func (b *Browser) GetElementMap(ctx context.Context) (*dom.ElementMap, error)

GetElementMap extracts interactive elements from the current page.

func (*Browser) GetTitle

func (b *Browser) GetTitle() string

GetTitle returns the current page title.

func (*Browser) GetURL

func (b *Browser) GetURL() string

GetURL returns the current page URL.

func (*Browser) GoBack

func (b *Browser) GoBack(ctx context.Context) error

GoBack navigates back in history.

func (*Browser) GoForward

func (b *Browser) GoForward(ctx context.Context) error

GoForward navigates forward in history.

func (*Browser) Hover

func (b *Browser) Hover(ctx context.Context, elementIndex int, elementMap *dom.ElementMap) error

Hover moves the mouse to hover over an element.

func (*Browser) IsPageReady

func (b *Browser) IsPageReady() bool

IsPageReady checks if the current page is ready for screenshot capture.

func (*Browser) ListTabs

func (b *Browser) ListTabs() []TabInfo

ListTabs returns information about all open tabs.

func (*Browser) Navigate

func (b *Browser) Navigate(ctx context.Context, url string) error

Navigate navigates the current page to a URL.

func (*Browser) NewTab

func (b *Browser) NewTab(ctx context.Context, url string) (string, error)

NewTab creates a new tab and optionally navigates to a URL.

func (*Browser) Reload

func (b *Browser) Reload(ctx context.Context) error

Reload reloads the current page.

func (*Browser) Screenshot

func (b *Browser) Screenshot(ctx context.Context, fullPage bool) ([]byte, error)

Screenshot takes a screenshot of the current page. Uses the enhanced screenshot package with proper page readiness checks.

func (*Browser) ScreenshotAfterAction

func (b *Browser) ScreenshotAfterAction(ctx context.Context) ([]byte, error)

ScreenshotAfterAction captures a screenshot after an action completes. Waits for page stability before capturing.

func (*Browser) ScreenshotAfterActionWithAnnotations

func (b *Browser) ScreenshotAfterActionWithAnnotations(ctx context.Context, elementMap *dom.ElementMap) ([]byte, error)

ScreenshotAfterActionWithAnnotations captures an annotated screenshot after an action.

func (*Browser) ScreenshotSafe

func (b *Browser) ScreenshotSafe(ctx context.Context, fullPage bool) ([]byte, error)

ScreenshotSafe takes a screenshot, returning nil (not error) for blank pages. This is useful for agent loops where blank screenshots should be skipped.

func (*Browser) ScreenshotSafeWithAnnotations

func (b *Browser) ScreenshotSafeWithAnnotations(ctx context.Context, elementMap *dom.ElementMap) ([]byte, error)

ScreenshotSafeWithAnnotations takes an annotated screenshot, returning nil for blank pages.

func (*Browser) ScreenshotWithAnnotations

func (b *Browser) ScreenshotWithAnnotations(ctx context.Context, elementMap *dom.ElementMap, fullPage bool) ([]byte, error)

ScreenshotWithAnnotations takes a screenshot with element annotations. This is the main entry point for annotated screenshots.

func (*Browser) Scroll

func (b *Browser) Scroll(ctx context.Context, direction string, amount float64, elementIndex *int, elementMap *dom.ElementMap) error

Scroll scrolls the page or an element.

func (*Browser) ScrollToElement

func (b *Browser) ScrollToElement(ctx context.Context, elementIndex int, elementMap *dom.ElementMap) error

ScrollToElement scrolls an element into view.

func (*Browser) SendKeys

func (b *Browser) SendKeys(ctx context.Context, keys string) error

SendKeys sends keyboard keys to the page.

func (*Browser) SetMaxElements

func (b *Browser) SetMaxElements(max int)

SetMaxElements sets the maximum number of elements to extract.

func (*Browser) Start

func (b *Browser) Start(ctx context.Context) error

Start launches the browser.

func (*Browser) SwitchTab

func (b *Browser) SwitchTab(tabID string) error

SwitchTab switches to a tab by ID.

func (*Browser) TypeText

func (b *Browser) TypeText(ctx context.Context, elementIndex int, text string, elementMap *dom.ElementMap) error

TypeText types text into an element by index.

func (*Browser) WaitForPageReady

func (b *Browser) WaitForPageReady(ctx context.Context, timeout time.Duration) error

WaitForPageReady waits until the page is ready, with timeout.

func (*Browser) WaitStable

func (b *Browser) WaitStable(ctx context.Context) error

WaitStable waits for the page to become stable.

type Config

type Config struct {
	// Headless runs the browser without a visible window.
	Headless bool

	// ProfileDir is the directory for browser profiles.
	ProfileDir string

	// ProfileName is the name of the profile to use.
	// Empty string uses a temporary profile.
	ProfileName string

	// Viewport is the browser viewport size.
	ViewportWidth  int
	ViewportHeight int

	// ShowHighlight shows visual feedback for actions.
	ShowHighlight bool

	// HighlightDuration is how long to show highlights.
	HighlightDuration time.Duration

	// Debug enables verbose logging.
	Debug bool

	// ShowAnnotations enables element annotations on screenshots.
	// When true, screenshots include bounding boxes and index labels.
	ShowAnnotations bool

	// Stealth configures anti-detection measures.
	Stealth StealthConfig
}

Config holds browser configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a default browser configuration.

type ElementMapAdapter

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

ElementMapAdapter adapts dom.ElementMap to screenshot.ElementMapInterface.

func NewElementMapAdapter

func NewElementMapAdapter(em *dom.ElementMap) *ElementMapAdapter

NewElementMapAdapter creates an adapter for annotation.

func (*ElementMapAdapter) GetElements

func (a *ElementMapAdapter) GetElements() []screenshotpkg.ElementInfo

GetElements returns elements as screenshot.ElementInfo slice.

func (*ElementMapAdapter) Len

func (a *ElementMapAdapter) Len() int

Len returns the number of elements.

type StealthConfig

type StealthConfig struct {
	// EnableStealth enables stealth mode with anti-detection.
	EnableStealth bool

	// UserAgent overrides the browser user agent.
	UserAgent string

	// Locale sets the browser locale (e.g., "en-US").
	Locale string

	// Timezone sets the browser timezone (e.g., "America/New_York").
	Timezone string

	// WebGLVendor spoofs the WebGL vendor.
	WebGLVendor string

	// WebGLRenderer spoofs the WebGL renderer.
	WebGLRenderer string

	// HumanLikeDelays adds random delays between actions.
	HumanLikeDelays bool

	// MinDelay minimum delay between actions (ms).
	MinDelay int

	// MaxDelay maximum delay between actions (ms).
	MaxDelay int
}

StealthConfig configures anti-detection measures.

func DefaultStealthConfig

func DefaultStealthConfig() StealthConfig

DefaultStealthConfig returns sensible stealth defaults.

type TabInfo

type TabInfo struct {
	ID     string
	URL    string
	Title  string
	Active bool
}

TabInfo contains information about an open tab.

Jump to

Keyboard shortcuts

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