Documentation
¶
Index ¶
- type Handle
- type Interactive
- type Launcher
- type Page
- type PageInfo
- type Rect
- type Service
- func (s *Service) Answer(_ context.Context, opts api.BrowserDialogOptions) (api.None, error)
- func (s *Service) AnswerDialog(_ context.Context, opts api.BrowserDialogOptions) (api.BrowserPageInfo, error)
- 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) DefaultView(_ context.Context, opts api.BrowserDefaultViewOptions) (api.None, error)
- func (s *Service) Detach(owner string) error
- func (s *Service) DetachView(_ context.Context, opts api.SessionIDOptions) (api.None, error)
- func (s *Service) ElementAtPoint(_ context.Context, opts api.BrowserPointOptions) (api.BrowserElement, 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) LocateElements(_ context.Context, opts api.BrowserLocateOptions) ([]api.BrowserRect, 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.BrowserInfoOptions) (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) SetDefaultView(v Viewport)
- func (s *Service) SetLocal(isLocal func(raw string) bool, local func(owner, raw string) (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)
// HasText says whether text is in the page's visible text, the whole
// document's and not only the viewport's.
HasText(ctx context.Context, text string) (bool, 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), with its URL and title whenever they change, with each step of a
// download it starts, with each error its console shows, and with each
// JavaScript dialog it opens, then nil once that dialog is closed.
Listen(onFrame func(data string), onInfo func(url, title string), onDownload func(guid string, d api.BrowserDownload), onConsoleError func(text string), onDialog func(*api.BrowserDialog))
// AnswerDialog answers the open JavaScript dialog: OK with text (a
// prompt's answer) when accept, Cancel otherwise. Every other call that
// runs the page's script or input fails with errDialogOpen while one is
// open.
AnswerDialog(ctx context.Context, accept bool, text string) error
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)
// ElementAt is the element under x,y, zero when the point holds none;
// Locate is the box of the element each selector finds, zero for none,
// after scrolling reveal's element into view when reveal is set.
ElementAt(ctx context.Context, x, y float64) (api.BrowserElement, error)
Locate(ctx context.Context, selectors []string, reveal string) ([]api.BrowserRect, 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"`
// Downloads and the console errors are the service's to fill, never the
// page script's.
Downloads []api.BrowserDownload `json:"-"`
ConsoleErrors []string `json:"-"`
ConsoleErrorsMore int `json:"-"`
Dialogs []api.BrowserDialog `json:"-"`
}
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) Answer ¶ added in v0.81.0
Answer is the person answering the page's open dialog in the pane. The agent hears of it in its next page answer. A dialog the agent answered first leaves nothing to do, and that is no error.
func (*Service) AnswerDialog ¶ added in v0.81.0
func (s *Service) AnswerDialog(_ context.Context, opts api.BrowserDialogOptions) (api.BrowserPageInfo, error)
AnswerDialog is the agent answering the page's open dialog, which the pane plays as its cursor pressing the dialog's button. It answers with the page as it stands after.
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) DefaultView ¶ added in v0.81.0
func (s *Service) DefaultView(_ context.Context, opts api.BrowserDefaultViewOptions) (api.None, error)
DefaultView sets the size a page no pane shows lays out at.
func (*Service) Detach ¶
Detach stops the frames of a pane that closed or went off screen. The browser keeps running for the agent, at the window's size again rather than the pane's.
func (*Service) DetachView ¶
DetachView stops a pane's frames.
func (*Service) ElementAtPoint ¶ added in v0.81.0
func (s *Service) ElementAtPoint(_ context.Context, opts api.BrowserPointOptions) (api.BrowserElement, error)
ElementAtPoint is the element under a point of this session's page.
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) LocateElements ¶ added in v0.81.0
func (s *Service) LocateElements(_ context.Context, opts api.BrowserLocateOptions) ([]api.BrowserRect, error)
LocateElements is where the elements opts.Selectors find stand now, after scrolling opts.Reveal's element into view when it is set.
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.BrowserInfoOptions) (api.BrowserPageInfo, error)
Read returns the page the agent is looking at, once the text it waits for came or went. A wait that gives up still answers with the page.
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) SetDefaultView ¶ added in v0.81.0
SetDefaultView sets the size a headless page no pane shows lays out at, and lays out the running ones there. It is not a use: a window resized does not keep an idle browser from the reaper.
func (*Service) SetLocal ¶ added in v0.82.0
func (s *Service) SetLocal(isLocal func(raw string) bool, local func(owner, raw string) (string, error))
SetLocal sets how a local file, a file: URL or an absolute path, becomes a URL a session's browser may load: the http URL that serves it from that session's checkout (internal/preview). Unset, a local file is refused like any other blocked URL.
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.