Documentation
¶
Overview ¶
Package browser drives a Chrome the operator runs beside the server, over the DevTools protocol: a fresh, isolated context per run, a page in it, and the few things a model needs — navigate, read the page as a tree it can point into, click, type, scroll, wait, screenshot. Every navigation and every request the page makes go through the same address guard as fetching a page: nothing private, nothing link-local, unless the operator listed it. Downloads are refused.
Nothing here launches Chrome. It connects to an endpoint, and tests speak to an in-process fake.
Index ¶
- type Browser
- type Context
- func (self *Context) Back(ctx context.Context) (*Location, error)
- func (self *Context) Click(ctx context.Context, where Target) (string, *Location, error)
- func (self *Context) Close() error
- func (self *Context) Evaluate(ctx context.Context, expression string, maximum int) (string, error)
- func (self *Context) Hover(ctx context.Context, where Target) (string, error)
- func (self *Context) LastUsed() time.Time
- func (self *Context) Navigate(ctx context.Context, address string) (*Location, error)
- func (self *Context) Press(ctx context.Context, key string) error
- func (self *Context) Screenshot(ctx context.Context, fullPage bool) ([]byte, error)
- func (self *Context) Scroll(ctx context.Context, direction string, amount int, where Target) error
- func (self *Context) Select(ctx context.Context, where Target, value string, index int) (string, error)
- func (self *Context) Snapshot(ctx context.Context, mode string, maximum int) (*Snapshot, error)
- func (self *Context) Type(ctx context.Context, where Target, text string, clearFirst, submit bool) error
- func (self *Context) Wait(ctx context.Context, condition, selector string, timeout time.Duration) (string, error)
- type Location
- type Settings
- type Snapshot
- type Target
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Browser ¶
type Browser struct {
// contains filtered or unexported fields
}
Browser is a connection to a Chrome.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is a fresh, isolated browser context with one page in it: no cookies, no storage, no history from anyone else.
func (*Context) Navigate ¶
Navigate opens an address, after the guard, and waits for the page to load.
func (*Context) Screenshot ¶
Screenshot is the viewport, or the whole page, as PNG.
func (*Context) Select ¶
func (self *Context) Select(ctx context.Context, where Target, value string, index int) (string, error)
Select chooses an option of a select by value, text or index.
func (*Context) Type ¶
func (self *Context) Type(ctx context.Context, where Target, text string, clearFirst, submit bool) error
Type types into an element, whatever kind it is. It is the person's agent doing what they asked; what stands between it and a field is the card they answer, not a list of fields kept here.
type Location ¶
type Location struct {
URL string `json:"url"`
Title string `json:"title"`
Status int `json:"status,omitempty"`
}
Location is where a navigation ended.
type Settings ¶
type Settings struct {
// Endpoint is http://host:9222 or a ws:// debugger address.
Endpoint string
// AllowPrivate lists hosts or CIDRs the operator lets the browser
// reach although they are private.
AllowPrivate []string
// ProxyListen is where the guarded proxy binds. Empty means every
// address on an unused port, and Chrome is told the address its own
// connection to this server came from -- which is reachable from
// wherever it is running.
ProxyListen string
}
Settings are what a browser needs.