Documentation
¶
Overview ¶
Package browser provides headless Chrome automation for form filling
Index ¶
- Constants
- func BrokerDomains(website, portal string) []string
- type AutomationSession
- func (s *AutomationSession) Act(caller context.Context, snapshot, ref, action, value string) (*Snapshot, error)
- func (s *AutomationSession) Close()
- func (s *AutomationSession) Observe(caller context.Context) (*Snapshot, error)
- func (s *AutomationSession) Open(caller context.Context, raw string) (*Snapshot, error)
- type Browser
- type BrowserConfig
- type CaptchaInfo
- type ConfirmationHandler
- type ConfirmationResult
- type Control
- type FieldMapping
- type FillResult
- type FormFiller
- type FormResult
- type Snapshot
- type URLPolicy
Constants ¶
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
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) Close ¶ added in v1.3.0
func (s *AutomationSession) Close()
type Browser ¶
type Browser struct {
// contains filtered or unexported fields
}
Browser wraps chromedp for headless Chrome automation
func New ¶
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) 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 ¶
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 (*ConfirmationHandler) ClickConfirmationLink ¶
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 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 ¶
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
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.