Documentation
¶
Overview ¶
Package browser drives a Chromium-family browser through the Chrome DevTools Protocol for the agent's browser tool (spec_027_parity §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
- type Transport
Constants ¶
This section is empty.
Variables ¶
var ErrBlockedAddress = errors.New("not a public address")
ErrBlockedAddress means 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 means 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 AttachTransport ¶ added in v0.8.4
AttachTransport drives the page at the other end of t, a relay to a browser someone else runs (the desktop app's own view, spec_050_agent_browser): as Attach, its network isn't filtered here (the other end filters it), but page loads still go through Navigation.
func (*Browser) Close ¶
Close stops the browser it launched (one it attached to isn't its to close) and removes its profile, unless it's kept (ProfileDir).
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
// KeepViewport leaves the page's size as it is (a view the user
// watches, sized by the window) instead of Width×Height.
KeepViewport bool
// ProfileDir is a profile kept between runs (a browser profile's,
// spec_049_browser_profiles BP-03): its sign-ins and cookies last, and
// Close leaves it. Empty: a new, empty profile, removed on Close.
ProfileDir string
}
Options configure a browser.
type Transport ¶ added in v0.8.4
Transport carries a DevTools Protocol connection's messages, whole, as JSON: a WebSocket to a browser Blitz started, or a relay to one someone else runs, such as the desktop app's own view (spec_050_agent_browser). ReadJSON blocks for the next message and fails once it's closed.
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. |