Documentation
¶
Overview ¶
Package browser provides an agent-driven headless Chrome wrapper built on chromedp. A single Browser holds one chromedp session against a long-lived Chrome process; tools call into it through the Manager singleton.
Index ¶
- type Browser
- func (b *Browser) Click(selector string) error
- func (b *Browser) Close()
- func (b *Browser) Eval(jsExpr string) (any, error)
- func (b *Browser) Fill(selector, value string) error
- func (b *Browser) IsOpen() bool
- func (b *Browser) Markdown() (string, error)
- func (b *Browser) Navigate(url string) error
- func (b *Browser) Open(parent context.Context) error
- func (b *Browser) OuterHTML(selector string) (string, error)
- func (b *Browser) Screenshot(width, height int) ([]byte, error)
- func (b *Browser) ScreenshotElement(selector string) ([]byte, error)
- func (b *Browser) Select(selector, value string) error
- func (b *Browser) Text(selector string) (string, error)
- func (b *Browser) Title() (string, error)
- func (b *Browser) URL() (string, error)
- func (b *Browser) WaitForNavigation(timeout time.Duration) error
- func (b *Browser) WaitForSelector(selector string, timeout time.Duration) error
- type Manager
- type Options
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Browser ¶
type Browser struct {
// contains filtered or unexported fields
}
Browser wraps a chromedp session. Methods are safe to call from a single goroutine; the underlying chromedp context serializes navigation and DOM access. Use Manager when you need cross-tool coordination.
func New ¶
New constructs a Browser with the given options. Options.Headless defaults to true when zero-value (Open will set it explicitly).
func (*Browser) Close ¶
func (b *Browser) Close()
Close tears down the chromedp session and the Chrome process. Idempotent.
func (*Browser) Markdown ¶
Markdown extracts the main content of the page and returns a tiny markdown rendering. Heuristic: prefer <main> > <article> > <body>.
func (*Browser) Open ¶
Open spawns the underlying Chrome process and waits until it is ready. It is safe to call Open more than once; subsequent calls are no-ops.
func (*Browser) Screenshot ¶
Screenshot captures a PNG of the current viewport. width/height ≤0 use the chromedp default viewport.
func (*Browser) ScreenshotElement ¶
ScreenshotElement captures a PNG of a single CSS-selected element.
func (*Browser) Text ¶
Text extracts visible text from the first element matching selector. An empty selector defaults to "body".
func (*Browser) WaitForNavigation ¶
WaitForNavigation waits until the body of the next page is ready. Useful after triggering a click that initiates navigation.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the singleton browser session for an overkill process. Lazy-spawns Chrome on the first call to Get and tears it down via Shutdown.
func NewManager ¶
NewManager constructs a Manager bound to the given options. The underlying Browser is not spawned until Get is called.
type Options ¶
type Options struct {
// Headless=true is retained for existing callers. False uses the default
// headless mode; use Visible to explicitly open a visible window.
Headless bool
Visible bool
ChromePath string
UserAgent string
// Timeout caps each launch/action; zero retains operation defaults.
Timeout time.Duration
}
Options configures the browser process. An empty Options is valid and uses chromedp defaults (headless, auto-detected Chrome path).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package devbrowser provides a narrow structured Chrome interface.
|
Package devbrowser provides a narrow structured Chrome interface. |