Documentation
¶
Index ¶
- Constants
- func ClampTimeout(ms int) int
- func EscapePythonString(s string) string
- func ValidateImageFormat(v string) (string, error)
- func ValidatePaperFormat(v string) (string, error)
- func ValidateWaitUntil(v string) (string, error)
- func ValidateWorkspacePath(p, fallback string) (string, error)
- type BrowserSession
- type ExtractOpts
- type Manager
- type NavigateOpts
- type NetworkPolicy
- type PDFOpts
- type PDFResult
- type PlaywrightManager
- func (m *PlaywrightManager) Click(ctx context.Context, sessionID uuid.UUID, selector string) error
- func (m *PlaywrightManager) Close(ctx context.Context, sessionID uuid.UUID) error
- func (m *PlaywrightManager) Evaluate(ctx context.Context, sessionID uuid.UUID, jsScript string) (interface{}, error)
- func (m *PlaywrightManager) Extract(ctx context.Context, sessionID uuid.UUID, opts ExtractOpts) (string, error)
- func (m *PlaywrightManager) Fill(ctx context.Context, sessionID uuid.UUID, selector, value string) error
- func (m *PlaywrightManager) Navigate(ctx context.Context, sessionID uuid.UUID, targetURL string, opts NavigateOpts) error
- func (m *PlaywrightManager) PDF(ctx context.Context, sessionID uuid.UUID, opts PDFOpts) (*PDFResult, error)
- func (m *PlaywrightManager) Screenshot(ctx context.Context, sessionID uuid.UUID, opts ScreenshotOpts) (*ScreenshotResult, error)
- func (m *PlaywrightManager) Wait(ctx context.Context, sessionID uuid.UUID, opts WaitOpts) error
- type ScreenshotOpts
- type ScreenshotResult
- type WaitOpts
Constants ¶
const DefaultBrowserTimeoutMs = 30000
DefaultBrowserTimeoutMs is used when the caller supplies no timeout.
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.
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
ClampTimeout keeps a caller-supplied timeout inside a usable range.
func EscapePythonString ¶ added in v0.3.2
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
ValidateImageFormat resolves a screenshot image format.
func ValidatePaperFormat ¶ added in v0.3.2
ValidatePaperFormat resolves a PDF paper size.
func ValidateWaitUntil ¶ added in v0.3.2
ValidateWaitUntil resolves a Playwright load-state option.
func ValidateWorkspacePath ¶ added in v0.3.2
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(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
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 PlaywrightManager ¶
type PlaywrightManager struct {
// contains filtered or unexported fields
}
PlaywrightManager implements Manager using Playwright via Docker exec
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
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 ¶
ScreenshotResult contains screenshot artifact info