Documentation
¶
Index ¶
- type Handle
- type Interactive
- type Launcher
- type Page
- type PageInfo
- type Rect
- type Service
- func (s *Service) Attach(owner string, v Viewport) (Handle, error)
- func (s *Service) AttachView(_ context.Context, opts api.BrowserViewOptions) (api.BrowserHandle, error)
- func (s *Service) Back(id string) error
- func (s *Service) Capture(_ context.Context, opts api.BrowserScreenshotOptions) (string, error)
- func (s *Service) Cleanup() error
- func (s *Service) Click(id string, t Target) error
- func (s *Service) ClickAt(_ context.Context, opts api.BrowserClickOptions) (api.BrowserPageInfo, error)
- func (s *Service) Close(id string) error
- func (s *Service) CloseOne(_ context.Context, opts api.SessionIDOptions) (api.None, error)
- func (s *Service) CloseOwnedBy(owner string) error
- func (s *Service) Detach(owner string) error
- func (s *Service) DetachView(_ context.Context, opts api.SessionIDOptions) (api.None, error)
- func (s *Service) Forward(id string) error
- func (s *Service) Go(_ context.Context, opts api.BrowserOpenOptions) (api.BrowserHandle, error)
- func (s *Service) GoBack(_ context.Context, opts api.SessionIDOptions) (api.None, error)
- func (s *Service) GoForward(_ context.Context, opts api.SessionIDOptions) (api.None, error)
- func (s *Service) Handles(_ context.Context, opts api.SessionIDOptions) ([]api.BrowserHandle, error)
- func (s *Service) Info(id string) (PageInfo, error)
- func (s *Service) KeyInput(_ context.Context, opts api.BrowserKeyOptions) (api.None, error)
- func (s *Service) List(owner string) ([]Handle, error)
- func (s *Service) MouseInput(_ context.Context, opts api.BrowserMouseOptions) (api.None, error)
- func (s *Service) Nav(owner, action, rawURL string) error
- func (s *Service) NavView(_ context.Context, opts api.BrowserNavOptions) (api.None, error)
- func (s *Service) Navigate(id, rawURL string) (Handle, error)
- func (s *Service) Open(owner, rawURL string) (Handle, error)
- func (s *Service) OpenURL(_ context.Context, opts api.BrowserOpenOptions) (api.BrowserHandle, error)
- func (s *Service) OpenVisible(owner string) (Handle, error)
- func (s *Service) Press(id, key string, t Target) error
- func (s *Service) PressKey(_ context.Context, opts api.BrowserPressOptions) (api.BrowserPageInfo, error)
- func (s *Service) Read(_ context.Context, opts api.SessionIDOptions) (api.BrowserPageInfo, error)
- func (s *Service) Reap()
- func (s *Service) Reload(id string) error
- func (s *Service) ReloadPage(_ context.Context, opts api.SessionIDOptions) (api.None, error)
- func (s *Service) Resize(owner string, v Viewport) error
- func (s *Service) ResizeView(_ context.Context, opts api.BrowserViewOptions) (api.None, error)
- func (s *Service) Running() []api.BrowserState
- func (s *Service) RunningStates(_ context.Context, _ api.None) ([]api.BrowserState, error)
- func (s *Service) Screenshot(id, dest string) (string, error)
- func (s *Service) Scroll(id string, dy int) error
- func (s *Service) ScrollBy(_ context.Context, opts api.BrowserScrollOptions) (api.None, error)
- func (s *Service) SelectedText(_ context.Context, opts api.SessionIDOptions) (string, error)
- func (s *Service) Show(_ context.Context, opts api.SessionIDOptions) (api.BrowserHandle, error)
- func (s *Service) TextInput(_ context.Context, opts api.BrowserTextOptions) (api.None, error)
- func (s *Service) Type(id, text string, clear bool, t Target) error
- func (s *Service) TypeText(_ context.Context, opts api.BrowserTypeOptions) (api.None, error)
- type Target
- type Viewport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handle ¶
type Handle struct {
ID string `json:"id"`
URL string `json:"url"`
Title string `json:"title"`
Owner string `json:"owner"`
Headed bool `json:"headed"`
}
Handle is what Open and OpenVisible return: the id later calls take, and enough for a card or a tool result to say which window it is.
type Interactive ¶
type Interactive struct {
Index int `json:"index"`
Tag string `json:"tag"`
Type string `json:"type,omitempty"`
Role string `json:"role,omitempty"`
Text string `json:"text"`
Href string `json:"href,omitempty"`
Rect Rect `json:"rect"`
Filled *bool `json:"filled,omitempty"`
Checked *bool `json:"checked,omitempty"`
}
Interactive is one clickable or fillable node from page-info. It never carries a control's value — filled/checked say that typing landed without putting the content in the transcript.
type Launcher ¶
Launcher starts a Chromium with its own user-data-dir. headed is a real window; false is headless. The directory is the caller's to delete.
type Page ¶
type Page interface {
Info(ctx context.Context) (PageInfo, error)
// Settle waits until a navigation the last action may have started has
// its document, bounded by domSettle.
Settle(ctx context.Context) error
// Click returns where it clicked, in CSS pixels.
Click(ctx context.Context, t Target) (x, y float64, err error)
Type(ctx context.Context, text string, clear bool, t Target) error
Press(ctx context.Context, key string, t Target) error
Screenshot(ctx context.Context, dest string) error
Reload(ctx context.Context) error
Back(ctx context.Context) error
Forward(ctx context.Context) error
// Scroll turns the wheel by dy CSS pixels at at, or at the viewport's
// middle when at is nil, and returns where it turned it.
Scroll(ctx context.Context, at *point, dy int) (x, y float64, err error)
Focus(ctx context.Context) error
// Cookies and SetCookies carry a browser's cookies, session ones included,
// into the process that replaces it.
Cookies(ctx context.Context) ([]*network.CookieParam, error)
SetCookies(ctx context.Context, cookies []*network.CookieParam) error
// Listen hands the page what to call with each screencast frame (base64
// JPEG) and with its URL and title whenever they change.
Listen(onFrame func(data string), onInfo func(url, title string))
Screencast(ctx context.Context, v Viewport) error
StopScreencast(ctx context.Context) error
Resize(ctx context.Context, v Viewport) error
Mouse(ctx context.Context, m api.BrowserMouseOptions) error
Key(ctx context.Context, k api.BrowserKeyOptions) error
InsertText(ctx context.Context, text string) error
// Selection is the text selected in the page, "" in a password field.
Selection(ctx context.Context) (string, error)
Alive() bool
Close() error
}
Page is one Chromium tab the service drives. chrome.go is the real one; tests inject a fake.
type PageInfo ¶
type PageInfo struct {
URL string `json:"url"`
Title string `json:"title"`
Text string `json:"text"`
Interactive []Interactive `json:"interactive"`
Truncated bool `json:"truncated"`
}
PageInfo is what the agent reads instead of a screenshot: the URL, the visible text, and the interactive nodes it can click or type into.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is one Chromium context per lich session: the window Browser tab opens and the page the agent drives are the same one. Headless until someone asks for a window; headed after OpenVisible.
func New ¶
New starts a service that launches the system Chromium (chromium.FindBrowser) into an ephemeral profile, never the lich --app one, and tells the window about each browser through emit.
func (*Service) Attach ¶
Attach shows this session's browser in a pane sized v, starting a headless one at about:blank when there is none. The page the agent left stays as it is: the pane only starts watching it.
func (*Service) AttachView ¶
func (s *Service) AttachView(_ context.Context, opts api.BrowserViewOptions) (api.BrowserHandle, error)
AttachView shows this session's page in a pane.
func (*Service) Cleanup ¶
Cleanup closes every browser this process started. Wired from main so a window-close exit does not leave Chromiums behind.
func (*Service) ClickAt ¶
func (s *Service) ClickAt(_ context.Context, opts api.BrowserClickOptions) (api.BrowserPageInfo, error)
ClickAt clicks in this session's browser.
func (*Service) Close ¶
Close tears down one browser, by handle id or by the lich session that owns it.
func (*Service) CloseOwnedBy ¶
CloseOwnedBy tears down the browser of a lich session that is going away. Missing is not an error: most sessions never opened one.
func (*Service) Detach ¶
Detach stops the frames of a pane that closed or went off screen. The browser keeps running for the agent.
func (*Service) DetachView ¶
DetachView stops a pane's frames.
func (*Service) Go ¶
func (s *Service) Go(_ context.Context, opts api.BrowserOpenOptions) (api.BrowserHandle, error)
Go loads a URL in this session's already-open browser.
func (*Service) Handles ¶
func (s *Service) Handles(_ context.Context, opts api.SessionIDOptions) ([]api.BrowserHandle, error)
Handles returns this session's browser, or an empty list.
func (*Service) List ¶
List returns this session's browser, or an empty list. Never null: a script should not have to tell those apart.
func (*Service) MouseInput ¶
MouseInput passes one pointer event from the pane.
func (*Service) Open ¶
Open navigates this session's browser to url, creating a headless one if none exists. A headed window the user already opened is reused, not replaced.
func (*Service) OpenURL ¶
func (s *Service) OpenURL(_ context.Context, opts api.BrowserOpenOptions) (api.BrowserHandle, error)
OpenURL navigates this session's browser, creating a headless one when the card has not opened a window.
func (*Service) OpenVisible ¶
OpenVisible brings this session's browser on screen. No browser yet: a headed window at about:blank. Already headed: focus it. Headless only: reopen it as a window (promote).
func (*Service) Press ¶
Press sends one named key (Enter, Tab, Escape, …) as a real key event. An optional target is focused first, the same way Type focuses before typing.
func (*Service) PressKey ¶
func (s *Service) PressKey(_ context.Context, opts api.BrowserPressOptions) (api.BrowserPageInfo, error)
PressKey presses one named key in this session's browser.
func (*Service) Read ¶
func (s *Service) Read(_ context.Context, opts api.SessionIDOptions) (api.BrowserPageInfo, error)
Read returns the page the agent is looking at.
func (*Service) Reap ¶
func (s *Service) Reap()
Reap closes headless browsers no pane shows that have sat idle past the idle window.
func (*Service) ReloadPage ¶
ReloadPage reloads this session's page.
func (*Service) Resize ¶
Resize lays the page out again at the pane's new size. A pane showing it gets its frames at that size too: the screencast keeps the size it started at, and the window would stretch the smaller frames over the larger pane.
func (*Service) ResizeView ¶
ResizeView lays the page out at the pane's new size.
func (*Service) Running ¶
func (s *Service) Running() []api.BrowserState
Running is every browser this process runs, for a window catching up.
func (*Service) RunningStates ¶
RunningStates is every browser this process runs, for a window catching up.
func (*Service) Screenshot ¶
Screenshot writes a PNG to dest (created if empty: inside the profile dir) and returns that path. The bytes stay off the transcript.
func (*Service) Scroll ¶
Scroll moves the viewport by dy CSS pixels (positive is down). It turns the wheel where the agent last acted, else in the middle.
func (*Service) SelectedText ¶
SelectedText is the text selected in this session's page.
func (*Service) Show ¶
func (s *Service) Show(_ context.Context, opts api.SessionIDOptions) (api.BrowserHandle, error)
Show brings this session's browser on screen.
type Target ¶
type Target struct {
Index *int `json:"index,omitempty"`
Selector string `json:"selector,omitempty"`
X *float64 `json:"x,omitempty"`
Y *float64 `json:"y,omitempty"`
}
Target picks an element for click and type. Index is the one page-info stamped (data-lich-idx); selector is a CSS query; x/y are viewport coordinates. Coordinates win when set, then selector, then index.