devbrowser

package
v0.11.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0, MIT Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrNetworkIsolationUnavailable = errors.New("dev-browser: restricted-network browsing is unavailable: request-time destination isolation is not implemented")

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

type HeadingEntry struct {
	Level int    `json:"level"`
	Text  string `json:"text"`
}

HeadingEntry is one h1-h6 in document order.

type LinkEntry

type LinkEntry struct {
	Text string `json:"text"`
	Href string `json:"href"`
}

LinkEntry is one <a href>. Text is the link's visible label.

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

func NewManagerWithOptions(options Options) *Manager

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

func (m *Manager) Click(name, selector string) (*Snapshot, error)

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) Close

func (m *Manager) Close(name string)

Close drops a named page. No-op if the page doesn't exist.

func (*Manager) ListPages

func (m *Manager) ListPages() []string

ListPages returns the names of currently-open pages. Deterministic order (not guaranteed alphabetical — we iterate the map).

func (*Manager) Open

func (m *Manager) Open(name, rawURL string) (*Snapshot, error)

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.

func (*Manager) Snapshot

func (m *Manager) Snapshot(name string) (*Snapshot, error)

Snapshot returns the current structured view of a named page without navigating. Useful after a Click or Type when the page has changed.

func (*Manager) Type

func (m *Manager) Type(name, selector, text string) (*Snapshot, error)

Type types text into the first input matching the selector. Same safety story as Click — separate op, no JS injection vector. We clear the field first so successive Type calls don't append on top.

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.

Jump to

Keyboard shortcuts

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