Documentation
¶
Index ¶
- Variables
- func Annotate(imgData []byte, elementMap ElementMapInterface, cfg AnnotationConfig) ([]byte, error)
- func AnnotateBrowserUseStyle(imgData []byte, elementMap ElementMapInterface) ([]byte, error)
- func AnnotateForLLM(imgData []byte, elementMap ElementMapInterface) ([]byte, error)
- func Capture(ctx context.Context, page *rod.Page, opts Options) ([]byte, error)
- func CaptureAfterAction(ctx context.Context, page *rod.Page, maxWidth int) ([]byte, error)
- func CaptureAfterActionWithAnnotations(ctx context.Context, page *rod.Page, elementMap ElementMapInterface, ...) ([]byte, error)
- func CaptureElement(ctx context.Context, page *rod.Page, selector string, opts Options) ([]byte, error)
- func CaptureFullPage(ctx context.Context, page *rod.Page, opts Options) ([]byte, error)
- func CaptureViewport(ctx context.Context, page *rod.Page, opts Options) ([]byte, error)
- func CaptureWithAnnotations(ctx context.Context, page *rod.Page, elementMap ElementMapInterface, ...) ([]byte, error)
- func ForLLM(ctx context.Context, page *rod.Page, maxWidth int) ([]byte, error)
- func ForLLMSafe(ctx context.Context, page *rod.Page, maxWidth int) ([]byte, error)
- func ForLLMSafeWithAnnotations(ctx context.Context, page *rod.Page, elementMap ElementMapInterface, ...) ([]byte, error)
- func ForLLMWithAnnotations(ctx context.Context, page *rod.Page, elementMap ElementMapInterface, ...) ([]byte, error)
- func HasContent(img image.Image) bool
- func IsPageReady(page *rod.Page) bool
- func WaitUntilReady(ctx context.Context, page *rod.Page, timeout time.Duration) error
- type AnnotatedOptions
- type AnnotationConfig
- type BoundingBoxInfo
- type ElementInfo
- type ElementMapInterface
- type Options
- type PageInfo
Constants ¶
This section is empty.
Variables ¶
var ErrBlankPage = errors.New("page is blank (about:blank)")
ErrBlankPage is returned when attempting to screenshot a blank page.
var ErrEmptyScreenshot = errors.New("screenshot appears to be empty or all white")
ErrEmptyScreenshot is returned when screenshot appears to be empty/white.
Functions ¶
func Annotate ¶
func Annotate(imgData []byte, elementMap ElementMapInterface, cfg AnnotationConfig) ([]byte, error)
Annotate draws bounding boxes and labels on a screenshot image. Following browser-use pattern: boxes around interactive elements with index labels.
func AnnotateBrowserUseStyle ¶
func AnnotateBrowserUseStyle(imgData []byte, elementMap ElementMapInterface) ([]byte, error)
AnnotateBrowserUseStyle annotates following browser-use pattern: Only show index labels for elements without text information.
func AnnotateForLLM ¶
func AnnotateForLLM(imgData []byte, elementMap ElementMapInterface) ([]byte, error)
AnnotateForLLM annotates a screenshot optimized for LLM vision consumption. Uses default annotation config with appropriate sizing.
func Capture ¶
Capture takes a screenshot of the page and returns compressed bytes. It implements proper page readiness checks following browser-use best practices.
func CaptureAfterAction ¶
CaptureAfterAction captures a screenshot after an action has been performed. It waits for the page to stabilize after the action before capturing.
func CaptureAfterActionWithAnnotations ¶
func CaptureAfterActionWithAnnotations(ctx context.Context, page *rod.Page, elementMap ElementMapInterface, maxWidth int) ([]byte, error)
CaptureAfterActionWithAnnotations captures an annotated screenshot after an action.
func CaptureElement ¶
func CaptureElement(ctx context.Context, page *rod.Page, selector string, opts Options) ([]byte, error)
CaptureElement takes a screenshot of a specific element.
func CaptureFullPage ¶
CaptureFullPage takes a screenshot of the entire page.
func CaptureViewport ¶
CaptureViewport takes a screenshot of the current viewport only.
func CaptureWithAnnotations ¶
func CaptureWithAnnotations(ctx context.Context, page *rod.Page, elementMap ElementMapInterface, opts AnnotatedOptions) ([]byte, error)
CaptureWithAnnotations captures a screenshot and draws element annotations. This follows browser-use pattern: bounding boxes around interactive elements with index labels.
func ForLLM ¶
ForLLM captures a screenshot optimized for LLM consumption. Uses JPEG format with reasonable compression for token efficiency. Includes page readiness checks and skips blank pages.
func ForLLMSafe ¶
ForLLMSafe captures a screenshot for LLM consumption with full validation. Returns nil data (not error) if page is blank or screenshot is empty. This is useful for agent loops where blank screenshots should be skipped.
func ForLLMSafeWithAnnotations ¶
func ForLLMSafeWithAnnotations(ctx context.Context, page *rod.Page, elementMap ElementMapInterface, maxWidth int) ([]byte, error)
ForLLMSafeWithAnnotations captures an annotated screenshot, returning nil for blank pages.
func ForLLMWithAnnotations ¶
func ForLLMWithAnnotations(ctx context.Context, page *rod.Page, elementMap ElementMapInterface, maxWidth int) ([]byte, error)
ForLLMWithAnnotations captures an annotated screenshot optimized for LLM vision. Includes bounding boxes around interactive elements with index labels.
func HasContent ¶
HasContent checks if the image has meaningful content (not mostly white).
func IsPageReady ¶
IsPageReady checks if the page is ready for screenshot capture.
Types ¶
type AnnotatedOptions ¶
type AnnotatedOptions struct {
Options
// Annotate enables drawing bounding boxes and labels on the screenshot.
Annotate bool
// AnnotationConfig customizes annotation appearance.
AnnotationConfig *AnnotationConfig
}
AnnotatedOptions extends Options with annotation settings.
func DefaultAnnotatedOptions ¶
func DefaultAnnotatedOptions() AnnotatedOptions
DefaultAnnotatedOptions returns options with annotations enabled.
type AnnotationConfig ¶
type AnnotationConfig struct {
// BorderWidth is the width of bounding box borders in pixels.
BorderWidth int
// FontSize is the approximate height of index labels in pixels.
FontSize int
// ShowLabels determines whether to show index labels on elements.
ShowLabels bool
// ShowLabelsOnlyForUnlabeled shows labels only for elements without text.
ShowLabelsOnlyForUnlabeled bool
// Colors for different element types.
LinkColor color.RGBA
ButtonColor color.RGBA
InputColor color.RGBA
DefaultColor color.RGBA
LabelBgColor color.RGBA
LabelTextColor color.RGBA
}
AnnotationConfig configures how annotations are drawn.
func DefaultAnnotationConfig ¶
func DefaultAnnotationConfig() AnnotationConfig
DefaultAnnotationConfig returns sensible defaults for annotations.
type BoundingBoxInfo ¶
type BoundingBoxInfo interface {
GetX() float64
GetY() float64
GetWidth() float64
GetHeight() float64
GetIsEmpty() bool
}
BoundingBoxInfo provides bounding box data for annotation.
type ElementInfo ¶
type ElementInfo interface {
GetIndex() int
GetTagName() string
GetRole() string
GetText() string
GetBoundingBox() BoundingBoxInfo
GetIsVisible() bool
}
ElementInfo provides element data needed for annotation.
type ElementMapInterface ¶
type ElementMapInterface interface {
Len() int
GetElements() []ElementInfo
}
ElementMapInterface defines the interface for element maps used in annotations. This allows the screenshot package to work with element maps without circular imports.
type Options ¶
type Options struct {
// MaxWidth is the maximum width for the screenshot.
// Images wider than this will be resized.
MaxWidth int
// Quality is the JPEG quality (1-100).
// Only used when Format is JPEG.
Quality int
// Format is the output format (png or jpeg).
Format string
// FullPage captures the entire page, not just the viewport.
FullPage bool
// WaitForLoad waits for page load event before capturing.
WaitForLoad bool
// WaitForIdle waits for network idle before capturing.
WaitForIdle bool
// StabilityTimeout is how long to wait for page stability.
// Default is 500ms if not set.
StabilityTimeout time.Duration
// SkipBlankPages returns ErrBlankPage instead of capturing blank pages.
SkipBlankPages bool
// ValidateContent checks if screenshot has actual content (not all white).
ValidateContent bool
}
Options configures screenshot capture.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns sensible defaults for LLM consumption.
func LLMOptions ¶
func LLMOptions() Options
LLMOptions returns options optimized for LLM vision consumption. Includes page readiness checks and content validation.