Documentation
¶
Overview ¶
Package browser drives a real Chromium/Chrome instance over the Chrome DevTools Protocol via go-rod/rod, giving the agent's browser_* tools a pure-Go backend with no Node.js or Playwright dependency. See roadmap/v0.5.0/j1-browser-automation-rod.md for the full spec.
Index ¶
- Variables
- type Manager
- func (m *Manager) Click(ctx context.Context, selector string) error
- func (m *Manager) Close(_ context.Context) error
- func (m *Manager) Hotkey(ctx context.Context, keys string) error
- func (m *Manager) Inspect(ctx context.Context, selector string) (string, error)
- func (m *Manager) Navigate(ctx context.Context, url, waitUntil string) (NavigateResult, error)
- func (m *Manager) Screenshot(ctx context.Context, selector string, fullPage bool) ([]byte, error)
- func (m *Manager) Scroll(ctx context.Context, selector string, deltaX, deltaY float64) error
- func (m *Manager) Status() Status
- func (m *Manager) Type(ctx context.Context, selector, text string, submit bool) error
- func (m *Manager) Wait(ctx context.Context, selector, text string, networkIdle bool, ...) error
- type NavigateResult
- type Status
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoBinaryFound means no system Chrome/Chromium/Edge binary was // found on PATH or in well-known install locations. Never triggers an // automatic download — see findChromeBinary. ErrNoBinaryFound = errors.New("no Chrome/Chromium binary found") // ErrLaunchFailed means a binary was found but the browser process // failed to start or the initial CDP connection failed. ErrLaunchFailed = errors.New("browser launch failed") // condition did not complete before its deadline. ErrNavigationTimeout = errors.New("navigation timed out") // ErrSelectorNotFound means a CSS selector did not resolve to an // element before its deadline. ErrSelectorNotFound = errors.New("selector not found") // ErrActionDenied means the manager's session was already torn down // by an explicit browser_close. Once closed, a Manager never // relaunches — close only ever reduces capability, per the safety // model in the roadmap doc. ErrActionDenied = errors.New("action denied: browser session is closed") )
Stable error taxonomy the browser_* tools map to user-facing messages. Every error this package returns wraps exactly one of these via %w, so callers can classify failures with errors.Is regardless of the underlying rod/CDP error type.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the session-scoped browser lifecycle: at most one launched Chrome/Chromium process and one active page, lazily started on the first action call. Every exported method takes mu for its full duration — including the underlying CDP round-trip — because there is exactly one page to drive; overlapping calls would race on it with no benefit, so serializing here is simpler and safer than trying to prove any subset of calls is independent. This is also what a concurrent `go test -race` exercise over Manager is checking.
func NewManager ¶
func NewManager() *Manager
NewManager returns an unlaunched Manager. The browser process starts lazily on the first action call that needs it (see ensureLocked); browser_status and browser_wait never trigger a launch.
func (*Manager) Close ¶
Close tears down the browser process and removes its temp profile directory. Idempotent: safe to call multiple times (an explicit browser_close, then again via CleanupTool.Cleanup at session exit). Once closed, the manager never relaunches — every later action call returns ErrActionDenied instead of silently starting a new browser.
func (*Manager) Screenshot ¶
func (*Manager) Wait ¶
func (m *Manager) Wait(ctx context.Context, selector, text string, networkIdle bool, timeout time.Duration) error
Wait deliberately does NOT launch the browser: waiting is defined as blocking until an already-visible condition is met, and a session that was never launched has nothing to wait for. Launching a process is a real state change, which is exactly what browser_wait's no-approval exemption assumes it never does. A non-positive timeout (the "built-in timeout" the tool docs promise) falls back to m.timeout() rather than waiting unbounded — the same policy every other action gets automatically.
type NavigateResult ¶
type NavigateResult struct {
}
NavigateResult is the outcome of a successful browser_navigate call.
type Status ¶
Status is a point-in-time snapshot of the manager's lifecycle state, returned by browser_status. Computing it never launches a browser or otherwise changes state — it only reports the binary path (discovered on demand, cheaply, via PATH/well-known-location checks) and whatever session is already running.