Documentation
¶
Overview ¶
Package browser drives a Chromium-family browser through the Chrome DevTools Protocol for the agent's browser tool (spec_parity_027 §5.2): its own throwaway profile, never the user's, with every request it makes going through a proxy that applies the web rules.
Index ¶
- Variables
- func Find(path string) (string, error)
- func PublicAddr(addr netip.Addr) bool
- type Browser
- func (b *Browser) Back(ctx context.Context) (Page, error)
- func (b *Browser) Click(ctx context.Context, selector string) error
- func (b *Browser) Close() error
- func (b *Browser) Console() []ConsoleLine
- func (b *Browser) Eval(ctx context.Context, script string) (string, error)
- func (b *Browser) HTML(ctx context.Context, selector string, max int) (string, bool, error)
- func (b *Browser) Navigate(ctx context.Context, u string) (Page, error)
- func (b *Browser) Page(ctx context.Context) (Page, error)
- func (b *Browser) Refused() []string
- func (b *Browser) Screenshot(ctx context.Context, full bool) ([]byte, error)
- func (b *Browser) Select(ctx context.Context, selector, value string) error
- func (b *Browser) Text(ctx context.Context, selector string, max int) (string, bool, error)
- func (b *Browser) Type(ctx context.Context, selector, text string, add, submit bool) error
- type ConsoleLine
- type Options
- type Page
Constants ¶
This section is empty.
Variables ¶
var ErrBlockedAddress = errors.New("not a public address")
ErrBlockedAddress: the browser tried to reach an address that isn't public.
var ErrNoBrowser = errors.New("no Chrome, Chromium, Edge or Brave found: install one or set browser.path")
ErrNoBrowser: no Chromium-family browser was found.
Functions ¶
func PublicAddr ¶
PublicAddr reports whether addr is a routable public address: not loopback, private, link-local (cloud metadata), CGNAT, multicast or unspecified.
Types ¶
type Browser ¶
type Browser struct {
// contains filtered or unexported fields
}
Browser is a running browser with one page.
func Attach ¶
Attach drives the page at a DevTools WebSocket address, in a browser someone else started: its network isn't filtered (Options.Host and AllowLocal don't apply), but page loads still go through Navigation.
func (*Browser) Console ¶
func (b *Browser) Console() []ConsoleLine
Console is the console's messages since the last call.
func (*Browser) Eval ¶
Eval runs a script the model wrote in the page and returns its value (awaited, as JSON unless a string).
func (*Browser) Refused ¶
Refused is what the browser was stopped from reaching since the last call.
func (*Browser) Screenshot ¶
Screenshot is a PNG of the viewport, or of the whole page.
type ConsoleLine ¶
ConsoleLine is one message of the page's console, or an uncaught error.
type Options ¶
type Options struct {
// Path is the browser to run; empty finds Chrome, Chromium, Edge or
// Brave.
Path string
// Visible shows its window; by default it runs headless.
Visible bool
// Width and Height are the viewport (default 1280×800).
Width, Height int
// AllowLocal lets it reach loopback and private addresses (the user's
// own app); link-local ones (cloud metadata) never.
AllowLocal bool
// Host decides each host it would reach (deny_domains); nil allows all.
Host func(host string) error
// those Navigate is asked for (links, redirects, forms): nil allows
// all.
Navigation func(u *url.URL) error
// Timeout bounds a page load (default 30s).
Timeout time.Duration
}
Options configure a browser.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package browsertest is a fake DevTools page, to test code driving a browser without one: it answers the commands package browser sends as a simple page would, and records them.
|
Package browsertest is a fake DevTools page, to test code driving a browser without one: it answers the commands package browser sends as a simple page would, and records them. |