Documentation
¶
Overview ¶
Package devbrowser provides a narrow structured Chrome interface.
Restricted-network browsing is currently unavailable: the default manager refuses browser operations before starting Chrome or resolving a destination. An application can deliberately opt into trusted-network browsing using NewManagerWithOptions. That mode permits local/private network access and uses ordinary Chrome networking, including page scripts and redirects. It provides no request-time destination isolation or DNS-rebinding protection.
The interface exposes Open, Snapshot, Click and Type, with structured results and operation timeouts. A narrow operation set is not a network sandbox.
Package devbrowser — snapshotForAI structured page extraction.
The model doesn't need raw HTML or a 3MB DOM dump. It needs a scannable summary it can reason about: title, headings, primary links, form fields, plus a bounded chunk of visible text. This file builds that summary from the live DOM via a single tiny JS payload — the only Evaluate() we allow ourselves to run, and only because there's no DOM-API-equivalent that returns pre-aggregated structured data.
We don't expose Evaluate to the agent. The model can't get arbitrary JS into the page; it can only ask for the snapshot.
Index ¶
- Variables
- type FormEntry
- type FormInput
- type HeadingEntry
- type LinkEntry
- type Manager
- func (m *Manager) Click(name, selector string) (*Snapshot, error)
- func (m *Manager) Close(name string)
- func (m *Manager) ListPages() []string
- func (m *Manager) Open(name, rawURL string) (*Snapshot, error)
- func (m *Manager) Shutdown()
- func (m *Manager) Snapshot(name string) (*Snapshot, error)
- func (m *Manager) Type(name, selector, text string) (*Snapshot, error)
- type Options
- type Page
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
ErrNetworkIsolationUnavailable means the requested restricted browser cannot be provided. The current Chrome API does not enforce a pinned, validated destination for every redirect, subresource, worker and other network request. Initial URL/DNS checks or CDP interception alone are not network isolation.
Functions ¶
This section is empty.
Types ¶
type FormEntry ¶
type FormEntry struct {
Action string `json:"action,omitempty"`
Method string `json:"method,omitempty"`
Inputs []FormInput `json:"inputs,omitempty"`
}
FormEntry is one <form>. Inputs lists the form's controls so the agent can decide what to fill before submitting.
type FormInput ¶
type FormInput struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Placeholder string `json:"placeholder,omitempty"`
Value string `json:"value,omitempty"`
}
FormInput is one input/textarea/select inside a form.
type HeadingEntry ¶
HeadingEntry is one h1-h6 in document order.
type Manager ¶
type Manager struct {
// PageTimeout caps how long any single op (Open, Snapshot,
// Click, Type) can take. Default 30s.
PageTimeout time.Duration
// IdleTimeout closes pages that haven't been touched in this
// long. Default 30min. 0 disables.
IdleTimeout time.Duration
// contains filtered or unexported fields
}
Manager owns the parent chromedp context (the actual browser process) and a map of named Pages. Lazy-spawn: the browser only starts when the first Open call hits.
func NewManager ¶
func NewManager() *Manager
NewManager constructs the default restricted-network manager. Restricted browsing is unavailable, so browser operations fail closed without traffic.
func NewManagerWithOptions ¶
NewManagerWithOptions accepts explicit application-owned network policy. TrustedNetwork permits local/private access; it is not an isolation bypass that an agent can request through Open, Click, Type or Snapshot arguments.
func (*Manager) Click ¶
Click clicks the first element matching the CSS selector on the named page. Returns the post-click snapshot so the agent sees the page state changed.
We expose Click as a separate op (not just "evaluate document.querySelector(s).click()") so the agent can't smuggle a raw JS expression in.
func (*Manager) ListPages ¶
ListPages returns the names of currently-open pages. Deterministic order (not guaranteed alphabetical — we iterate the map).
func (*Manager) Open ¶
Open navigates a named page to a URL. Creates the page on first call; reuses it on subsequent calls (so "search" → "google.com" then "search" → "duckduckgo.com" walks the same tab). URLs are checked for http(s) syntax and rejected userinfo. Only explicitly trusted networking can open pages; private/local destinations are allowed in that mode.
func (*Manager) Shutdown ¶
func (m *Manager) Shutdown()
Shutdown closes every open page + the parent browser. Idempotent.
type Options ¶
type Options struct {
// TrustedNetwork explicitly permits Chrome to access public, local and private
// networks. Only enable for browsing whose network access the operator trusts,
// such as an authenticated local development workflow. This does not provide
// restricted-network isolation, redirect checks or DNS-rebinding protection.
TrustedNetwork bool
}
Options are application-owned construction policy, never model tool input.
type Page ¶
type Page struct {
Name string
Created time.Time
LastUsed time.Time
// contains filtered or unexported fields
}
Page is one named tab the agent has open. We hold the chromedp.Context that drives its tab and a mutex so two concurrent tool calls on the same page serialize cleanly (chromedp itself doesn't serialize ops on a single context).
type Snapshot ¶
type Snapshot struct {
URL string `json:"url"`
Title string `json:"title"`
Headings []HeadingEntry `json:"headings,omitempty"`
Links []LinkEntry `json:"links,omitempty"`
Forms []FormEntry `json:"forms,omitempty"`
Text string `json:"text"`
TextLength int `json:"text_length"`
WasTruncated bool `json:"truncated,omitempty"`
}
Snapshot is the structured page content the agent reads. JSON- marshalable so tools can serialize without ceremony.