browser

package
v1.5.7 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package browser provides headless Chrome automation for form filling

Index

Constants

View Source
const (
	CaptchaTypeRecaptchaV2  = "recaptcha_v2"
	CaptchaTypeRecaptchaV3  = "recaptcha_v3"
	CaptchaTypeHCaptcha     = "hcaptcha"
	CaptchaTypeTurnstile    = "cloudflare_turnstile"
	CaptchaTypeFunCaptcha   = "funcaptcha"
	CaptchaTypeImageCaptcha = "image_captcha"
	CaptchaTypeTextCaptcha  = "text_captcha"
	CaptchaTypeCloudflare   = "cloudflare_challenge"
	CaptchaTypeUnknown      = "unknown"
)

Variables

This section is empty.

Functions

func BrokerDomains added in v1.3.0

func BrokerDomains(website, portal string) []string

BrokerDomains derives destinations only from trusted local catalog entries.

Types

type AutomationSession added in v1.3.0

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

AutomationSession keeps one Chrome tab across MCP calls. Actions use refs from a fresh snapshot; agents never supply JavaScript.

func NewAutomationSession added in v1.3.0

func NewAutomationSession(cfg BrowserConfig, p *config.Profile, policy URLPolicy) (*AutomationSession, error)

func (*AutomationSession) Act added in v1.3.0

func (s *AutomationSession) Act(caller context.Context, snapshot, ref, action, value string) (*Snapshot, error)

func (*AutomationSession) Close added in v1.3.0

func (s *AutomationSession) Close()

func (*AutomationSession) Observe added in v1.3.0

func (s *AutomationSession) Observe(caller context.Context) (*Snapshot, error)

func (*AutomationSession) Open added in v1.3.0

func (s *AutomationSession) Open(caller context.Context, raw string) (*Snapshot, error)

type Browser

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

Browser wraps chromedp for headless Chrome automation

func New

func New(cfg BrowserConfig, profile *config.Profile, allowedDomains []string) (*Browser, error)

New creates a new Browser instance. allowedDomains restricts the hosts NavigateAndFill is willing to navigate to and autofill with profile PII (see matchesAllowedDomain); pass nil/empty to skip that check entirely (e.g. for callers that don't yet have a broker domain list).

func (*Browser) Close

func (b *Browser) Close()

Close cleans up browser resources

func (*Browser) NavigateAndFill

func (b *Browser) NavigateAndFill(url string, brokerID string, autoSubmit bool) (*FormResult, error)

NavigateAndFill navigates to a URL and attempts to fill any opt-out form

type BrowserConfig

type BrowserConfig struct {
	ExecutablePath string // Optional Chrome/Chromium executable override.
	Headless       bool
	Timeout        time.Duration
	ScreenshotDir  string
	UserAgent      string
	WindowWidth    int
	WindowHeight   int
	WaitForUser    bool         // If true, pause when CAPTCHA detected for user to solve
	WaitCallback   func() error // Called when waiting for user (e.g., to prompt in terminal)
}

BrowserConfig holds browser automation settings

func DefaultConfig

func DefaultConfig() BrowserConfig

DefaultConfig returns sensible default browser settings

type CaptchaInfo

type CaptchaInfo struct {
	Found bool
	Type  string // one of the CaptchaType constants
}

CaptchaInfo is the result of detectCaptcha.

func (CaptchaInfo) GetCaptchaDescription

func (c CaptchaInfo) GetCaptchaDescription() string

GetCaptchaDescription returns a human-readable description

func (CaptchaInfo) IsCaptchaBlocking

func (c CaptchaInfo) IsCaptchaBlocking() bool

IsCaptchaBlocking returns true if the CAPTCHA requires human intervention. reCAPTCHA v3 is invisible and usually doesn't.

type ConfirmationHandler

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

ConfirmationHandler handles clicking confirmation links from emails

func NewConfirmationHandler

func NewConfirmationHandler(brokerDomains []string) *ConfirmationHandler

NewConfirmationHandler creates a new handler with known broker domains

func (h *ConfirmationHandler) ClickConfirmationLink(confirmURL string, validateDomain bool) (*ConfirmationResult, error)

ClickConfirmationLink sends a GET request to the confirmation URL

func (*ConfirmationHandler) ExtractConfirmationStatus

func (h *ConfirmationHandler) ExtractConfirmationStatus(result *ConfirmationResult) string

ExtractConfirmationStatus extracts a human-readable status from the response

func (*ConfirmationHandler) ValidateDomain

func (h *ConfirmationHandler) ValidateDomain(confirmURL string) (bool, string, error)

ValidateDomain checks if the URL belongs to a known broker domain

type ConfirmationResult

type ConfirmationResult struct {
	Success      bool
	URL          string
	FinalURL     string
	StatusCode   int
	ResponseBody string
	ErrorMessage string
	RedirectPath []string
}

ConfirmationResult holds the outcome of clicking a confirmation link

type Control added in v1.3.0

type Control struct {
	Ref      string   `json:"ref"`
	Tag      string   `json:"tag"`
	Type     string   `json:"type"`
	Label    string   `json:"label"`
	Value    string   `json:"value"`
	Required bool     `json:"required"`
	Options  []string `json:"options,omitempty"`
}

type FieldMapping

type FieldMapping struct {
	FieldType    string
	ProfileValue string
	Selectors    []string
	Patterns     []string // Patterns to match in name/id/placeholder
}

FieldMapping maps detected field types to profile values

type FillResult

type FillResult struct {
	FilledFields  []string
	MissingFields []string
	Errors        []string
}

FillResult contains the outcome of form filling

type FormFiller

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

FormFiller handles form field detection and auto-filling

func NewFormFiller

func NewFormFiller(profile *config.Profile) *FormFiller

NewFormFiller creates a new FormFiller

func (*FormFiller) Fill

func (f *FormFiller) Fill(ctx context.Context) *FillResult

Fill detects and fills form fields

type FormResult

type FormResult struct {
	Success         bool
	URL             string
	BrokerID        string
	FieldsFilled    []string
	FieldsMissing   []string
	CaptchaFound    bool
	CaptchaType     string
	ScreenshotPath  string
	ErrorMessage    string
	SubmitAttempted bool
	FillErrors      []string // real (non-"not found") errors hit while filling fields, e.g. context timeouts
}

FormResult represents the outcome of a form fill attempt

type Snapshot added in v1.3.0

type Snapshot struct {
	ID                string    `json:"snapshot_id"`
	URL               string    `json:"url"`
	Title             string    `json:"title"`
	Text              string    `json:"text"`
	Controls          []Control `json:"controls"`
	Blocker           string    `json:"needs_user,omitempty"`
	Screenshot        string    `json:"screenshot,omitempty"`
	Validation        []string  `json:"validation_errors,omitempty"`
	SubmissionBlocked bool      `json:"submission_blocked,omitempty"`
	SensitiveControls bool      `json:"sensitive_controls,omitempty"`
}

func (Snapshot) Fingerprint added in v1.3.0

func (s Snapshot) Fingerprint() string

Fingerprint ignores IDs and screenshots so re-observing a page can't dodge the duplicate-action check.

type URLPolicy added in v1.3.0

type URLPolicy struct {
	Domains []string
	// ExactPaths pins page loads on a shared-platform host to the paths of the
	// catalog URLs: the host serves other companies' forms under other paths.
	ExactPaths  map[string][]string
	LocalOrigin string
}

URLPolicy is scoped to one broker, never the whole directory. Only the hosts in Domains (and their www. form) are allowed, not subdomains: on shared platforms a subdomain is another company's tenant. LocalOrigin is only for the demo/test server.

func NewURLPolicy added in v1.3.0

func NewURLPolicy(website, portal string) URLPolicy

func (URLPolicy) Validate added in v1.3.0

func (p URLPolicy) Validate(ctx context.Context, raw string) error

func (URLPolicy) ValidateNavigation added in v1.3.0

func (p URLPolicy) ValidateNavigation(ctx context.Context, raw string) error

ValidateNavigation is Validate plus the path pin, for page loads and frames. Subresources and XHR only need the host, since platforms serve shared assets.

Jump to

Keyboard shortcuts

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