browser

package
v0.0.0-...-b59f3eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package browser implements the opt-in browser tool family (issue #94): a chromedp-driven headless Chromium whose traffic is forced through the agent's EgressProxy, exposed to the LLM as token-optimized tools that exchange indexed page digests instead of raw HTML.

Index

Constants

This section is empty.

Variables

View Source
var ErrStale = errors.New("stale element index: the page changed since the last snapshot")

ErrStale is returned when an interaction references a generation older than the current page state (the page navigated or was re-snapshotted since the LLM last saw it). Tools catch it and return a fresh digest so the model recovers in one turn.

View Source
var ToolNames = []string{
	"browser_navigate",
	"browser_state",
	"browser_click",
	"browser_fill",
	"browser_extract",
	"browser_screenshot",
}

ToolNames lists the browser tool family in registration order. Useful for tests and for denied_tools documentation.

Functions

func HeadlessFromEnv

func HeadlessFromEnv() bool

HeadlessFromEnv reports whether the browser should run headless. Defaults to true; FORGE_BROWSER_HEADLESS=false or 0 opts into headful mode for local debugging.

func RegisterTools

func RegisterTools(reg *coretools.Registry, m *Manager) error

RegisterTools registers the browser tool family against a live Manager. Fail-closed: a manager without a proxy must never have been constructed (NewManager enforces it), but re-assert here since this is the last gate before the LLM can drive the browser.

func ResolveBinary

func ResolveBinary() (string, error)

ResolveBinary locates a Chromium-compatible browser binary. FORGE_BROWSER_BIN takes precedence and must point at an existing file; otherwise candidates are probed via exec.LookPath (absolute candidates via os.Stat).

Types

type Config

type Config struct {
	// BinaryPath is the resolved absolute path to a Chromium-compatible binary.
	BinaryPath string
	// Headless launches with --headless=new when true.
	Headless bool
	// ProxyURL is the EgressProxy address (http://127.0.0.1:<port>). Required:
	// the manager refuses to launch an unproxied browser.
	ProxyURL string
	// WorkDir is the agent working directory; the throwaway browser profile
	// and screenshot fallback directory live under it.
	WorkDir string
	// AllowSensitiveFill permits browser_fill on password/payment fields.
	AllowSensitiveFill bool

	NavTimeout    time.Duration
	ActionTimeout time.Duration
}

Config holds everything the Manager needs to launch and drive Chromium.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager owns at most one Chromium process per agent, launched lazily on the first tool call and stopped by the runner on shutdown. All tool executions are serialized: the LLM drives a single logical tab.

func NewManager

func NewManager(cfg Config) (*Manager, error)

NewManager validates cfg and returns an unlaunched Manager.

func (*Manager) Click

func (m *Manager) Click(index int, gen int64, maxEls int) (pageSnapshot, error)

Click resolves index to fresh viewport coordinates and dispatches a trusted CDP mouse click, then returns the post-action snapshot.

func (*Manager) Extract

func (m *Manager) Extract(mode, selector string) (content string, url string, err error)

Extract returns the page content in the requested mode ("text", "links", "html") plus the current URL. Pagination happens in the tool layer.

func (*Manager) Fill

func (m *Manager) Fill(index int, text string, gen int64, submit bool, allowSensitive bool, maxEls int) (pageSnapshot, error)

Fill types text into the element at index: focus via trusted click, select existing content, replace it with CDP Input.insertText (fires native input events, so React/Vue controlled inputs see the change), then dispatch change. Select elements pick the matching option instead. Protected fields (password/payment autocomplete) are refused unless allowSensitive.

func (*Manager) Navigate

func (m *Manager) Navigate(url string, waitMS int, maxEls int) (pageSnapshot, error)

Navigate loads url and returns a fresh snapshot.

func (*Manager) Screenshot

func (m *Manager) Screenshot(fullPage bool) ([]byte, error)

Screenshot captures the viewport (or full page) as PNG bytes.

func (*Manager) Snapshot

func (m *Manager) Snapshot(maxEls int, scrollToIndex int, scrollPages float64) (pageSnapshot, error)

Snapshot re-reads the current page (optionally scrolling first).

func (*Manager) Stop

func (m *Manager) Stop()

Stop shuts the browser down and removes the throwaway profile. Idempotent.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL