browser

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package browser drives a sandboxed headless Chromium process over the Chrome DevTools Protocol (CDP) while forcing every subresource TCP socket through an in-process SSRF-guarded loopback CONNECT proxy.

SSRF Isolation Model

Untrusted JavaScript executing inside a headless browser can attempt `fetch("http://192.168.1.1/")`, cloud-metadata probes (`169.254.169.254`), or DNS-rebinding subresource loads. EdgeFetch launches Chromium with `--proxy-server=http://127.0.0.1:<port>` and `--host-resolver-rules="MAP * ~NOTFOUND , EXCLUDE 127.0.0.1"`, disabling Chromium's internal DNS resolver so every socket traverses SSRFProxy:

  1. Plain-HTTP proxy requests (`GET http://...`) are rejected with `403 Forbidden`; only `CONNECT host:443` tunnels are permitted.
  2. Target authorities are validated against the caller's URL allowlist (blocking recursive coordination-hub fetches, non-443 ports, and IP literals).
  3. Outbound TCP dials attach `politeness.RejectNonPublicPeer` (`net.Dialer.Control`) so DNS-rebinding targets resolving to RFC 1918, loopback, link-local, CGNAT, NAT64, or IPv6 transition prefixes abort before SYN.
  4. Rendered DOMs are checked via `extract.DetectRenderedChallenge`; anti-bot/CAPTCHA challenges halt immediately with ErrChallengeDetected and are never clicked through or waited out.

Index

Constants

This section is empty.

Variables

View Source
var ErrBrowserUnavailable = errors.New("headless Chromium is not installed on this node (deploy edgefetch_fat to enable browser rendering)")

ErrBrowserUnavailable indicates no headless Chromium binary is installed in the current runtime (e.g. distroless Lite).

View Source
var ErrChallengeDetected = errors.New("anti-bot challenge detected in rendered DOM")

ErrChallengeDetected is returned when a rendered DOM contains a CAPTCHA or anti-bot challenge; EdgeFetch halts immediately and never attempts to solve, click through, or wait out challenges.

Functions

func FindChromeBinary

func FindChromeBinary() string

FindChromeBinary locates an installed headless Chromium/Chrome/Edge/Brave executable across Linux, macOS, and Windows, enabling a ~8 MB desktop binary download to render JavaScript (`browser-v1` + `interact-v1`) using pre-installed OS browsers.

Types

type InteractAction

type InteractAction struct {
	Type     string `json:"type"`               // "click", "fill", "type", "press", "wait", "scroll", "select", "navigate"
	Selector string `json:"selector,omitempty"` // CSS selector for click/fill/type/select/scroll
	Value    string `json:"value,omitempty"`    // Input value for fill/type/select
	Key      string `json:"key,omitempty"`      // Key name for press (e.g. "Enter", "Tab", "Escape")
	URL      string `json:"url,omitempty"`      // HTTPS target for navigate
	WaitMs   int    `json:"waitMs,omitempty"`   // Milliseconds to pause after or during "wait"
}

InteractAction describes a single deterministic browser interaction step (`firecrawl_interact` parity).

type Output

type Output struct {
	Status           int
	Headers          http.Header
	FinalURL         string
	HTML             string
	ScreenshotBase64 string
	SessionID        string
}

Output holds the rendered DOM, HTTP metadata, screenshot, and optional session handle.

type Renderer

type Renderer struct {
	CheckRobots func(ctx context.Context, rawURL string) error
	// contains filtered or unexported fields
}

Renderer manages a shared headless Chromium process + SSRF-safe loopback CONNECT proxy.

func NewMockRenderer

func NewMockRenderer(wsURL string, allow func(*url.URL) error, userAgent string) *Renderer

NewMockRenderer creates a Renderer backed by an in-memory/loopback CDP WebSocket URL for deterministic unit tests.

func NewRenderer

func NewRenderer(chromeBin string, allow func(*url.URL) error, userAgent string, maxConcurrent int, log *slog.Logger) *Renderer

NewRenderer constructs a Renderer bounded to `maxConcurrent` simultaneous tabs (default 2).

func (*Renderer) Available

func (r *Renderer) Available() bool

Available reports whether a headless browser binary (or test override) is available.

func (*Renderer) Close

func (r *Renderer) Close() error

Close terminates any active Chromium subprocess, loopback SSRF proxy, and temporary profile directory.

func (*Renderer) CloseSession

func (r *Renderer) CloseSession(ctx context.Context, sessionID string) bool

CloseSession terminates a retained `interact` browser session immediately (`interact_stop`).

func (*Renderer) Execute

func (r *Renderer) Execute(ctx context.Context, task Task) (Output, error)

Execute runs a stateless page render or stateful multi-step `interact` turn inside an isolated incognito context.

type SSRFProxy

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

SSRFProxy is a loopback-only HTTP CONNECT tunnel (`127.0.0.1:0`) paired with Chromium's `--proxy-server` + `--host-resolver-rules="MAP * ~NOTFOUND , EXCLUDE 127.0.0.1"` flags.

Why this matters on Home Assistant OS: Untrusted JavaScript executing inside a headless browser can call `fetch("http://192.168.1.1/...")`, open WebSockets, or trigger DNS-rebinding subresources. By disabling Chromium's own DNS resolver (`MAP * ~NOTFOUND`) and forcing all connections through `SSRFProxy`, every subresource TCP dial passes through both `allow(*url.URL)` and `politeness.RejectNonPublicPeer` BEFORE the TCP SYN leaves the kernel.

func NewSSRFProxy

func NewSSRFProxy(allow func(*url.URL) error, customDial func(ctx context.Context, network, addr string) (net.Conn, error)) (*SSRFProxy, error)

NewSSRFProxy starts a loopback CONNECT proxy enforcing `allow` and `politeness.RejectNonPublicPeer` on every tunnel.

func (*SSRFProxy) Addr

func (p *SSRFProxy) Addr() string

Addr returns `127.0.0.1:<port>` suitable for `--proxy-server=http://<Addr()>`.

func (*SSRFProxy) Close

func (p *SSRFProxy) Close() error

Close shuts down the loopback proxy listener.

type Task

type Task struct {
	URL          string
	UserAgent    string
	Headers      map[string]string
	WaitForMs    int
	WaitSelector string
	Screenshot   bool
	Actions      []InteractAction
	SessionID    string // Optional existing session to resume
	KeepSession  bool   // Retain tab open for follow-up `interact` calls
	CloseSession bool   // Close `SessionID` immediately after or without running actions
}

Task describes a browser render or interaction request.

Jump to

Keyboard shortcuts

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