{"modulePath":"github.com/lichdotdev/lich","version":"v0.93.1","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package browser\n\n## Types\n\n```go\ntype Handle struct {\n\tID     string `json:\"id\"`\n\tURL    string `json:\"url\"`\n\tTitle  string `json:\"title\"`\n\tOwner  string `json:\"owner\"`\n\tHeaded bool   `json:\"headed\"`\n}\n```\nHandle 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.\n\n```go\ntype Interactive struct {\n\tIndex   int    `json:\"index\"`\n\tTag     string `json:\"tag\"`\n\tType    string `json:\"type,omitempty\"`\n\tRole    string `json:\"role,omitempty\"`\n\tText    string `json:\"text\"`\n\tHref    string `json:\"href,omitempty\"`\n\tRect    Rect   `json:\"rect\"`\n\tFilled  *bool  `json:\"filled,omitempty\"`\n\tChecked *bool  `json:\"checked,omitempty\"`\n}\n```\nInteractive 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.\n\n```go\ntype Launcher func(dir string, headed bool, scale float64) (Page, error)\n```\nLauncher starts a Chromium with its own user-data-dir. headed is a real window; false is headless, which draws at scale until it is closed. The directory is the caller's to delete.\n\n```go\ntype Page interface {\n\tNavigate(ctx context.Context, url string) error\n\t// Info reads the page, or, when within is not empty, the subtree of the\n\t// first element that CSS selector matches. A selector that matches nothing\n\t// or is invalid is an error that leaves the browser as it is.\n\tInfo(ctx context.Context, within string) (PageInfo, error)\n\t// HasText says whether text is in the page's visible text, the whole\n\t// document's and not only the viewport's.\n\tHasText(ctx context.Context, text string) (bool, error)\n\t// Settle waits until a navigation the last action may have started has\n\t// its document, bounded by domSettle, and then until the fetches that\n\t// began since have landed and the page stopped changing, bounded by\n\t// quietMax.\n\tSettle(ctx context.Context, since browserTime) error\n\t// ActionTime reads the same monotonic clock as Chrome's request events.\n\tActionTime(ctx context.Context) (time.Duration, error)\n\t// Click returns where it clicked, in CSS pixels.\n\tClick(ctx context.Context, t Target) (x, y float64, err error)\n\tType(ctx context.Context, text string, clear bool, t Target) error\n\tPress(ctx context.Context, key string, t Target) error\n\t// Screenshot writes the viewport, at shotScale image pixels per CSS\n\t// pixel, and returns the viewport's size in CSS pixels.\n\tScreenshot(ctx context.Context, dest string) (w, h int, err error)\n\t// AnnotatedScreenshot is Screenshot after a fresh Info read, with each\n\t// element's index drawn on it at its box.\n\tAnnotatedScreenshot(ctx context.Context, dest string) (w, h int, err error)\n\tReload(ctx context.Context) error\n\tBack(ctx context.Context) error\n\tForward(ctx context.Context) error\n\t// Scroll turns the wheel by dy CSS pixels at at, or at the viewport's\n\t// middle when at is nil, and returns where it turned it.\n\tScroll(ctx context.Context, at *point, dy int) (x, y float64, err error)\n\tFocus(ctx context.Context) error\n\t// Eval runs script in the page, awaiting a promise it returns, and\n\t// returns its value: a string as it is, anything else as JSON. A script\n\t// that throws is an error carrying the exception's text.\n\tEval(ctx context.Context, script string) (string, error)\n\t// Cookies and SetCookies carry a browser's cookies, session ones included,\n\t// into the process that replaces it.\n\tCookies(ctx context.Context) ([]*network.CookieParam, error)\n\tSetCookies(ctx context.Context, cookies []*network.CookieParam) error\n\t// Listen hands the page what to call with each screencast frame (a tab's\n\t// id and its base64 JPEG), with its URL and title whenever they change, with each step of a\n\t// download it starts, with each error its console shows, and with each\n\t// JavaScript dialog it opens, then nil once that dialog is closed, and\n\t// with its tabs whenever one opens, closes, comes to the front or changes\n\t// its URL or title.\n\tListen(onFrame func(tab, data string), onInfo func(url, title string), onDownload func(guid string, d api.BrowserDownload), onConsoleError func(text string), onDialog func(*api.BrowserDialog), onTabs func([]api.BrowserTab))\n\t// OnReload hands the page what to call with true when its front tab starts\n\t// a reload and false once the reloaded document is ready.\n\tOnReload(onReload func(started bool))\n\t// NewTab opens a blank tab in front; SelectTab brings the tab id to the\n\t// front; CloseTab closes it, unless it is the last one. Every other call\n\t// acts on the front tab.\n\tNewTab(ctx context.Context) error\n\t// IndexNext is the element index Info hands out next. SetIndexNext\n\t// carries it into the browser that replaces this one, so a number the\n\t// agent holds is never handed to a second element.\n\tIndexNext() int\n\tSetIndexNext(n int)\n\tSelectTab(ctx context.Context, id string) error\n\tCloseTab(ctx context.Context, id string) error\n\t// DevTools shows in the pane, in place of the front tab, that tab's\n\t// DevTools, a tab of its own the agent never sees, opening it first when\n\t// it has none. SelectTab and CloseTab take its id too; every agent call\n\t// still acts on the page.\n\tDevTools(ctx context.Context) error\n\t// AnswerDialog answers the open JavaScript dialog: OK with text (a\n\t// prompt's answer) when accept, Cancel otherwise. Every other call that\n\t// runs the page's script or input fails with errDialogOpen while one is\n\t// open.\n\tAnswerDialog(ctx context.Context, accept bool, text string) error\n\t// OnFileChooser hands the page what to call when a file input asks for\n\t// files, in the input's own mode; the paths it answers fill the input,\n\t// and none leaves it as it was.\n\tOnFileChooser(pick func(page.FileChooserOpenedMode) ([]string, error))\n\tScreencast(ctx context.Context, v Viewport) error\n\t// Still is what the screencast shows, as the front tab's id and a base64\n\t// PNG.\n\tStill(ctx context.Context) (tab, data string, err error)\n\tStopScreencast(ctx context.Context) error\n\tResize(ctx context.Context, v Viewport) error\n\tMouse(ctx context.Context, m api.BrowserMouseOptions) error\n\tKey(ctx context.Context, k api.BrowserKeyOptions) error\n\tInsertText(ctx context.Context, text string) error\n\t// Selection is the text selected in the page, \"\" in a password field.\n\tSelection(ctx context.Context) (string, error)\n\t// ElementAt is the element under x,y, zero when the point holds none;\n\t// Locate is the box of the element each selector finds, zero for none,\n\t// after scrolling reveal's element into view when reveal is set.\n\tElementAt(ctx context.Context, x, y float64) (api.BrowserElement, error)\n\tLocate(ctx context.Context, selectors []string, reveal string) ([]api.BrowserRect, error)\n\tAlive() bool\n\tClose() error\n}\n```\nPage is one Chromium tab the service drives. chrome.go is the real one; tests inject a fake.\n\n```go\ntype PageInfo struct {\n\tURL         string        `json:\"url\"`\n\tTitle       string        `json:\"title\"`\n\tText        string        `json:\"text\"`\n\tInteractive []Interactive `json:\"interactive\"`\n\tTruncated   bool          `json:\"truncated\"`\n\t// Error is the page script's refusal of a within selector.\n\tError string `json:\"error,omitempty\"`\n\t// InteractiveSame is the service's: Interactive is left out as the list\n\t// the agent last heard.\n\tInteractiveSame bool `json:\"-\"`\n\t// Downloads and the console errors are the service's to fill, never the\n\t// page script's.\n\tDownloads         []api.BrowserDownload `json:\"-\"`\n\tConsoleErrors     []string              `json:\"-\"`\n\tConsoleErrorsMore int                   `json:\"-\"`\n\tDialogs           []api.BrowserDialog   `json:\"-\"`\n}\n```\nPageInfo is what the agent reads instead of a screenshot: the URL, the visible text, and the interactive nodes it can click or type into.\n\n```go\ntype Rect struct {\n\tX int `json:\"x\"`\n\tY int `json:\"y\"`\n\tW int `json:\"w\"`\n\tH int `json:\"h\"`\n}\n```\nRect is an element's viewport box, integer pixels.\n\n```go\ntype Service struct {\n\t// contains filtered or unexported fields\n}\n```\nService is one Chromium context per lich session: the page the window shows beside the session and the page the agent drives are the same one. Headless until someone asks for a window; headed after OpenVisible.\n\n```go\nfunc New(emit func(name string, data any)) *Service\n```\nNew 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.\n\n```go\nfunc (s *Service) ActOnTab(_ context.Context, opts api.BrowserTabOptions) (api.BrowserPageInfo, error)\n```\nActOnTab is the agent opening, selecting or closing a tab, answered with the page then in front.\n\n```go\nfunc (s *Service) AnnotatedScreenshot(id, dest string) (string, error)\n```\nAnnotatedScreenshot is Screenshot with the indexes a click takes drawn on it. The read behind them is not told: the agent got no list in text.\n\n```go\nfunc (s *Service) Answer(_ context.Context, opts api.BrowserDialogOptions) (api.None, error)\n```\nAnswer 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.\n\n```go\nfunc (s *Service) AnswerDialog(_ context.Context, opts api.BrowserDialogOptions) (api.BrowserPageInfo, error)\n```\nAnswerDialog 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.\n\n```go\nfunc (s *Service) Attach(owner string, v Viewport) (Handle, error)\n```\nAttach 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.\n\n```go\nfunc (s *Service) AttachView(_ context.Context, opts api.BrowserViewOptions) (api.BrowserHandle, error)\n```\nAttachView shows this session's page in a pane.\n\n```go\nfunc (s *Service) Back(id string) error\n```\nBack goes back in history.\n\n```go\nfunc (s *Service) Capture(_ context.Context, opts api.BrowserScreenshotOptions) (string, error)\n```\nCapture writes a PNG of this session's page and returns its path.\n\n```go\nfunc (s *Service) Cleanup() error\n```\nCleanup closes every browser this process started. Wired from main so a window-close exit does not leave Chromiums behind.\n\n```go\nfunc (s *Service) Click(id string, t Target) error\n```\nClick sends a real mouse event at the target, not element.click().\n\n```go\nfunc (s *Service) ClickAt(_ context.Context, opts api.BrowserClickOptions) (api.BrowserPageInfo, error)\n```\nClickAt clicks in this session's browser.\n\n```go\nfunc (s *Service) Close(id string) error\n```\nClose tears down one browser, by handle id or by the lich session that owns it.\n\n```go\nfunc (s *Service) CloseOne(_ context.Context, opts api.SessionIDOptions) (api.None, error)\n```\nCloseOne tears down this session's browser.\n\n```go\nfunc (s *Service) CloseOwnedBy(owner string) error\n```\nCloseOwnedBy tears down the browser of a lich session that is going away. Missing is not an error: most sessions never opened one.\n\n```go\nfunc (s *Service) DefaultView(_ context.Context, opts api.BrowserDefaultViewOptions) (api.None, error)\n```\nDefaultView sets the size a page no pane shows lays out at.\n\n```go\nfunc (s *Service) Detach(owner string) error\n```\nDetach 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. A browser in its own window is left alone: an override there pins the page and the window's own resizing stops laying it out.\n\n```go\nfunc (s *Service) DetachView(_ context.Context, opts api.SessionIDOptions) (api.None, error)\n```\nDetachView stops a pane's frames.\n\n```go\nfunc (s *Service) DevTools(owner string) error\n```\nDevTools is the person opening DevTools for the front tab in the pane, or selecting it.\n\n```go\nfunc (s *Service) DevToolsView(_ context.Context, opts api.SessionIDOptions) (api.None, error)\n```\nDevToolsView opens or selects the front tab's DevTools in the pane.\n\n```go\nfunc (s *Service) ElementAtPoint(_ context.Context, opts api.BrowserPointOptions) (api.BrowserElement, error)\n```\nElementAtPoint is the element under a point of this session's page.\n\n```go\nfunc (s *Service) Eval(_ context.Context, opts api.BrowserEvalOptions) (string, error)\n```\n\n```go\nfunc (s *Service) Forward(id string) error\n```\nForward goes forward in history.\n\n```go\nfunc (s *Service) Go(_ context.Context, opts api.BrowserOpenOptions) (api.BrowserHandle, error)\n```\nGo loads a URL in this session's already-open browser.\n\n```go\nfunc (s *Service) GoBack(_ context.Context, opts api.SessionIDOptions) (api.None, error)\n```\nGoBack goes back in this session's history.\n\n```go\nfunc (s *Service) GoForward(_ context.Context, opts api.SessionIDOptions) (api.None, error)\n```\nGoForward goes forward in this session's history.\n\n```go\nfunc (s *Service) Handles(_ context.Context, opts api.SessionIDOptions) ([]api.BrowserHandle, error)\n```\nHandles returns this session's browser, or an empty list.\n\n```go\nfunc (s *Service) Info(id, within string) (PageInfo, error)\n```\nInfo returns the page the agent is looking at, or the subtree of the first element within matches. Never includes form values.\n\n```go\nfunc (s *Service) Keep(owner string) error\n```\nKeep answers the reaper's question about owner's browser with keep: it stays, and is asked about again once it sits idle another idle window.\n\n```go\nfunc (s *Service) KeepIdle(_ context.Context, opts api.SessionIDOptions) (api.None, error)\n```\nKeepIdle keeps this session's idle browser for another idle window.\n\n```go\nfunc (s *Service) KeyInput(_ context.Context, opts api.BrowserKeyOptions) (api.None, error)\n```\nKeyInput passes one key from the pane.\n\n```go\nfunc (s *Service) List(owner string) ([]Handle, error)\n```\nList returns this session's browser, or an empty list. Never null: a script should not have to tell those apart.\n\n```go\nfunc (s *Service) ListTabs(_ context.Context, opts api.SessionIDOptions) ([]api.BrowserTab, error)\n```\nListTabs is this session's browser's tabs.\n\n```go\nfunc (s *Service) LocateElements(_ context.Context, opts api.BrowserLocateOptions) ([]api.BrowserRect, error)\n```\nLocateElements is where the elements opts.Selectors find stand now, after scrolling opts.Reveal's element into view when it is set.\n\n```go\nfunc (s *Service) MouseInput(_ context.Context, opts api.BrowserMouseOptions) (api.None, error)\n```\nMouseInput passes one pointer event from the pane.\n\n```go\nfunc (s *Service) Nav(owner, action, rawURL string) error\n```\nNav runs the pane's toolbar: back, forward, reload, or go to url.\n\n```go\nfunc (s *Service) NavView(_ context.Context, opts api.BrowserNavOptions) (api.None, error)\n```\nNavView runs the pane's toolbar.\n\n```go\nfunc (s *Service) Navigate(id, rawURL string) (Handle, error)\n```\nNavigate loads url in this session's browser.\n\n```go\nfunc (s *Service) Open(owner, rawURL string) (Handle, error)\n```\nOpen 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.\n\n```go\nfunc (s *Service) OpenURL(_ context.Context, opts api.BrowserOpenOptions) (api.BrowserHandle, error)\n```\nOpenURL navigates this session's browser, creating a headless one when the card has not opened a window.\n\n```go\nfunc (s *Service) OpenVisible(owner string) (Handle, error)\n```\nOpenVisible 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).\n\n```go\nfunc (s *Service) Press(id, key string, t Target) error\n```\nPress 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.\n\n```go\nfunc (s *Service) PressKey(_ context.Context, opts api.BrowserPressOptions) (api.BrowserPageInfo, error)\n```\nPressKey presses one named key in this session's browser.\n\n```go\nfunc (s *Service) Read(_ context.Context, opts api.BrowserInfoOptions) (api.BrowserPageInfo, error)\n```\nRead 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.\n\n```go\nfunc (s *Service) Reap()\n```\nReap asks the window, once each, whether to close the headless browsers no pane shows that have sat idle past the idle window. Close or Keep answers.\n\n```go\nfunc (s *Service) Reload(id string) error\n```\nReload reloads the current page.\n\n```go\nfunc (s *Service) ReloadPage(_ context.Context, opts api.SessionIDOptions) (api.None, error)\n```\nReloadPage reloads this session's page.\n\n```go\nfunc (s *Service) Resize(owner string, v Viewport) error\n```\nResize 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.\n\n```go\nfunc (s *Service) ResizeView(_ context.Context, opts api.BrowserViewOptions) (api.None, error)\n```\nResizeView lays the page out at the pane's new size.\n\n```go\nfunc (s *Service) Running() []api.BrowserState\n```\nRunning is every browser this process runs, for a window catching up.\n\n```go\nfunc (s *Service) RunningStates(_ context.Context, _ api.None) ([]api.BrowserState, error)\n```\nRunningStates is every browser this process runs, for a window catching up.\n\n```go\nfunc (s *Service) Screenshot(id, dest string) (string, error)\n```\nScreenshot writes a PNG to dest (created if empty: inside the profile dir) and returns that path. The bytes stay off the transcript.\n\n```go\nfunc (s *Service) Scroll(id string, dy int) error\n```\nScroll moves the viewport by dy CSS pixels (positive is down). It turns the wheel where the agent last acted, else in the middle.\n\n```go\nfunc (s *Service) ScrollBy(_ context.Context, opts api.BrowserScrollOptions) (api.None, error)\n```\nScrollBy scrolls this session's page.\n\n```go\nfunc (s *Service) SelectedText(_ context.Context, opts api.SessionIDOptions) (string, error)\n```\nSelectedText is the text selected in this session's page.\n\n```go\nfunc (s *Service) SetDefaultView(v Viewport, window float64)\n```\nSetDefaultView 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. window is the window's own scale: a pane's browser launched under another relaunches once it holds still.\n\n```go\nfunc (s *Service) SetLocal(isLocal func(raw string) bool, local func(owner, raw string) (string, error))\n```\nSetLocal 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.\n\n```go\nfunc (s *Service) SetPicker(pickFile func(title string) (string, error), pickFiles func(title string) ([]string, error))\n```\nSetPicker wires the host's file picker (internal/project), which a page's file input opens. Startup wiring, called before anything serves.\n\n```go\nfunc (s *Service) Show(_ context.Context, opts api.SessionIDOptions) (api.BrowserHandle, error)\n```\nShow brings this session's browser on screen.\n\n```go\nfunc (s *Service) TabAct(opts api.BrowserTabOptions) error\n```\nTabAct is the agent opening, selecting or closing a tab, which the pane plays as its cursor on the header's tabs. A new tab with a URL then loads it, as Navigate does. A DevTools tab is not one the agent can name, and selecting the tab it drives leaves the pane on that tab's DevTools.\n\n```go\nfunc (s *Service) TabNav(opts api.BrowserTabOptions) error\n```\nTabNav is the person opening, selecting or closing a tab in the pane.\n\n```go\nfunc (s *Service) TabView(_ context.Context, opts api.BrowserTabOptions) (api.None, error)\n```\nTabView runs the pane's tabs.\n\n```go\nfunc (s *Service) Tabs(id string) ([]api.BrowserTab, error)\n```\nTabs is this session's browser's tabs, in the pane's order.\n\n```go\nfunc (s *Service) TextInput(_ context.Context, opts api.BrowserTextOptions) (api.None, error)\n```\nTextInput types text the pane's input method committed.\n\n```go\nfunc (s *Service) Type(id, text string, clear bool, t Target) error\n```\nType sends keystrokes. clear selects-and-replaces; the typed text never comes back through Info.\n\n```go\nfunc (s *Service) TypeText(_ context.Context, opts api.BrowserTypeOptions) (api.None, error)\n```\nTypeText types into this session's browser.\n\n```go\ntype Target struct {\n\tIndex    *int     `json:\"index,omitempty\"`\n\tSelector string   `json:\"selector,omitempty\"`\n\tX        *float64 `json:\"x,omitempty\"`\n\tY        *float64 `json:\"y,omitempty\"`\n\t// contains filtered or unexported fields\n}\n```\nTarget 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 pixels of the last screenshot's image, the viewport's CSS pixels scaled by shotScale. Coordinates win when set, then selector, then index.\n\n```go\ntype Viewport struct {\n\tW, H  int\n\tScale float64\n}\n```\nViewport is the pane a page is drawn into: W and H in CSS pixels, Scale the device pixels per CSS pixel.\n\n","path":"github.com/lichdotdev/lich/internal/browser","name":"browser","synopsis":"","isRedistributable":true}
