Documentation
¶
Overview ¶
Package livebrowser is the machine's real browser for the pane: a headless Chrome the runtime starts when a browser tab of the pane opens an outside site, driven over the DevTools protocol (CDP). The page's picture goes to the pane as a screencast, the person's mouse, keys, wheel and paste go back as input events, and the agent's tools act on the page through the same protocol. The proxy (internal/preview) keeps the machine's own servers and stands, where the page is rewritten, inspected and edited; this browser takes the sites the proxy cannot carry.
The browser is driven over a pipe (--remote-debugging-pipe), not a DevTools port: no process or page on the machine can reach the protocol, and so the profile's cookies, except the runtime through the pipe it holds.
Index ¶
- Variables
- func EnvArgs(value string) []string
- type Act
- type Acted
- type Config
- type Event
- type Frame
- type Info
- type Rect
- type Service
- func (s *Service) Available() bool
- func (s *Service) Close()
- func (s *Service) Open(ctx context.Context, id string, width, height int, scale float64) (*Tab, error)
- func (s *Service) ProfileDir() string
- func (s *Service) Refusal(raw string) string
- func (s *Service) Running() bool
- func (s *Service) Tabs() int
- type Socket
- type Tab
- func (t *Tab) Acked()
- func (t *Tab) Act(ctx context.Context, a Act) Acted
- func (t *Tab) Back() error
- func (t *Tab) Close()
- func (t *Tab) Ended() <-chan struct{}
- func (t *Tab) Evaluate(expression string, result any) error
- func (t *Tab) Forward() error
- func (t *Tab) Frames() <-chan Frame
- func (t *Tab) Info() (Info, error)
- func (t *Tab) InsertText(text string) error
- func (t *Tab) Key(kind, key, code, text string, vk, modifiers int) error
- func (t *Tab) Mouse(kind string, x, y float64, button string, buttons, modifiers, clicks int) error
- func (t *Tab) Navigate(url string) error
- func (t *Tab) Paced(on bool)
- func (t *Tab) Reload() error
- func (t *Tab) Resize(width, height int, scale float64) error
- func (t *Tab) Selection() (string, error)
- func (t *Tab) Sent()
- func (t *Tab) StartScreencast() error
- func (t *Tab) StopScreencast() error
- func (t *Tab) Touched()
- func (t *Tab) Updates() <-chan Info
- func (t *Tab) WaitSlot(ctx context.Context) bool
- func (t *Tab) Wheel(x, y, dx, dy float64, modifiers int) error
- func (t *Tab) Why() string
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("the browser's connection is closed")
ErrClosed: the browser's connection is gone.
Functions ¶
Types ¶
type Act ¶
type Act struct {
ID string `json:"id"`
Op string `json:"op"`
Ref string `json:"ref"`
Text string `json:"text"`
Key string `json:"key"`
Value string `json:"value"`
DY int `json:"dy"`
MS int `json:"ms"`
Submit bool `json:"submit"`
// Event is what a wait is for on a video or audio: ended, playing or paused.
Event string `json:"event"`
Tool string `json:"tool"`
Input string `json:"input"`
// Host is the site the person let the agent act on: a page that moved to another site since is not acted on.
Host string `json:"host"`
// contains filtered or unexported fields
}
Act is one action: op is snapshot, locate, click, type, press, hover, select, scroll, wait, tools or call; navigate and back are the tab's (the pane does them through the socket's nav and back).
type Acted ¶
type Acted struct {
ID string `json:"id"`
OK bool `json:"ok"`
Text string `json:"text"`
Rect *Rect `json:"rect"`
}
Acted is what an action came to; Rect is its element's box, for the agent's cursor in the pane.
type Config ¶
type Config struct {
// DataDir is the runtime's data directory: the browser's profile (cookies, sign-ins) lives in its live-browser/.
// One runtime is one person on one machine, so the profile is theirs alone.
DataDir string
// Binary is the browser to run; empty looks for google-chrome, chromium and their variants on PATH.
Binary string
// ExtraArgs are added to the browser's command line (RUNTIME_LIVE_BROWSER_ARGS).
ExtraArgs []string
// MaxTabs bounds the pages open at once; a tab past it is refused.
MaxTabs int
// IdleAfter closes the browser once no tab has been open for this long.
IdleAfter time.Duration
// Nice lowers the browser's priority (0 keeps it).
Nice int
// Local are the machine's own addresses (preview.SelfAddresses); Lookup resolves names (nil for the system's).
// Together they decide what the browser may load: see Refusal.
Local map[string]bool
Lookup preview.Lookup
// Log takes the service's notes.
Log func(level, msg string, kv ...any)
}
Config is how the service runs the browser.
type Event ¶
type Event struct {
SessionID string
Method string
Params json.RawMessage
}
Event is what Chrome tells of its own: a method with parameters, for the session it belongs to ("" for the browser).
type Info ¶
type Info struct {
URL string `json:"url"`
Title string `json:"title"`
CanBack bool `json:"canBack"`
CanForward bool `json:"canForward"`
Loading bool `json:"loading"`
}
Info is what the pane shows of the page besides its picture.
type Rect ¶
type Rect struct {
X float64 `json:"x"`
Y float64 `json:"y"`
Width float64 `json:"width"`
Height float64 `json:"height"`
}
Rect is an element's box in the page's viewport, CSS pixels.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service owns the one browser of the runtime: started on the first tab, closed when idle or when it dies.
func (*Service) Open ¶
func (s *Service) Open(ctx context.Context, id string, width, height int, scale float64) (*Tab, error)
Open gives a tab for the id (the pane's tab), starting the browser when it is not running. A tab that already exists is returned as it is: a page survives a reload of the pane. Past MaxTabs, the request is refused.
func (*Service) ProfileDir ¶
ProfileDir is where the browser keeps the person's cookies and sign-ins.
func (*Service) Refusal ¶
Refusal says why an address may not open in the live browser: "" when it may. The browser runs on the machine, so its servers and the private networks behind it stay with the proxy, which knows what is allowed there. The rule holds for every connection the browser makes, not only the address typed: see egress.
type Tab ¶
type Tab struct {
ID string
// contains filtered or unexported fields
}
Tab is one page of the browser, shown in one browser tab of the pane.
func (*Tab) Acked ¶
func (t *Tab) Acked()
Acked: the pane drew (or dropped) a picture; the pump may send the next, and the browser hears of one more taken.
func (*Tab) Act ¶
Act runs one action on the page and never fails loudly: a page that breaks it answers with words.
func (*Tab) Ended ¶
func (t *Tab) Ended() <-chan struct{}
Ended is closed when the tab is gone; Why says why.
func (*Tab) InsertText ¶
InsertText types text as one piece (a paste, an IME's composition).
func (*Tab) Mouse ¶
Mouse sends a pointer event: kind is mousePressed, mouseReleased or mouseMoved; x and y are CSS pixels.
func (*Tab) StartScreencast ¶
StartScreencast asks for the page's pictures as they change; one that runs is started over (a new size).
func (*Tab) StopScreencast ¶
StopScreencast ends the pictures while nobody looks.
func (*Tab) Touched ¶
func (t *Tab) Touched()
Touched: the person or the agent did something, or the page moved: the page is in motion, its pictures go on.
func (*Tab) WaitSlot ¶
WaitSlot waits until the pane has room for one more picture: at once for a pane that does not ack; a pane silent for holdMax is not waited for any longer. False when the context ended.