browser

package
v0.4.9 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBrowserTimeoutMs = 30000

DefaultBrowserTimeoutMs is used when the caller supplies no timeout.

View Source
const MaxBrowserTimeoutMs = 120000

MaxBrowserTimeoutMs bounds how long a single browser operation may block a worker. Playwright treats 0 as "no timeout", which would pin a container and an API goroutine indefinitely.

View Source
const WorkspaceDir = "/workspace"

WorkspaceDir is the only directory inside a sandbox that browser output may be written to. It is the mount the API reads artifacts back from, so a path outside it produces a file the caller can never retrieve.

Variables

This section is empty.

Functions

func ClampTimeout added in v0.3.2

func ClampTimeout(ms int) int

ClampTimeout keeps a caller-supplied timeout inside a usable range.

func EscapePythonString added in v0.3.2

func EscapePythonString(s string) string

EscapePythonString renders s safe for interpolation into a single-quoted Python string literal. Backslashes must be doubled first, otherwise the escaping of the quotes themselves can be undone by a trailing backslash in the input. Newlines are escaped because a raw newline terminates the literal and lets the caller append arbitrary Python statements.

func ValidateImageFormat added in v0.3.2

func ValidateImageFormat(v string) (string, error)

ValidateImageFormat resolves a screenshot image format.

func ValidatePaperFormat added in v0.3.2

func ValidatePaperFormat(v string) (string, error)

ValidatePaperFormat resolves a PDF paper size.

func ValidateWaitUntil added in v0.3.2

func ValidateWaitUntil(v string) (string, error)

ValidateWaitUntil resolves a Playwright load-state option.

func ValidateWorkspacePath added in v0.3.2

func ValidateWorkspacePath(p, fallback string) (string, error)

ValidateWorkspacePath resolves a caller-supplied output path against the workspace and refuses anything that escapes it.

Traversal here does not cross the sandbox boundary — the path is interpreted inside the container — but "/workspace/../../etc/hosts" silently writes a file the caller cannot read back, and the cleaned path is also what gets interpolated into the generated Python. Resolving it up front means the generated script only ever names a location that exists for the artifact store.

Types

type BrowserSession

type BrowserSession struct {
	SessionID uuid.UUID
	CreatedAt time.Time
	LastUsed  time.Time
	PageCount int
}

BrowserSession tracks browser state for a session

type ExtractOpts

type ExtractOpts struct {
	Selector string // CSS selector (empty = entire page)
	Extract  string // "text", "html", "attributes"
}

ExtractOpts configures content extraction

type Manager

type Manager interface {
	// Navigate to a URL
	Navigate(ctx context.Context, sessionID uuid.UUID, url string, opts NavigateOpts) error

	// Take a screenshot
	Screenshot(ctx context.Context, sessionID uuid.UUID, opts ScreenshotOpts) (*ScreenshotResult, error)

	// Click an element
	Click(ctx context.Context, sessionID uuid.UUID, selector string) error

	// Fill an input field
	Fill(ctx context.Context, sessionID uuid.UUID, selector, value string) error

	// Extract content from the page
	Extract(ctx context.Context, sessionID uuid.UUID, opts ExtractOpts) (string, error)

	// Evaluate JavaScript
	Evaluate(ctx context.Context, sessionID uuid.UUID, script string) (interface{}, error)

	// Wait for an element or condition
	Wait(ctx context.Context, sessionID uuid.UUID, opts WaitOpts) error

	// Generate a PDF
	PDF(ctx context.Context, sessionID uuid.UUID, opts PDFOpts) (*PDFResult, error)

	// Close browser resources for a session
	Close(ctx context.Context, sessionID uuid.UUID) error
}

Manager provides browser automation capabilities for VaultRun sessions

func New

func New(docker *dockerpkg.Client, db *sqlx.DB, storage artifacts.Store) Manager

New creates a new browser manager

type NavigateOpts struct {
	WaitUntil string // "load", "domcontentloaded", "networkidle"
	Timeout   int    // milliseconds
}

NavigateOpts configures navigation behavior

type NetworkPolicy

type NetworkPolicy struct {
	AllowedHosts    []string
	BlockPrivateIPs bool
	BlockLocalhost  bool
	BlockMetadata   bool // Block cloud metadata endpoints (169.254.169.254, etc.)
}

NetworkPolicy defines allowed/blocked URLs for browser navigation

func DefaultNetworkPolicy

func DefaultNetworkPolicy() *NetworkPolicy

DefaultNetworkPolicy returns a secure default policy

func (*NetworkPolicy) ValidateURL added in v0.3.2

func (p *NetworkPolicy) ValidateURL(rawURL string) error

ValidateURL reports whether the policy permits navigating to rawURL.

type PDFOpts

type PDFOpts struct {
	Format string // "A4", "Letter"
	Path   string // Output path (optional)
}

PDFOpts configures PDF generation

type PDFResult

type PDFResult struct {
	ArtifactID uuid.UUID
	Path       string
	SizeBytes  int64
}

PDFResult contains PDF artifact info

type PlaywrightManager

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

PlaywrightManager implements Manager using Playwright via Docker exec

func (*PlaywrightManager) Click

func (m *PlaywrightManager) Click(ctx context.Context, sessionID uuid.UUID, selector string) error

Click clicks an element

func (*PlaywrightManager) Close

func (m *PlaywrightManager) Close(ctx context.Context, sessionID uuid.UUID) error

Close closes browser resources

func (*PlaywrightManager) Evaluate

func (m *PlaywrightManager) Evaluate(ctx context.Context, sessionID uuid.UUID, jsScript string) (interface{}, error)

Evaluate runs JavaScript in the browser

func (*PlaywrightManager) Extract

func (m *PlaywrightManager) Extract(ctx context.Context, sessionID uuid.UUID, opts ExtractOpts) (string, error)

Extract extracts content from the page

func (*PlaywrightManager) Fill

func (m *PlaywrightManager) Fill(ctx context.Context, sessionID uuid.UUID, selector, value string) error

Fill fills an input field

func (*PlaywrightManager) Navigate

func (m *PlaywrightManager) Navigate(ctx context.Context, sessionID uuid.UUID, targetURL string, opts NavigateOpts) error

Navigate navigates to a URL

func (*PlaywrightManager) PDF

func (m *PlaywrightManager) PDF(ctx context.Context, sessionID uuid.UUID, opts PDFOpts) (*PDFResult, error)

PDF generates a PDF of the current page

func (*PlaywrightManager) Screenshot

func (m *PlaywrightManager) Screenshot(ctx context.Context, sessionID uuid.UUID, opts ScreenshotOpts) (*ScreenshotResult, error)

Screenshot captures a screenshot

func (*PlaywrightManager) Wait

func (m *PlaywrightManager) Wait(ctx context.Context, sessionID uuid.UUID, opts WaitOpts) error

Wait waits for an element or timeout

type ScreenshotOpts

type ScreenshotOpts struct {
	FullPage bool   // Capture entire page (not just viewport)
	Selector string // Screenshot specific element only
	Format   string // "png" or "jpeg"
}

ScreenshotOpts configures screenshot capture

type ScreenshotResult

type ScreenshotResult struct {
	ArtifactID uuid.UUID
	Path       string
	SizeBytes  int64
	Format     string
}

ScreenshotResult contains screenshot artifact info

type WaitOpts

type WaitOpts struct {
	Selector string // Wait for element to appear
	Timeout  int    // milliseconds
}

WaitOpts configures wait conditions

Jump to

Keyboard shortcuts

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