Documentation
¶
Overview ¶
Package w3pilot provides a Go client for the W3Pilot browser automation platform.
W3Pilot is a browser automation platform built for AI agents that uses the WebDriver BiDi protocol for bidirectional communication with the browser.
Quick Start ¶
Launch a browser and navigate to a page:
ctx := context.Background()
pilot, err := w3pilot.Launch(ctx)
if err != nil {
log.Fatal(err)
}
defer pilot.Quit(ctx)
if err := pilot.Go(ctx, "https://example.com"); err != nil {
log.Fatal(err)
}
Finding and Interacting with Elements ¶
Find elements using CSS selectors and interact with them:
link, err := pilot.Find(ctx, "a.my-link", nil)
if err != nil {
log.Fatal(err)
}
if err := link.Click(ctx, nil); err != nil {
log.Fatal(err)
}
Type text into input fields:
input, err := pilot.Find(ctx, "input[name='search']", nil)
if err != nil {
log.Fatal(err)
}
if err := input.Type(ctx, "search query", nil); err != nil {
log.Fatal(err)
}
Screenshots ¶
Capture screenshots as PNG data:
data, err := pilot.Screenshot(ctx)
if err != nil {
log.Fatal(err)
}
os.WriteFile("screenshot.png", data, 0644)
Headless Mode ¶
Launch in headless mode for CI/server environments:
pilot, err := w3pilot.LaunchHeadless(ctx)
Or with explicit options:
pilot, err := w3pilot.Browser.Launch(ctx, &w3pilot.LaunchOptions{
Headless: true,
Port: 9515,
})
Requirements ¶
This client requires Chrome or Chromium. If Chrome is not found on your system, it will automatically download Chrome for Testing from Google's official API.
You can also specify a custom Chrome path via the CHROME_PATH environment variable or the ExecutablePath option in LaunchOptions.
Package w3pilot provides a Go client for browser automation using the WebDriver BiDi protocol. It launches Chrome with BiDi support and communicates over WebSocket.
Example ¶
package main
import (
"context"
"fmt"
"log"
"github.com/plexusone/w3pilot"
)
func main() {
ctx := context.Background()
// Launch browser
pilot, err := w3pilot.Launch(ctx)
if err != nil {
log.Fatal(err)
}
defer func() { _ = pilot.Quit(ctx) }()
// Navigate to a page
if err := pilot.Go(ctx, "https://example.com"); err != nil {
log.Fatal(err)
}
// Find and click a link
link, err := pilot.Find(ctx, "a", nil)
if err != nil {
log.Fatal(err)
}
if err := link.Click(ctx, nil); err != nil {
log.Fatal(err)
}
// Get page title
title, err := pilot.Title(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println("Page title:", title)
}
Output:
Example (FormInteraction) ¶
package main
import (
"context"
"log"
"github.com/plexusone/w3pilot"
)
func main() {
ctx := context.Background()
pilot, err := w3pilot.Browser.Launch(ctx, &w3pilot.LaunchOptions{
Headless: true,
})
if err != nil {
log.Fatal(err)
}
defer func() { _ = pilot.Quit(ctx) }()
// Navigate to a form page
if err := pilot.Go(ctx, "https://example.com/login"); err != nil {
log.Fatal(err)
}
// Fill in username
username, err := pilot.Find(ctx, "input[name='username']", nil)
if err != nil {
log.Fatal(err)
}
if err := username.Type(ctx, "myuser", nil); err != nil {
log.Fatal(err)
}
// Fill in password
password, err := pilot.Find(ctx, "input[name='password']", nil)
if err != nil {
log.Fatal(err)
}
if err := password.Type(ctx, "mypassword", nil); err != nil {
log.Fatal(err)
}
// Click submit
submit, err := pilot.Find(ctx, "button[type='submit']", nil)
if err != nil {
log.Fatal(err)
}
if err := submit.Click(ctx, nil); err != nil {
log.Fatal(err)
}
}
Output:
Example (Headless) ¶
package main
import (
"context"
"log"
"os"
"github.com/plexusone/w3pilot"
)
func main() {
ctx := context.Background()
// Launch headless browser
pilot, err := w3pilot.LaunchHeadless(ctx)
if err != nil {
log.Fatal(err)
}
defer func() { _ = pilot.Quit(ctx) }()
// Navigate
if err := pilot.Go(ctx, "https://example.com"); err != nil {
log.Fatal(err)
}
// Take screenshot
data, err := pilot.Screenshot(ctx)
if err != nil {
log.Fatal(err)
}
// Save to file
if err := os.WriteFile("screenshot.png", data, 0600); err != nil {
log.Fatal(err)
}
}
Output:
Index ¶
- Constants
- Variables
- func ClickerVersion(clickerPath string) (string, error)
- func ContextWithLogger(ctx context.Context, logger *slog.Logger) context.Context
- func Debug() bool
- func FindClickerBinary() (string, error)
- func IsUnsupportedCommand(err error) bool
- func LoggerFromContext(ctx context.Context) *slog.Logger
- func NewDebugLogger() *slog.Logger
- type A11yTreeOptions
- type ActionOptions
- type AssertOptions
- type AssertionError
- type BiDiClient
- type BiDiCommand
- type BiDiError
- type BiDiEvent
- type BiDiResponse
- type BiDiTransport
- type BoundingBox
- type BrowserContext
- func (c *BrowserContext) AddInitScript(ctx context.Context, script string) error
- func (c *BrowserContext) ClearCookies(ctx context.Context) error
- func (c *BrowserContext) ClearPermissions(ctx context.Context) error
- func (c *BrowserContext) Close(ctx context.Context) error
- func (c *BrowserContext) Cookies(ctx context.Context, urls ...string) ([]Cookie, error)
- func (c *BrowserContext) DeleteCookie(ctx context.Context, name string, domain string, path string) error
- func (c *BrowserContext) GrantPermissions(ctx context.Context, permissions []string, origin string) error
- func (c *BrowserContext) NewPage(ctx context.Context) (*Pilot, error)
- func (c *BrowserContext) SetCookies(ctx context.Context, cookies []SetCookieParam) error
- func (c *BrowserContext) StorageState(ctx context.Context) (*StorageState, error)
- type BrowserCrashedError
- type ClickOptions
- type ClickerProcess
- type Clock
- func (c *Clock) FastForward(ctx context.Context, ticks int64) error
- func (c *Clock) Install(ctx context.Context, opts *ClockInstallOptions) error
- func (c *Clock) PauseAt(ctx context.Context, t interface{}) error
- func (c *Clock) Resume(ctx context.Context) error
- func (c *Clock) RunFor(ctx context.Context, ticks int64) error
- func (c *Clock) SetFixedTime(ctx context.Context, t interface{}) error
- func (c *Clock) SetSystemTime(ctx context.Context, t interface{}) error
- func (c *Clock) SetTimezone(ctx context.Context, tz string) error
- type ClockInstallOptions
- type ConnectionError
- type ConsoleEntry
- type ConsoleHandler
- type ConsoleMessage
- type ContinueOptions
- type Cookie
- type CoverageReport
- type CoverageSummary
- type Dialog
- type DialogHandler
- type DialogInfo
- type Download
- type DownloadHandler
- type Element
- func (e *Element) BoundingBox(ctx context.Context) (BoundingBox, error)
- func (e *Element) Center() (x, y float64)
- func (e *Element) Check(ctx context.Context, opts *ActionOptions) error
- func (e *Element) Clear(ctx context.Context, opts *ActionOptions) error
- func (e *Element) Click(ctx context.Context, opts *ActionOptions) error
- func (e *Element) DblClick(ctx context.Context, opts *ActionOptions) error
- func (e *Element) DispatchEvent(ctx context.Context, eventType string, eventInit map[string]interface{}) error
- func (e *Element) DragTo(ctx context.Context, target *Element, opts *ActionOptions) error
- func (e *Element) Eval(ctx context.Context, fn string, args ...interface{}) (interface{}, error)
- func (e *Element) Fill(ctx context.Context, value string, opts *ActionOptions) error
- func (e *Element) Find(ctx context.Context, selector string, opts *FindOptions) (*Element, error)
- func (e *Element) FindAll(ctx context.Context, selector string, opts *FindOptions) ([]*Element, error)
- func (e *Element) Focus(ctx context.Context, opts *ActionOptions) error
- func (e *Element) GetAttribute(ctx context.Context, name string) (string, error)
- func (e *Element) HTML(ctx context.Context) (string, error)
- func (e *Element) Highlight(ctx context.Context, opts *HighlightOptions) error
- func (e *Element) Hover(ctx context.Context, opts *ActionOptions) error
- func (e *Element) Info() ElementInfo
- func (e *Element) InnerHTML(ctx context.Context) (string, error)
- func (e *Element) InnerText(ctx context.Context) (string, error)
- func (e *Element) IsChecked(ctx context.Context) (bool, error)
- func (e *Element) IsEditable(ctx context.Context) (bool, error)
- func (e *Element) IsEnabled(ctx context.Context) (bool, error)
- func (e *Element) IsHidden(ctx context.Context) (bool, error)
- func (e *Element) IsVisible(ctx context.Context) (bool, error)
- func (e *Element) Label(ctx context.Context) (string, error)
- func (e *Element) Press(ctx context.Context, key string, opts *ActionOptions) error
- func (e *Element) Role(ctx context.Context) (string, error)
- func (e *Element) Screenshot(ctx context.Context) ([]byte, error)
- func (e *Element) ScrollIntoView(ctx context.Context, opts *ActionOptions) error
- func (e *Element) SelectOption(ctx context.Context, values SelectOptionValues, opts *ActionOptions) error
- func (e *Element) Selector() string
- func (e *Element) SetFiles(ctx context.Context, paths []string, opts *ActionOptions) error
- func (e *Element) Tap(ctx context.Context, opts *ActionOptions) error
- func (e *Element) Text(ctx context.Context) (string, error)
- func (e *Element) Type(ctx context.Context, text string, opts *ActionOptions) error
- func (e *Element) Uncheck(ctx context.Context, opts *ActionOptions) error
- func (e *Element) Value(ctx context.Context) (string, error)
- func (e *Element) VerifyChecked(ctx context.Context) error
- func (e *Element) VerifyDisabled(ctx context.Context) error
- func (e *Element) VerifyEnabled(ctx context.Context) error
- func (e *Element) VerifyHidden(ctx context.Context) error
- func (e *Element) VerifyText(ctx context.Context, expected string, opts *VerifyTextOptions) error
- func (e *Element) VerifyUnchecked(ctx context.Context) error
- func (e *Element) VerifyValue(ctx context.Context, expected string) error
- func (e *Element) VerifyVisible(ctx context.Context) error
- func (e *Element) WaitFor(ctx context.Context, timeout time.Duration) error
- func (e *Element) WaitUntil(ctx context.Context, state string, timeout time.Duration) error
- type ElementInfo
- type ElementNotFoundError
- type EmulateMediaOptions
- type EventHandler
- type ExceptionDetails
- type ExtensionInfo
- type ExtractTableOptions
- type FindOptions
- type FrameInfo
- type FulfillOptions
- type GenerateLocatorOptions
- type Geolocation
- type HighlightOptions
- type InspectButton
- type InspectHeading
- type InspectImage
- type InspectInput
- type InspectLink
- type InspectOptions
- type InspectResult
- type InspectSelect
- type InspectSummary
- type Keyboard
- func (k *Keyboard) Down(ctx context.Context, key string) error
- func (k *Keyboard) InsertText(ctx context.Context, text string) error
- func (k *Keyboard) Press(ctx context.Context, key string) error
- func (k *Keyboard) Type(ctx context.Context, text string) error
- func (k *Keyboard) Up(ctx context.Context, key string) error
- type LaunchOptions
- type LighthouseCategory
- type LighthouseDevice
- type LighthouseOptions
- type LighthouseResult
- type LighthouseScore
- type LocatorInfo
- type LogEntry
- type LoginOptions
- type LoginResult
- type MemoryStats
- type MockRouteOptions
- type Mouse
- func (m *Mouse) Click(ctx context.Context, x, y float64, opts *ClickOptions) error
- func (m *Mouse) DblClick(ctx context.Context, x, y float64, opts *ClickOptions) error
- func (m *Mouse) Down(ctx context.Context, button MouseButton) error
- func (m *Mouse) Move(ctx context.Context, x, y float64) error
- func (m *Mouse) Up(ctx context.Context, button MouseButton) error
- func (m *Mouse) Wheel(ctx context.Context, deltaX, deltaY float64) error
- type MouseButton
- type NetworkRequest
- type NetworkRequestsOptions
- type PDFMargin
- type PDFOptions
- type PageContext
- type PageError
- type PageErrorHandler
- type PageHandler
- type PerformanceMetrics
- type Pilot
- func (p *Pilot) A11yTree(ctx context.Context, opts *A11yTreeOptions) (interface{}, error)
- func (p *Pilot) AddInitScript(ctx context.Context, script string) error
- func (p *Pilot) AddScript(ctx context.Context, source string) error
- func (p *Pilot) AddStyle(ctx context.Context, source string) error
- func (p *Pilot) AssertElement(ctx context.Context, selector string, opts *AssertOptions) error
- func (p *Pilot) AssertText(ctx context.Context, text string, opts *AssertOptions) error
- func (p *Pilot) AssertURL(ctx context.Context, pattern string, _ *AssertOptions) error
- func (p *Pilot) Back(ctx context.Context) error
- func (p *Pilot) BringToFront(ctx context.Context) error
- func (p *Pilot) BrowserLogs() []LogEntry
- func (p *Pilot) BrowserVersion(ctx context.Context) (string, error)
- func (p *Pilot) BrowsingContext() string
- func (p *Pilot) CDP() *cdp.Client
- func (p *Pilot) CDPPort() int
- func (p *Pilot) ClearCPUEmulation(ctx context.Context) error
- func (p *Pilot) ClearConsoleDebugger()
- func (p *Pilot) ClearConsoleMessages(ctx context.Context) error
- func (p *Pilot) ClearErrors(ctx context.Context) error
- func (p *Pilot) ClearNetworkEmulation(ctx context.Context) error
- func (p *Pilot) ClearNetworkRequests(ctx context.Context) error
- func (p *Pilot) ClearStorage(ctx context.Context) error
- func (p *Pilot) Clicker() *ClickerProcess
- func (p *Pilot) Clock(ctx context.Context) (*Clock, error)
- func (p *Pilot) Close(ctx context.Context) error
- func (p *Pilot) CollectConsole(ctx context.Context) error
- func (p *Pilot) CollectErrors(ctx context.Context) error
- func (p *Pilot) ConsoleEntries() []ConsoleEntry
- func (p *Pilot) ConsoleExceptions() []ExceptionDetails
- func (p *Pilot) ConsoleMessages(ctx context.Context, level string) ([]ConsoleMessage, error)
- func (p *Pilot) Content(ctx context.Context) (string, error)
- func (p *Pilot) Context() *BrowserContext
- func (p *Pilot) DisableConsoleDebugger(ctx context.Context) error
- func (p *Pilot) EmulateCPU(ctx context.Context, rate int) error
- func (p *Pilot) EmulateMedia(ctx context.Context, opts EmulateMediaOptions) error
- func (p *Pilot) EmulateNetwork(ctx context.Context, conditions cdp.NetworkConditions) error
- func (p *Pilot) EnableConsoleDebugger(ctx context.Context) error
- func (p *Pilot) Errors(ctx context.Context) ([]PageError, error)
- func (p *Pilot) Evaluate(ctx context.Context, script string) (interface{}, error)
- func (p *Pilot) Expose(ctx context.Context, name string) error
- func (p *Pilot) ExtractTable(ctx context.Context, selector string, opts *ExtractTableOptions) (*TableResult, error)
- func (p *Pilot) Find(ctx context.Context, selector string, opts *FindOptions) (*Element, error)
- func (p *Pilot) FindAll(ctx context.Context, selector string, opts *FindOptions) ([]*Element, error)
- func (p *Pilot) Forward(ctx context.Context) error
- func (p *Pilot) Frame(ctx context.Context, nameOrURL string) (*Pilot, error)
- func (p *Pilot) Frames(ctx context.Context) ([]FrameInfo, error)
- func (p *Pilot) GenerateLocator(ctx context.Context, selector string, opts *GenerateLocatorOptions) (*LocatorInfo, error)
- func (p *Pilot) GetDialog(ctx context.Context) (DialogInfo, error)
- func (p *Pilot) GetMemoryStats(ctx context.Context) (*MemoryStats, error)
- func (p *Pilot) GetNetworkResponseBody(ctx context.Context, requestID string, saveTo string) (*cdp.ResponseBody, error)
- func (p *Pilot) GetPerformanceMetrics(ctx context.Context) (*PerformanceMetrics, error)
- func (p *Pilot) GetViewport(ctx context.Context) (Viewport, error)
- func (p *Pilot) GetWindow(ctx context.Context) (WindowState, error)
- func (p *Pilot) Go(ctx context.Context, url string) error
- func (p *Pilot) HandleDialog(ctx context.Context, accept bool, promptText string) error
- func (p *Pilot) HasCDP() bool
- func (p *Pilot) Inspect(ctx context.Context, opts *InspectOptions) (*InspectResult, error)
- func (p *Pilot) InstallExtension(ctx context.Context, path string) (string, error)
- func (p *Pilot) IsClosed() bool
- func (p *Pilot) IsConsoleDebuggerEnabled() bool
- func (p *Pilot) IsCoverageRunning() bool
- func (p *Pilot) IsScreencasting() bool
- func (p *Pilot) Keyboard(ctx context.Context) (*Keyboard, error)
- func (p *Pilot) LighthouseAudit(ctx context.Context, opts *LighthouseOptions) (*LighthouseResult, error)
- func (p *Pilot) ListExtensions(ctx context.Context) ([]ExtensionInfo, error)
- func (p *Pilot) ListRoutes(ctx context.Context) ([]RouteInfo, error)
- func (p *Pilot) Login(ctx context.Context, opts *LoginOptions) (*LoginResult, error)
- func (p *Pilot) MainFrame() *Pilot
- func (p *Pilot) MockRoute(ctx context.Context, pattern string, opts MockRouteOptions) error
- func (p *Pilot) Mouse(ctx context.Context) (*Mouse, error)
- func (p *Pilot) MustFind(ctx context.Context, selector string) *Element
- func (p *Pilot) NetworkRequests(ctx context.Context, opts *NetworkRequestsOptions) ([]NetworkRequest, error)
- func (p *Pilot) NewContext(ctx context.Context) (*BrowserContext, error)
- func (p *Pilot) NewPage(ctx context.Context) (*Pilot, error)
- func (p *Pilot) ObserveWebVitals(ctx context.Context) (<-chan *PerformanceMetrics, func(), error)
- func (p *Pilot) OnConsole(ctx context.Context, handler ConsoleHandler) error
- func (p *Pilot) OnDialog(ctx context.Context, handler DialogHandler) error
- func (p *Pilot) OnDownload(ctx context.Context, handler DownloadHandler) error
- func (p *Pilot) OnError(ctx context.Context, handler PageErrorHandler) error
- func (p *Pilot) OnPage(ctx context.Context, handler PageHandler) error
- func (p *Pilot) OnPopup(ctx context.Context, handler PopupHandler) error
- func (p *Pilot) OnRequest(ctx context.Context, handler RequestHandler) error
- func (p *Pilot) OnResponse(ctx context.Context, handler ResponseHandler) error
- func (p *Pilot) OnWebSocket(ctx context.Context, handler WebSocketHandler) error
- func (p *Pilot) PDF(ctx context.Context, opts *PDFOptions) ([]byte, error)
- func (p *Pilot) Pages(ctx context.Context) ([]*Pilot, error)
- func (p *Pilot) Quit(ctx context.Context) error
- func (p *Pilot) Reload(ctx context.Context) error
- func (p *Pilot) RemoveAllListeners()
- func (p *Pilot) Route(ctx context.Context, pattern string, handler RouteHandler) error
- func (p *Pilot) Screenshot(ctx context.Context) ([]byte, error)
- func (p *Pilot) Scroll(ctx context.Context, direction string, amount int, opts *ScrollOptions) error
- func (p *Pilot) SetContent(ctx context.Context, html string) error
- func (p *Pilot) SetExtraHTTPHeaders(ctx context.Context, headers map[string]string) error
- func (p *Pilot) SetGeolocation(ctx context.Context, coords Geolocation) error
- func (p *Pilot) SetOffline(ctx context.Context, offline bool) error
- func (p *Pilot) SetStorageState(ctx context.Context, state *StorageState) error
- func (p *Pilot) SetViewport(ctx context.Context, viewport Viewport) error
- func (p *Pilot) SetWindow(ctx context.Context, opts SetWindowOptions) error
- func (p *Pilot) StartCSSCoverage(ctx context.Context) error
- func (p *Pilot) StartCoverage(ctx context.Context) error
- func (p *Pilot) StartJSCoverage(ctx context.Context, callCount, detailed bool) error
- func (p *Pilot) StartScreencast(ctx context.Context, opts *cdp.ScreencastOptions, ...) error
- func (p *Pilot) StartVideo(ctx context.Context, opts *VideoOptions) (*Video, error)
- func (p *Pilot) StopCoverage(ctx context.Context) (*CoverageReport, error)
- func (p *Pilot) StopScreencast(ctx context.Context) error
- func (p *Pilot) StopVideo(ctx context.Context) (string, error)
- func (p *Pilot) StorageState(ctx context.Context) (*StorageState, error)
- func (p *Pilot) TakeHeapSnapshot(ctx context.Context, path string) (*cdp.HeapSnapshot, error)
- func (p *Pilot) Title(ctx context.Context) (string, error)
- func (p *Pilot) Touch(ctx context.Context) (*Touch, error)
- func (p *Pilot) URL(ctx context.Context) (string, error)
- func (p *Pilot) UninstallExtension(ctx context.Context, id string) error
- func (p *Pilot) Unroute(ctx context.Context, pattern string) error
- func (p *Pilot) ValidateSelector(ctx context.Context, selector string) (*SelectorValidation, error)
- func (p *Pilot) ValidateSelectors(ctx context.Context, selectors []string) ([]SelectorValidation, error)
- func (p *Pilot) WaitForFunction(ctx context.Context, fn string, timeout time.Duration) error
- func (p *Pilot) WaitForLoad(ctx context.Context, state string, timeout time.Duration) error
- func (p *Pilot) WaitForNavigation(ctx context.Context, timeout time.Duration) error
- func (p *Pilot) WaitForURL(ctx context.Context, pattern string, timeout time.Duration) error
- type PipeOptions
- type PopupHandler
- type Request
- type RequestHandler
- type Response
- type ResponseHandler
- type Route
- type RouteHandler
- type RouteInfo
- type ScreencastFrameHandler
- type ScrollOptions
- type SelectOptionValues
- type SelectorValidation
- type SetCookieParam
- type SetWindowOptions
- type StorageState
- type StorageStateOrigin
- type TableResult
- type TimeoutError
- type Touch
- type VerificationError
- type VerifyTextOptions
- type Video
- type VideoOptions
- type VideoSize
- type Viewport
- type WebSocketCloseHandler
- type WebSocketHandler
- type WebSocketInfo
- type WebSocketMessage
- type WebSocketMessageHandler
- type WindowState
Examples ¶
Constants ¶
const ( // VibiumBinaryEnvVar is the preferred environment variable for the vibium binary path. VibiumBinaryEnvVar = "VIBIUM_BIN_PATH" // ClickerBinaryEnvVar is the legacy environment variable (still supported). ClickerBinaryEnvVar = "CLICKER_BIN_PATH" )
Environment variables for specifying binary paths.
const DefaultTimeout = 30 * time.Second
DefaultTimeout is the default timeout for finding elements and waiting for actionability.
Variables ¶
var ( // ErrConnectionFailed is returned when WebSocket connection fails. ErrConnectionFailed = errors.New("failed to connect to browser") // ErrElementNotFound is returned when an element cannot be found. ErrElementNotFound = errors.New("element not found") // ErrBrowserCrashed is returned when the browser process exits unexpectedly. ErrBrowserCrashed = errors.New("browser crashed") // ErrBrowserNotFound is returned when Chrome cannot be found. ErrBrowserNotFound = errors.New("Chrome not found") // ErrClickerNotFound is deprecated: use ErrBrowserNotFound instead. // Deprecated: This error is no longer used. Use ErrBrowserNotFound. ErrClickerNotFound = ErrBrowserNotFound // ErrTimeout is returned when an operation times out. ErrTimeout = errors.New("operation timed out") // ErrConnectionClosed is returned when the WebSocket connection is closed. ErrConnectionClosed = errors.New("connection closed") )
var Browser = &browserLauncher{}
Browser provides browser launching capabilities.
Functions ¶
func ClickerVersion ¶
ClickerVersion returns the version of the clicker/vibium binary.
func ContextWithLogger ¶
ContextWithLogger returns a new context with the logger attached.
func Debug ¶
func Debug() bool
Debug returns true if debug logging is enabled via W3PILOT_DEBUG environment variable.
func FindClickerBinary ¶
FindClickerBinary locates the clicker binary.
Search order:
- VIBIUM_BIN_PATH environment variable
- CLICKER_BIN_PATH environment variable (legacy)
- PATH lookup for "clicker" or "vibium"
- Go bin directory ($GOPATH/bin or ~/go/bin)
- Common installation paths
func IsUnsupportedCommand ¶ added in v0.7.0
IsUnsupportedCommand returns true if the error indicates the command is not supported by the backend (e.g., clicker doesn't implement a vibium: command). This is used internally to trigger fallback to CDP.
func LoggerFromContext ¶
LoggerFromContext returns the logger from the context, or nil if not present.
func NewDebugLogger ¶
NewDebugLogger creates a new debug logger that writes to stderr. Returns nil if debug logging is disabled.
Types ¶
type A11yTreeOptions ¶
type A11yTreeOptions struct {
// InterestingOnly filters the tree to only include interesting nodes.
// Interesting nodes are those with semantic meaning (roles, names, states).
// Default is true.
InterestingOnly *bool
// Root specifies a CSS selector for the root element.
// If specified, only the subtree under this element is returned.
Root string
}
A11yTreeOptions configures accessibility tree retrieval.
type ActionOptions ¶
type ActionOptions struct {
// Timeout specifies how long to wait for actionability.
// Default is 30 seconds.
Timeout time.Duration
}
ActionOptions configures action behavior (click, type).
type AssertOptions ¶ added in v0.8.0
type AssertOptions struct {
// Timeout for finding elements or waiting for conditions.
Timeout time.Duration
// Selector to scope the search (for AssertText).
Selector string
}
AssertOptions configures assertion behavior.
type AssertionError ¶ added in v0.8.0
type AssertionError struct {
Type string `json:"type"`
Message string `json:"message"`
Expected string `json:"expected,omitempty"`
Actual string `json:"actual,omitempty"`
Selector string `json:"selector,omitempty"`
}
AssertionError is returned when an assertion fails.
func (*AssertionError) Error ¶ added in v0.8.0
func (e *AssertionError) Error() string
type BiDiClient ¶
type BiDiClient struct {
// contains filtered or unexported fields
}
BiDiClient wraps a BiDiTransport with convenience methods. This provides a stable interface for the rest of the codebase.
func NewBiDiClient ¶
func NewBiDiClient(transport BiDiTransport) *BiDiClient
NewBiDiClient creates a new BiDi client wrapping the given transport.
func (*BiDiClient) OnEvent ¶
func (c *BiDiClient) OnEvent(method string, handler EventHandler)
OnEvent registers a handler for events matching the given method pattern. The method can be an exact match (e.g., "log.entryAdded") or a prefix (e.g., "log." to match all log events).
func (*BiDiClient) RemoveEventHandlers ¶
func (c *BiDiClient) RemoveEventHandlers(method string)
RemoveEventHandlers removes all handlers for the given method.
func (*BiDiClient) Send ¶
func (c *BiDiClient) Send(ctx context.Context, method string, params interface{}) (json.RawMessage, error)
Send sends a command and waits for the response.
type BiDiCommand ¶
type BiDiCommand struct {
ID int64 `json:"id"`
Method string `json:"method"`
Params interface{} `json:"params"`
}
BiDiCommand represents a WebDriver BiDi command.
type BiDiEvent ¶
type BiDiEvent struct {
Method string `json:"method"`
Params json.RawMessage `json:"params"`
}
BiDiEvent represents a WebDriver BiDi event.
type BiDiResponse ¶
type BiDiResponse struct {
ID int64 `json:"id"`
Type string `json:"type"`
Method string `json:"method,omitempty"` // For events
Result json.RawMessage `json:"result,omitempty"`
Params json.RawMessage `json:"params,omitempty"` // For events
Error string `json:"error,omitempty"`
Message string `json:"message,omitempty"`
}
BiDiResponse represents a WebDriver BiDi response.
type BiDiTransport ¶
type BiDiTransport interface {
// Send sends a command and waits for the response.
Send(ctx context.Context, method string, params interface{}) (json.RawMessage, error)
// OnEvent registers a handler for events matching the given method pattern.
OnEvent(method string, handler EventHandler)
// RemoveEventHandlers removes all handlers for the given method.
RemoveEventHandlers(method string)
// Close closes the transport connection.
Close() error
}
BiDiTransport is the interface for BiDi communication. wsTransport implements this interface using WebSocket.
type BoundingBox ¶
type BoundingBox struct {
X float64 `json:"x"`
Y float64 `json:"y"`
Width float64 `json:"width"`
Height float64 `json:"height"`
}
BoundingBox represents the position and size of an element.
type BrowserContext ¶
type BrowserContext struct {
// contains filtered or unexported fields
}
BrowserContext represents an isolated browser context (like an incognito window). Each context has its own cookies, localStorage, and session storage.
func (*BrowserContext) AddInitScript ¶
func (c *BrowserContext) AddInitScript(ctx context.Context, script string) error
AddInitScript adds a script that will be evaluated in every page created in this context.
func (*BrowserContext) ClearCookies ¶
func (c *BrowserContext) ClearCookies(ctx context.Context) error
ClearCookies clears all cookies.
func (*BrowserContext) ClearPermissions ¶
func (c *BrowserContext) ClearPermissions(ctx context.Context) error
ClearPermissions clears all granted permissions.
func (*BrowserContext) Close ¶
func (c *BrowserContext) Close(ctx context.Context) error
Close closes the browser context and all pages within it.
func (*BrowserContext) Cookies ¶
Cookies returns cookies matching the specified URLs. If no URLs are specified, returns all cookies for the context.
func (*BrowserContext) DeleteCookie ¶
func (c *BrowserContext) DeleteCookie(ctx context.Context, name string, domain string, path string) error
DeleteCookie deletes a specific cookie by name. Optional domain and path can be specified to target a specific cookie.
func (*BrowserContext) GrantPermissions ¶
func (c *BrowserContext) GrantPermissions(ctx context.Context, permissions []string, origin string) error
GrantPermissions grants the specified permissions.
func (*BrowserContext) NewPage ¶
func (c *BrowserContext) NewPage(ctx context.Context) (*Pilot, error)
NewPage creates a new page in this browser context.
func (*BrowserContext) SetCookies ¶
func (c *BrowserContext) SetCookies(ctx context.Context, cookies []SetCookieParam) error
SetCookies sets cookies.
func (*BrowserContext) StorageState ¶
func (c *BrowserContext) StorageState(ctx context.Context) (*StorageState, error)
StorageState returns the storage state including cookies and localStorage. If the native vibium:context.storageState command is unavailable (e.g., when connected to a browser not launched through w3pilot), falls back to collecting cookies only via standard BiDi commands. localStorage will need to be collected at the page level via Pilot.StorageState().
type BrowserCrashedError ¶
BrowserCrashedError represents an unexpected browser exit.
func (*BrowserCrashedError) Error ¶
func (e *BrowserCrashedError) Error() string
type ClickOptions ¶
type ClickOptions struct {
Button MouseButton
ClickCount int
Delay int // milliseconds between mousedown and mouseup
}
ClickOptions configures mouse click behavior.
type ClickerProcess ¶
type ClickerProcess struct {
// contains filtered or unexported fields
}
ClickerProcess manages the clicker binary subprocess.
func StartClicker ¶
func StartClicker(ctx context.Context, opts LaunchOptions) (*ClickerProcess, error)
StartClicker starts the clicker binary and returns a ClickerProcess.
func (*ClickerProcess) Port ¶
func (p *ClickerProcess) Port() int
Port returns the port the clicker is listening on.
func (*ClickerProcess) Process ¶ added in v0.8.0
func (p *ClickerProcess) Process() *os.Process
Process returns the underlying os.Process.
func (*ClickerProcess) Stop ¶
func (p *ClickerProcess) Stop() error
Stop gracefully stops the clicker process.
func (*ClickerProcess) Wait ¶
func (p *ClickerProcess) Wait() error
Wait waits for the clicker process to exit.
func (*ClickerProcess) WebSocketURL ¶
func (p *ClickerProcess) WebSocketURL() string
WebSocketURL returns the WebSocket URL for connecting to the clicker.
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock provides control over time in the browser.
func NewClock ¶
func NewClock(client *BiDiClient, browsingContext string) *Clock
NewClock creates a new Clock controller.
func (*Clock) FastForward ¶
FastForward advances time by the specified number of milliseconds. Timers are not fired.
func (*Clock) Install ¶
func (c *Clock) Install(ctx context.Context, opts *ClockInstallOptions) error
Install installs fake timers in the browser. This replaces native time-related functions like Date, setTimeout, etc.
func (*Clock) RunFor ¶
RunFor advances time by the specified number of milliseconds, firing all pending timers.
func (*Clock) SetFixedTime ¶
SetFixedTime sets a fixed time that will be returned by Date.now() and new Date().
func (*Clock) SetSystemTime ¶
SetSystemTime sets the system time.
type ClockInstallOptions ¶
type ClockInstallOptions struct {
// Time to set as the current time (Unix timestamp in milliseconds or time.Time)
Time interface{}
}
ClockInstallOptions configures clock installation.
type ConnectionError ¶
ConnectionError represents a WebSocket connection failure.
func (*ConnectionError) Error ¶
func (e *ConnectionError) Error() string
func (*ConnectionError) Unwrap ¶
func (e *ConnectionError) Unwrap() error
type ConsoleEntry ¶
type ConsoleEntry = cdp.ConsoleEntry
ConsoleEntry is an alias for cdp.ConsoleEntry.
type ConsoleHandler ¶
type ConsoleHandler func(*ConsoleMessage)
ConsoleHandler is called for each console message.
type ConsoleMessage ¶
type ConsoleMessage struct {
Type string `json:"type"`
Text string `json:"text"`
Args []string `json:"args,omitempty"`
URL string `json:"url,omitempty"`
Line int `json:"line,omitempty"`
}
ConsoleMessage represents a console message from the browser.
type ContinueOptions ¶
ContinueOptions configures how to continue a route.
type Cookie ¶
type Cookie struct {
Name string `json:"name"`
Value string `json:"value"`
Domain string `json:"domain"`
Path string `json:"path"`
Expires float64 `json:"expires"`
HTTPOnly bool `json:"httpOnly"`
Secure bool `json:"secure"`
SameSite string `json:"sameSite"`
PartitionKey string `json:"partitionKey,omitempty"`
}
Cookie represents a browser cookie.
type CoverageReport ¶
type CoverageReport = cdp.CoverageReport
CoverageReport is an alias for cdp.CoverageReport.
type CoverageSummary ¶
type CoverageSummary = cdp.CoverageSummary
CoverageSummary is an alias for cdp.CoverageSummary.
type Dialog ¶
type Dialog struct {
Type string `json:"type"` // "alert", "confirm", "prompt", "beforeunload"
Message string `json:"message"`
Default string `json:"defaultValue,omitempty"` // For prompt dialogs
// contains filtered or unexported fields
}
Dialog represents a browser dialog (alert, confirm, prompt, beforeunload).
type DialogHandler ¶
type DialogHandler func(*Dialog)
DialogHandler is called when a dialog appears.
type DialogInfo ¶
type DialogInfo struct {
HasDialog bool `json:"has_dialog"`
Type string `json:"type,omitempty"`
Message string `json:"message,omitempty"`
DefaultValue string `json:"default_value,omitempty"`
}
DialogInfo contains information about the current dialog.
type Download ¶
type Download struct {
URL string `json:"url"`
Name string `json:"suggestedFilename"`
// contains filtered or unexported fields
}
Download represents a file download.
type DownloadHandler ¶
type DownloadHandler func(*Download)
DownloadHandler is called when a download starts.
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element represents a DOM element that can be interacted with.
func NewElement ¶
func NewElement(client *BiDiClient, browsingContext, selector string, info ElementInfo) *Element
NewElement creates a new Element instance.
func (*Element) BoundingBox ¶
func (e *Element) BoundingBox(ctx context.Context) (BoundingBox, error)
BoundingBox returns the element's bounding box.
func (*Element) Check ¶
func (e *Element) Check(ctx context.Context, opts *ActionOptions) error
Check checks a checkbox element. It waits for the element to be visible, stable, and enabled.
func (*Element) Clear ¶
func (e *Element) Clear(ctx context.Context, opts *ActionOptions) error
Clear clears the text content of an input field.
func (*Element) Click ¶
func (e *Element) Click(ctx context.Context, opts *ActionOptions) error
Click clicks on the element. It waits for the element to be visible, stable, able to receive events, and enabled before clicking.
func (*Element) DblClick ¶
func (e *Element) DblClick(ctx context.Context, opts *ActionOptions) error
DblClick double-clicks on the element.
func (*Element) DispatchEvent ¶
func (e *Element) DispatchEvent(ctx context.Context, eventType string, eventInit map[string]interface{}) error
DispatchEvent dispatches a DOM event on the element.
func (*Element) Eval ¶
Eval evaluates a JavaScript function with this element as the argument. The function should accept the element as its first parameter.
func (*Element) Fill ¶
Fill clears the input and fills it with the specified value. It waits for the element to be visible, stable, enabled, and editable before filling.
func (*Element) Find ¶
Find finds a child element within this element by CSS selector or semantic options.
func (*Element) FindAll ¶
func (e *Element) FindAll(ctx context.Context, selector string, opts *FindOptions) ([]*Element, error)
FindAll finds all child elements within this element by CSS selector or semantic options.
func (*Element) Focus ¶
func (e *Element) Focus(ctx context.Context, opts *ActionOptions) error
Focus focuses the element.
func (*Element) GetAttribute ¶
GetAttribute returns the value of the specified attribute.
func (*Element) Highlight ¶
func (e *Element) Highlight(ctx context.Context, opts *HighlightOptions) error
Highlight draws a visual overlay on the element for debugging. The highlight is displayed for the specified duration (default 2 seconds). This is useful for visual debugging to see which element is being targeted.
func (*Element) Hover ¶
func (e *Element) Hover(ctx context.Context, opts *ActionOptions) error
Hover moves the mouse over the element.
func (*Element) IsEditable ¶
IsEditable returns whether the element is editable.
func (*Element) Press ¶
Press presses a key on the element. It waits for the element to be visible, stable, and able to receive events.
func (*Element) Screenshot ¶
Screenshot captures a screenshot of just this element.
func (*Element) ScrollIntoView ¶
func (e *Element) ScrollIntoView(ctx context.Context, opts *ActionOptions) error
ScrollIntoView scrolls the element into the visible area of the viewport.
func (*Element) SelectOption ¶
func (e *Element) SelectOption(ctx context.Context, values SelectOptionValues, opts *ActionOptions) error
SelectOption selects an option in a <select> element by value, label, or index.
func (*Element) Tap ¶
func (e *Element) Tap(ctx context.Context, opts *ActionOptions) error
Tap performs a touch tap on the element.
func (*Element) Type ¶
Type types text into the element. It waits for the element to be visible, stable, able to receive events, enabled, and editable before typing.
func (*Element) Uncheck ¶
func (e *Element) Uncheck(ctx context.Context, opts *ActionOptions) error
Uncheck unchecks a checkbox element. It waits for the element to be visible, stable, and enabled.
func (*Element) VerifyChecked ¶ added in v0.8.0
VerifyChecked verifies that the checkbox/radio element is checked.
func (*Element) VerifyDisabled ¶ added in v0.8.0
VerifyDisabled verifies that the element is disabled.
func (*Element) VerifyEnabled ¶ added in v0.8.0
VerifyEnabled verifies that the element is enabled.
func (*Element) VerifyHidden ¶ added in v0.8.0
VerifyHidden verifies that the element is hidden.
func (*Element) VerifyText ¶ added in v0.8.0
VerifyText verifies that the element's text matches the expected value. By default, it checks if the text contains the expected value. Set opts.Exact = true to require an exact match.
func (*Element) VerifyUnchecked ¶ added in v0.8.0
VerifyUnchecked verifies that the checkbox/radio element is unchecked.
func (*Element) VerifyValue ¶ added in v0.8.0
VerifyValue verifies that the element's value matches the expected value.
func (*Element) VerifyVisible ¶ added in v0.8.0
VerifyVisible verifies that the element is visible.
type ElementInfo ¶
type ElementInfo struct {
Tag string `json:"tag"`
Text string `json:"text"`
Box BoundingBox `json:"box"`
}
ElementInfo contains metadata about a DOM element.
type ElementNotFoundError ¶
type ElementNotFoundError struct {
Selector string `json:"selector"`
PageContext *PageContext `json:"page_context,omitempty"`
Suggestions []string `json:"suggestions,omitempty"`
}
ElementNotFoundError represents an element that could not be found.
func (*ElementNotFoundError) Error ¶
func (e *ElementNotFoundError) Error() string
type EmulateMediaOptions ¶
type EmulateMediaOptions struct {
Media string // "screen", "print", or ""
ColorScheme string // "light", "dark", "no-preference", or ""
ReducedMotion string // "reduce", "no-preference", or ""
ForcedColors string // "active", "none", or ""
Contrast string // "more", "less", "no-preference", or ""
}
EmulateMediaOptions configures media emulation for accessibility testing.
type EventHandler ¶
type EventHandler func(event *BiDiEvent)
EventHandler is a callback for handling BiDi events.
type ExceptionDetails ¶
type ExceptionDetails = cdp.ExceptionDetails
ExceptionDetails is an alias for cdp.ExceptionDetails.
type ExtensionInfo ¶
type ExtensionInfo = cdp.ExtensionInfo
ExtensionInfo contains information about a browser extension.
type ExtractTableOptions ¶
type ExtractTableOptions struct {
// IncludeHeaders determines if the first row is treated as headers
IncludeHeaders bool
// MaxRows limits the number of rows to extract (0 = no limit)
MaxRows int
// HeaderSelector is a custom selector for header cells (default: th, thead td)
HeaderSelector string
// RowSelector is a custom selector for data rows (default: tbody tr, tr)
RowSelector string
// CellSelector is a custom selector for cells (default: td)
CellSelector string
}
ExtractTableOptions configures the table extraction.
type FindOptions ¶
type FindOptions struct {
// Timeout specifies how long to wait for the element to appear.
// Default is 30 seconds.
Timeout time.Duration
// Role matches elements by ARIA role (e.g., "button", "textbox").
Role string
// Text matches elements containing the specified text.
Text string
// Label matches elements by their associated label text.
Label string
// Placeholder matches input elements by placeholder attribute.
Placeholder string
// TestID matches elements by data-testid attribute.
TestID string
// Alt matches image elements by alt attribute.
Alt string
// Title matches elements by title attribute.
Title string
// XPath matches elements using an XPath expression.
XPath string
// Near finds elements near another element specified by selector.
Near string
}
FindOptions configures element finding behavior.
type FulfillOptions ¶
type FulfillOptions struct {
Status int
Headers map[string]string
ContentType string
Body []byte
Path string // Path to file to serve
}
FulfillOptions configures how to fulfill a route.
type GenerateLocatorOptions ¶ added in v0.8.0
type GenerateLocatorOptions struct {
// Strategy specifies the locator strategy: css, xpath, testid, role, text.
// Default is "css".
Strategy string
// Timeout for finding the element.
Timeout time.Duration
}
GenerateLocatorOptions configures locator generation.
type Geolocation ¶
Geolocation represents geographic coordinates.
type HighlightOptions ¶
type HighlightOptions struct {
// Color is the highlight border color (CSS color value).
// Default is "red".
Color string
// Duration is how long to show the highlight in milliseconds.
// Default is 2000 (2 seconds). Use 0 for persistent highlight.
Duration int
}
HighlightOptions configures element highlighting.
type InspectButton ¶
type InspectButton struct {
Selector string `json:"selector"`
Text string `json:"text"`
Type string `json:"type,omitempty"` // button, submit, reset
Disabled bool `json:"disabled,omitempty"` // true if disabled
Visible bool `json:"visible"`
}
InspectButton represents a button element.
type InspectHeading ¶
type InspectHeading struct {
Selector string `json:"selector"`
Level int `json:"level"` // 1-6
Text string `json:"text"`
Visible bool `json:"visible"`
}
InspectHeading represents a heading element.
type InspectImage ¶
type InspectImage struct {
Selector string `json:"selector"`
Alt string `json:"alt"`
Src string `json:"src"`
Visible bool `json:"visible"`
}
InspectImage represents an image element.
type InspectInput ¶
type InspectInput struct {
Selector string `json:"selector"`
Type string `json:"type"` // text, password, email, etc.
Name string `json:"name,omitempty"` // input name attribute
Placeholder string `json:"placeholder,omitempty"` // placeholder text
Value string `json:"value,omitempty"` // current value (masked for password)
Label string `json:"label,omitempty"` // associated label text
Required bool `json:"required,omitempty"` // true if required
Disabled bool `json:"disabled,omitempty"` // true if disabled
ReadOnly bool `json:"readonly,omitempty"` // true if readonly
Visible bool `json:"visible"`
}
InspectInput represents an input element.
type InspectLink ¶
type InspectLink struct {
Selector string `json:"selector"`
Text string `json:"text"`
Href string `json:"href"`
Visible bool `json:"visible"`
}
InspectLink represents a link element.
type InspectOptions ¶
type InspectOptions struct {
// IncludeButtons includes button elements (button, input[type=button], input[type=submit], [role=button])
IncludeButtons bool
// IncludeLinks includes anchor elements (a[href])
IncludeLinks bool
// IncludeInputs includes input and textarea elements
IncludeInputs bool
// IncludeSelects includes select elements
IncludeSelects bool
// IncludeHeadings includes heading elements (h1-h6)
IncludeHeadings bool
// IncludeImages includes images with alt text
IncludeImages bool
// MaxItems limits the number of items per category (0 = no limit, default 50)
MaxItems int
}
InspectOptions configures what elements to include in the inspection.
func DefaultInspectOptions ¶
func DefaultInspectOptions() *InspectOptions
DefaultInspectOptions returns the default inspection options.
type InspectResult ¶
type InspectResult struct {
URL string `json:"url"`
Title string `json:"title"`
Buttons []InspectButton `json:"buttons,omitempty"`
Links []InspectLink `json:"links,omitempty"`
Inputs []InspectInput `json:"inputs,omitempty"`
Selects []InspectSelect `json:"selects,omitempty"`
Headings []InspectHeading `json:"headings,omitempty"`
Images []InspectImage `json:"images,omitempty"`
Summary InspectSummary `json:"summary"`
}
InspectResult contains the results of page inspection.
type InspectSelect ¶
type InspectSelect struct {
Selector string `json:"selector"`
Name string `json:"name,omitempty"`
Label string `json:"label,omitempty"`
Options []string `json:"options"` // option texts (limited)
Selected string `json:"selected,omitempty"` // currently selected option text
Multiple bool `json:"multiple,omitempty"`
Disabled bool `json:"disabled,omitempty"`
Visible bool `json:"visible"`
}
InspectSelect represents a select element.
type InspectSummary ¶
type InspectSummary struct {
TotalButtons int `json:"total_buttons"`
TotalLinks int `json:"total_links"`
TotalInputs int `json:"total_inputs"`
TotalSelects int `json:"total_selects"`
TotalHeadings int `json:"total_headings"`
TotalImages int `json:"total_images"`
}
InspectSummary provides a summary of the inspection results.
type Keyboard ¶
type Keyboard struct {
// contains filtered or unexported fields
}
Keyboard provides keyboard input control.
func NewKeyboard ¶
func NewKeyboard(client *BiDiClient, browsingContext string) *Keyboard
NewKeyboard creates a new Keyboard controller.
func (*Keyboard) InsertText ¶
InsertText inserts text directly without keypress events. This is faster than Type but doesn't trigger keyboard events.
func (*Keyboard) Press ¶
Press presses a key on the keyboard. Key names follow the Playwright key naming convention (e.g., "Enter", "Tab", "ArrowUp").
type LaunchOptions ¶
type LaunchOptions struct {
// Headless runs the browser without a visible window.
Headless bool
// UseWebSocket uses WebSocket transport instead of pipe (stdin/stdout).
// Default is false (use pipe mode for full vibium:* command support).
// Set to true for WebSocket mode (useful for multiple clients or debugging).
UseWebSocket bool
// Port specifies the WebSocket server port for clicker (WebSocket mode only).
// If 0, an available port is auto-selected.
Port int
// ExecutablePath specifies a custom path to the clicker binary.
// If empty, it will be discovered automatically from PATH or standard locations.
ExecutablePath string
// Deprecated: UserDataDir is now handled by vibium.
UserDataDir string
// Deprecated: Args is now handled by vibium.
Args []string
// Deprecated: AutoInstall is no longer used. Install vibium separately.
AutoInstall *bool
}
LaunchOptions configures browser launch behavior.
type LighthouseCategory ¶
type LighthouseCategory string
LighthouseCategory represents a Lighthouse audit category.
const ( LighthousePerformance LighthouseCategory = "performance" LighthouseAccessibility LighthouseCategory = "accessibility" LighthouseBestPractices LighthouseCategory = "best-practices" LighthouseSEO LighthouseCategory = "seo" )
type LighthouseDevice ¶
type LighthouseDevice string
LighthouseDevice represents the device to emulate.
const ( LighthouseDesktop LighthouseDevice = "desktop" LighthouseMobile LighthouseDevice = "mobile" )
type LighthouseOptions ¶
type LighthouseOptions struct {
// Categories to audit (default: all)
Categories []LighthouseCategory
// Device to emulate (default: desktop)
Device LighthouseDevice
// OutputDir for reports (default: temp directory)
OutputDir string
// Port for Chrome debugging (default: use Pilot's CDP port)
Port int
}
LighthouseOptions configures a Lighthouse audit.
type LighthouseResult ¶
type LighthouseResult struct {
// URL that was audited
URL string `json:"url"`
// Device used for emulation
Device string `json:"device"`
// Scores by category (0-100)
Scores map[string]LighthouseScore `json:"scores"`
// Timing information
TotalDurationMS float64 `json:"totalDurationMs"`
// Report paths
JSONReportPath string `json:"jsonReportPath,omitempty"`
HTMLReportPath string `json:"htmlReportPath,omitempty"`
// Summary of audits
PassedAudits int `json:"passedAudits"`
FailedAudits int `json:"failedAudits"`
}
LighthouseResult contains the results of a Lighthouse audit.
type LighthouseScore ¶
LighthouseScore represents a category score.
type LocatorInfo ¶ added in v0.8.0
type LocatorInfo struct {
// Locator is the generated locator string.
Locator string `json:"locator"`
// Strategy is the locator strategy used (css, xpath, testid, role, text).
Strategy string `json:"strategy"`
// Metadata contains additional information about the element.
Metadata map[string]string `json:"metadata,omitempty"`
}
LocatorInfo contains information about a generated locator.
type LoginOptions ¶
type LoginOptions struct {
// UsernameSelector is the CSS selector for the username/email field
UsernameSelector string
// PasswordSelector is the CSS selector for the password field
PasswordSelector string
// SubmitSelector is the CSS selector for the submit button
SubmitSelector string
// Username is the username/email to fill
Username string
// Password is the password to fill
Password string
// SuccessIndicator is a CSS selector or URL pattern that indicates successful login
SuccessIndicator string
// Timeout for the entire login process
Timeout time.Duration
}
LoginOptions configures the login workflow.
type LoginResult ¶
type LoginResult struct {
Success bool `json:"success"`
URL string `json:"url"`
Title string `json:"title"`
Message string `json:"message"`
ErrorReason string `json:"error_reason,omitempty"`
}
LoginResult contains the result of a login attempt.
type MemoryStats ¶
type MemoryStats struct {
UsedJSHeapSize int64 `json:"usedJSHeapSize"` // Used JS heap size in bytes
TotalJSHeapSize int64 `json:"totalJSHeapSize"` // Total JS heap size in bytes
JSHeapSizeLimit int64 `json:"jsHeapSizeLimit"` // JS heap size limit in bytes
}
MemoryStats contains JavaScript heap memory information.
type MockRouteOptions ¶
type MockRouteOptions struct {
Status int // HTTP status code (default: 200)
Body string // Response body
ContentType string // Content-Type header (default: application/json)
Headers map[string]string // Additional response headers
}
MockRouteOptions configures a static mock response for a route.
type Mouse ¶
type Mouse struct {
// contains filtered or unexported fields
}
Mouse provides mouse input control.
func NewMouse ¶
func NewMouse(client *BiDiClient, browsingContext string) *Mouse
NewMouse creates a new Mouse controller.
func (*Mouse) Down ¶
func (m *Mouse) Down(ctx context.Context, button MouseButton) error
Down presses the mouse button.
type MouseButton ¶
type MouseButton string
MouseButton represents a mouse button.
const ( MouseButtonLeft MouseButton = "left" MouseButtonRight MouseButton = "right" MouseButtonMiddle MouseButton = "middle" )
type NetworkRequest ¶
type NetworkRequest struct {
URL string `json:"url"`
Method string `json:"method"`
Headers map[string]string `json:"headers,omitempty"`
PostData string `json:"postData,omitempty"`
ResourceType string `json:"resourceType"`
Status int `json:"status,omitempty"`
StatusText string `json:"statusText,omitempty"`
ResponseSize int64 `json:"responseSize,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"`
}
NetworkRequest represents a captured network request with its response.
type NetworkRequestsOptions ¶
type NetworkRequestsOptions struct {
URLPattern string // Glob or regex pattern to filter URLs
Method string // Filter by HTTP method (GET, POST, etc.)
ResourceType string // Filter by resource type (document, script, xhr, etc.)
}
NetworkRequestsOptions configures network request filtering.
type PDFOptions ¶
type PDFOptions struct {
Path string
Scale float64
DisplayHeader bool
PrintBackground bool
Landscape bool
PageRanges string
Format string // "Letter", "Legal", "Tabloid", "A0"-"A6"
Width string
Height string
Margin *PDFMargin
}
PDFOptions configures PDF generation.
type PageContext ¶
type PageContext struct {
URL string `json:"url"`
Title string `json:"title"`
VisibleText string `json:"visible_text,omitempty"`
}
PageContext provides context about the page state when an error occurred. This helps AI agents understand the situation and recover from errors.
type PageError ¶
type PageError struct {
Message string `json:"message"`
Stack string `json:"stack,omitempty"`
URL string `json:"url,omitempty"`
Line int `json:"line,omitempty"`
Column int `json:"column,omitempty"`
}
PageError represents a JavaScript error that occurred on the page.
type PageErrorHandler ¶
type PageErrorHandler func(*PageError)
PageErrorHandler is called when a JavaScript error occurs on the page.
type PerformanceMetrics ¶
type PerformanceMetrics struct {
// Core Web Vitals
LCP float64 `json:"lcp,omitempty"` // Largest Contentful Paint (ms)
CLS float64 `json:"cls,omitempty"` // Cumulative Layout Shift
INP float64 `json:"inp,omitempty"` // Interaction to Next Paint (ms)
FID float64 `json:"fid,omitempty"` // First Input Delay (ms)
FCP float64 `json:"fcp,omitempty"` // First Contentful Paint (ms)
TTFB float64 `json:"ttfb,omitempty"` // Time to First Byte (ms)
// Navigation Timing
DOMContentLoaded float64 `json:"domContentLoaded,omitempty"` // DOMContentLoaded event (ms)
Load float64 `json:"load,omitempty"` // Load event (ms)
DOMInteractive float64 `json:"domInteractive,omitempty"` // DOM interactive (ms)
// Resource Timing
ResourceCount int `json:"resourceCount,omitempty"` // Number of resources loaded
}
PerformanceMetrics contains Core Web Vitals and navigation timing.
type Pilot ¶
type Pilot struct {
// contains filtered or unexported fields
}
Pilot is the main browser control interface.
func Connect ¶ added in v0.8.0
Connect is a convenience function that connects to an existing browser.
func LaunchHeadless ¶
LaunchHeadless is a convenience function that launches a headless browser.
func (*Pilot) A11yTree ¶
func (p *Pilot) A11yTree(ctx context.Context, opts *A11yTreeOptions) (interface{}, error)
A11yTree returns the accessibility tree for the page. Options can filter the tree to only interesting nodes or specify a root element.
func (*Pilot) AddInitScript ¶
AddInitScript adds a script that will be evaluated in every page before any page scripts. This is useful for mocking APIs, injecting test helpers, or setting up authentication.
func (*Pilot) AssertElement ¶ added in v0.8.0
AssertElement asserts that an element matching the selector exists.
func (*Pilot) AssertText ¶ added in v0.8.0
AssertText asserts that the specified text exists on the page.
func (*Pilot) AssertURL ¶ added in v0.8.0
AssertURL asserts that the current URL matches the expected pattern. The pattern can be an exact URL, a glob pattern (with *), or a regex (wrapped in /).
func (*Pilot) BringToFront ¶
BringToFront activates the page (brings the browser tab to front).
func (*Pilot) BrowserLogs ¶
BrowserLogs returns all captured browser log entries (deprecations, interventions). Call EnableConsoleDebugger first to start capturing.
func (*Pilot) BrowserVersion ¶
BrowserVersion returns the browser version string.
func (*Pilot) BrowsingContext ¶
BrowsingContext returns the browsing context ID for this page.
func (*Pilot) CDP ¶
CDP returns the Chrome DevTools Protocol client, or nil if not available. Use HasCDP() to check availability before calling CDP methods.
func (*Pilot) ClearCPUEmulation ¶
ClearCPUEmulation clears CPU throttling. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) ClearConsoleDebugger ¶
func (p *Pilot) ClearConsoleDebugger()
ClearConsoleDebugger clears all captured console entries, exceptions, and logs.
func (*Pilot) ClearConsoleMessages ¶
ClearConsoleMessages clears the buffered console messages. Tries BiDi first, falls back to CDP if BiDi doesn't support this command.
func (*Pilot) ClearErrors ¶
ClearErrors clears the buffered page errors.
func (*Pilot) ClearNetworkEmulation ¶
ClearNetworkEmulation clears network throttling. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) ClearNetworkRequests ¶
ClearNetworkRequests clears the buffered network requests.
func (*Pilot) ClearStorage ¶
ClearStorage clears all cookies, localStorage, and sessionStorage.
func (*Pilot) Clicker ¶ added in v0.8.0
func (p *Pilot) Clicker() *ClickerProcess
Clicker returns the clicker process, or nil if using pipe mode.
func (*Pilot) CollectConsole ¶
CollectConsole enables buffered console message collection. Messages can be retrieved with ConsoleMessages() and cleared with ClearConsoleMessages().
func (*Pilot) CollectErrors ¶
CollectErrors enables buffered page error collection. Errors can be retrieved with Errors() and cleared with ClearErrors().
func (*Pilot) ConsoleEntries ¶
func (p *Pilot) ConsoleEntries() []ConsoleEntry
ConsoleEntries returns all captured console entries with stack traces. Call EnableConsoleDebugger first to start capturing.
func (*Pilot) ConsoleExceptions ¶
func (p *Pilot) ConsoleExceptions() []ExceptionDetails
ConsoleExceptions returns all captured JavaScript exceptions. Call EnableConsoleDebugger first to start capturing.
func (*Pilot) ConsoleMessages ¶
ConsoleMessages returns buffered console messages from the page. The level parameter filters messages by type (log, info, warn, error, debug). If level is empty, all messages are returned.
func (*Pilot) Context ¶
func (p *Pilot) Context() *BrowserContext
Context returns the browser context for this page. Returns nil if this is the default context.
func (*Pilot) DisableConsoleDebugger ¶
DisableConsoleDebugger stops capturing console messages. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) EmulateCPU ¶
EmulateCPU sets CPU throttling. rate=1 means no throttling, rate=4 means 4x slowdown. Use cdp.CPU4xSlowdown, cdp.CPU6xSlowdown, etc. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) EmulateMedia ¶
func (p *Pilot) EmulateMedia(ctx context.Context, opts EmulateMediaOptions) error
EmulateMedia sets the media emulation options.
func (*Pilot) EmulateNetwork ¶
EmulateNetwork sets network throttling conditions. Use cdp.NetworkSlow3G, cdp.NetworkFast3G, cdp.Network4G, etc. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) EnableConsoleDebugger ¶
EnableConsoleDebugger starts capturing console messages with full stack traces. This uses CDP Runtime domain for enhanced debugging compared to BiDi console events. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) Errors ¶
Errors retrieves buffered page errors. Call CollectErrors() first to enable error collection.
func (*Pilot) Expose ¶
Expose exposes a function that can be called from JavaScript in the page. Note: The handler function must be registered separately.
func (*Pilot) ExtractTable ¶
func (p *Pilot) ExtractTable(ctx context.Context, selector string, opts *ExtractTableOptions) (*TableResult, error)
ExtractTable extracts data from an HTML table into structured JSON.
func (*Pilot) FindAll ¶
func (p *Pilot) FindAll(ctx context.Context, selector string, opts *FindOptions) ([]*Element, error)
FindAll finds all elements matching the selector and optional semantic options. If selector is empty but semantic options are provided, elements are found by those options.
func (*Pilot) GenerateLocator ¶ added in v0.8.0
func (p *Pilot) GenerateLocator(ctx context.Context, selector string, opts *GenerateLocatorOptions) (*LocatorInfo, error)
GenerateLocator generates a robust locator for the element at the given selector.
func (*Pilot) GetDialog ¶
func (p *Pilot) GetDialog(ctx context.Context) (DialogInfo, error)
GetDialog returns information about the current dialog, if any.
func (*Pilot) GetMemoryStats ¶
func (p *Pilot) GetMemoryStats(ctx context.Context) (*MemoryStats, error)
GetMemoryStats retrieves JavaScript heap memory information. Note: This requires Chrome with --enable-precise-memory-info flag.
func (*Pilot) GetNetworkResponseBody ¶
func (p *Pilot) GetNetworkResponseBody(ctx context.Context, requestID string, saveTo string) (*cdp.ResponseBody, error)
GetNetworkResponseBody retrieves the body of a network response. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) GetPerformanceMetrics ¶
func (p *Pilot) GetPerformanceMetrics(ctx context.Context) (*PerformanceMetrics, error)
GetPerformanceMetrics retrieves Core Web Vitals and navigation timing. Note: Some metrics (LCP, CLS, INP) require user interaction or time to measure.
func (*Pilot) GetViewport ¶
GetViewport returns the current viewport dimensions.
func (*Pilot) GetWindow ¶
func (p *Pilot) GetWindow(ctx context.Context) (WindowState, error)
GetWindow returns the browser window state.
func (*Pilot) HandleDialog ¶
HandleDialog handles the current dialog by accepting or dismissing it. If accept is true, the dialog is accepted. If promptText is provided (for prompt dialogs), it will be entered before accepting.
func (*Pilot) Inspect ¶
func (p *Pilot) Inspect(ctx context.Context, opts *InspectOptions) (*InspectResult, error)
Inspect examines the current page and returns information about interactive elements. This is designed to help AI agents understand the page structure.
func (*Pilot) InstallExtension ¶
InstallExtension loads an unpacked extension from a directory. Returns the extension ID if successful. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) IsConsoleDebuggerEnabled ¶
IsConsoleDebuggerEnabled returns whether the console debugger is active.
func (*Pilot) IsCoverageRunning ¶
IsCoverageRunning returns whether coverage collection is active.
func (*Pilot) IsScreencasting ¶
IsScreencasting returns whether screencast is active.
func (*Pilot) LighthouseAudit ¶
func (p *Pilot) LighthouseAudit(ctx context.Context, opts *LighthouseOptions) (*LighthouseResult, error)
LighthouseAudit runs a Lighthouse audit on the current page. Requires lighthouse CLI: npm install -g lighthouse
func (*Pilot) ListExtensions ¶
func (p *Pilot) ListExtensions(ctx context.Context) ([]ExtensionInfo, error)
ListExtensions returns all installed extensions. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) ListRoutes ¶
ListRoutes returns all active route handlers.
func (*Pilot) Login ¶
func (p *Pilot) Login(ctx context.Context, opts *LoginOptions) (*LoginResult, error)
Login performs an automated login workflow. It fills the username and password fields, submits the form, and waits for success.
func (*Pilot) MainFrame ¶
MainFrame returns the main frame of the page. Since Pilot represents both page and frame in this SDK, it returns itself. This method exists for API compatibility with other W3Pilot clients.
func (*Pilot) MockRoute ¶
MockRoute registers a route that returns a static mock response. This is useful for MCP tools and testing without callbacks.
func (*Pilot) NetworkRequests ¶
func (p *Pilot) NetworkRequests(ctx context.Context, opts *NetworkRequestsOptions) ([]NetworkRequest, error)
NetworkRequests returns buffered network requests from the page. Options can filter by URL pattern, method, or resource type.
func (*Pilot) NewContext ¶
func (p *Pilot) NewContext(ctx context.Context) (*BrowserContext, error)
NewContext creates a new isolated browser context.
func (*Pilot) ObserveWebVitals ¶
func (p *Pilot) ObserveWebVitals(ctx context.Context) (<-chan *PerformanceMetrics, func(), error)
ObserveWebVitals starts observing Core Web Vitals in real-time. Returns a channel that receives metrics as they are measured. Call the returned cancel function to stop observing.
func (*Pilot) OnConsole ¶
func (p *Pilot) OnConsole(ctx context.Context, handler ConsoleHandler) error
OnConsole registers a handler for console messages.
func (*Pilot) OnDialog ¶
func (p *Pilot) OnDialog(ctx context.Context, handler DialogHandler) error
OnDialog registers a handler for dialogs (alert, confirm, prompt).
func (*Pilot) OnDownload ¶
func (p *Pilot) OnDownload(ctx context.Context, handler DownloadHandler) error
OnDownload registers a handler for downloads.
func (*Pilot) OnError ¶
func (p *Pilot) OnError(ctx context.Context, handler PageErrorHandler) error
OnError registers a handler for JavaScript errors on the page.
func (*Pilot) OnPage ¶
func (p *Pilot) OnPage(ctx context.Context, handler PageHandler) error
OnPage registers a handler that is called when a new page is created in the browser. This includes pages created via NewPage(), window.open(), or clicking links with target="_blank".
func (*Pilot) OnPopup ¶
func (p *Pilot) OnPopup(ctx context.Context, handler PopupHandler) error
OnPopup registers a handler that is called when a popup window is opened. Popups are typically created via window.open() with specific features.
func (*Pilot) OnRequest ¶
func (p *Pilot) OnRequest(ctx context.Context, handler RequestHandler) error
OnRequest registers a handler for network requests. Note: This is a convenience method; for full control use Route().
func (*Pilot) OnResponse ¶
func (p *Pilot) OnResponse(ctx context.Context, handler ResponseHandler) error
OnResponse registers a handler for network responses.
func (*Pilot) OnWebSocket ¶
func (p *Pilot) OnWebSocket(ctx context.Context, handler WebSocketHandler) error
OnWebSocket registers a handler that is called when the page opens a WebSocket connection.
func (*Pilot) RemoveAllListeners ¶
func (p *Pilot) RemoveAllListeners()
RemoveAllListeners removes all registered event listeners. This is useful for cleanup when you no longer need to receive events.
func (*Pilot) Route ¶
Route registers a handler for requests matching the URL pattern. The pattern can be a glob pattern (e.g., "**/*.png") or regex (e.g., "/api/.*").
func (*Pilot) Screenshot ¶
Screenshot captures a screenshot of the current page and returns PNG data.
func (*Pilot) Scroll ¶
func (p *Pilot) Scroll(ctx context.Context, direction string, amount int, opts *ScrollOptions) error
Scroll scrolls the page or a specific element. direction can be "up", "down", "left", or "right". amount is the number of pixels to scroll (use 0 for full page).
func (*Pilot) SetContent ¶
SetContent sets the HTML content of the page.
func (*Pilot) SetExtraHTTPHeaders ¶
SetExtraHTTPHeaders sets extra HTTP headers that will be sent with every request.
func (*Pilot) SetGeolocation ¶
func (p *Pilot) SetGeolocation(ctx context.Context, coords Geolocation) error
SetGeolocation overrides the browser's geolocation.
func (*Pilot) SetOffline ¶
SetOffline sets the browser's offline mode. Tries BiDi first, falls back to CDP if BiDi doesn't support this command. For fine-grained network control (latency, bandwidth), use EmulateNetwork() instead.
func (*Pilot) SetStorageState ¶
func (p *Pilot) SetStorageState(ctx context.Context, state *StorageState) error
SetStorageState restores browser storage state from a previously saved StorageState. This includes cookies, localStorage, and sessionStorage. The browser should be on a page (or will be navigated to the first origin) for storage to be set correctly.
func (*Pilot) SetViewport ¶
SetViewport sets the viewport dimensions.
func (*Pilot) SetWindow ¶
func (p *Pilot) SetWindow(ctx context.Context, opts SetWindowOptions) error
SetWindow sets the browser window state.
func (*Pilot) StartCSSCoverage ¶
StartCSSCoverage begins collecting CSS coverage data. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) StartCoverage ¶
StartCoverage begins collecting JS and CSS coverage data. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) StartJSCoverage ¶
StartJSCoverage begins collecting JavaScript coverage data. callCount: collect execution counts per block detailed: collect block-level coverage (vs function-level) Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) StartScreencast ¶
func (p *Pilot) StartScreencast(ctx context.Context, opts *cdp.ScreencastOptions, handler ScreencastFrameHandler) error
StartScreencast begins capturing screen frames. The handler is called for each captured frame with base64-encoded image data. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) StartVideo ¶
StartVideo starts recording video of the page. The video is saved when StopVideo is called or the browser closes.
func (*Pilot) StopCoverage ¶
func (p *Pilot) StopCoverage(ctx context.Context) (*CoverageReport, error)
StopCoverage stops coverage collection and returns the results. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) StopScreencast ¶
StopScreencast stops capturing screen frames. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) StorageState ¶
func (p *Pilot) StorageState(ctx context.Context) (*StorageState, error)
StorageState returns the complete browser storage state including cookies, localStorage, and sessionStorage for the current page's origin. This can be saved and later restored using SetStorageState to resume a session.
func (*Pilot) TakeHeapSnapshot ¶
TakeHeapSnapshot captures a V8 heap snapshot and saves it to a file. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) UninstallExtension ¶
UninstallExtension removes an extension by ID. Requires CDP connection. Returns error if CDP is not available.
func (*Pilot) ValidateSelector ¶
ValidateSelector validates a single selector.
func (*Pilot) ValidateSelectors ¶
func (p *Pilot) ValidateSelectors(ctx context.Context, selectors []string) ([]SelectorValidation, error)
ValidateSelectors checks multiple selectors and returns validation results. This helps AI agents verify selectors before attempting interactions.
func (*Pilot) WaitForFunction ¶
WaitForFunction waits for a JavaScript function to return a truthy value.
func (*Pilot) WaitForLoad ¶
WaitForLoad waits for the page to reach the specified load state. State can be: "load", "domcontentloaded", "networkidle".
func (*Pilot) WaitForNavigation ¶
WaitForNavigation waits for a navigation to complete.
type PipeOptions ¶
type PipeOptions struct {
// Headless runs the browser in headless mode.
Headless bool
// ExecutablePath is the path to the clicker binary.
// If empty, it will be discovered automatically.
ExecutablePath string
// StartupTimeout is the maximum time to wait for clicker to be ready.
// Default: 30 seconds.
StartupTimeout time.Duration
}
PipeOptions configures the pipe transport.
type PopupHandler ¶
type PopupHandler func(*Pilot)
PopupHandler is called when a popup window opens.
type Request ¶
type Request struct {
URL string `json:"url"`
Method string `json:"method"`
Headers map[string]string `json:"headers"`
PostData string `json:"postData,omitempty"`
ResourceType string `json:"resourceType"`
}
Request represents a network request.
type RequestHandler ¶
type RequestHandler func(*Request)
RequestHandler is called for each network request.
type Response ¶
type Response struct {
URL string `json:"url"`
Status int `json:"status"`
StatusText string `json:"statusText"`
Headers map[string]string `json:"headers"`
Body []byte `json:"-"`
}
Response represents a network response.
type ResponseHandler ¶
type ResponseHandler func(*Response)
ResponseHandler is called for each network response.
type Route ¶
type Route struct {
Request *Request
// contains filtered or unexported fields
}
Route represents an intercepted network request.
type RouteHandler ¶
RouteHandler is called when a request matches a route pattern.
type RouteInfo ¶
type RouteInfo struct {
Pattern string `json:"pattern"`
Status int `json:"status,omitempty"`
ContentType string `json:"contentType,omitempty"`
}
RouteInfo represents information about an active route.
type ScreencastFrameHandler ¶
type ScreencastFrameHandler func(frame *cdp.ScreencastFrame)
ScreencastFrameHandler is called for each captured screencast frame.
type ScrollOptions ¶
type ScrollOptions struct {
Selector string // Optional CSS selector to scroll within
}
ScrollOptions configures scroll behavior.
type SelectOptionValues ¶
type SelectOptionValues struct {
// Values selects options by their value attribute.
Values []string
// Labels selects options by their visible text.
Labels []string
// Indexes selects options by their zero-based index.
Indexes []int
}
SelectOptionValues specifies which options to select in a <select> element.
type SelectorValidation ¶
type SelectorValidation struct {
Selector string `json:"selector"`
Found bool `json:"found"`
Count int `json:"count"`
Visible bool `json:"visible"`
Enabled bool `json:"enabled,omitempty"`
TagName string `json:"tag_name,omitempty"`
Suggestions []string `json:"suggestions,omitempty"`
}
SelectorValidation represents the validation result for a single selector.
type SetCookieParam ¶
type SetCookieParam struct {
Name string `json:"name"`
Value string `json:"value"`
URL string `json:"url,omitempty"`
Domain string `json:"domain,omitempty"`
Path string `json:"path,omitempty"`
Expires float64 `json:"expires,omitempty"`
HTTPOnly bool `json:"httpOnly,omitempty"`
Secure bool `json:"secure,omitempty"`
SameSite string `json:"sameSite,omitempty"`
PartitionKey string `json:"partitionKey,omitempty"`
}
SetCookieParam represents parameters for setting a cookie.
type SetWindowOptions ¶
type SetWindowOptions struct {
X *int
Y *int
Width *int
Height *int
State string // "normal", "minimized", "maximized", "fullscreen"
}
SetWindowOptions configures window state.
type StorageState ¶
type StorageState struct {
Cookies []Cookie `json:"cookies"`
Origins []StorageStateOrigin `json:"origins"`
}
StorageState represents browser storage state including cookies, localStorage, and sessionStorage.
type StorageStateOrigin ¶
type StorageStateOrigin struct {
Origin string `json:"origin"`
LocalStorage map[string]string `json:"localStorage"`
SessionStorage map[string]string `json:"sessionStorage,omitempty"`
}
StorageStateOrigin represents storage for an origin.
type TableResult ¶
type TableResult struct {
Headers []string `json:"headers,omitempty"`
Rows [][]string `json:"rows"`
RowsJSON []map[string]string `json:"rows_json,omitempty"` // Rows as objects with header keys
RowCount int `json:"row_count"`
}
TableResult contains the extracted table data.
type TimeoutError ¶
type TimeoutError struct {
Selector string `json:"selector"`
Timeout int64 `json:"timeout_ms"` // milliseconds
Reason string `json:"reason,omitempty"`
PageContext *PageContext `json:"page_context,omitempty"`
Suggestions []string `json:"suggestions,omitempty"`
}
TimeoutError represents a timeout waiting for an element or action.
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
type Touch ¶
type Touch struct {
// contains filtered or unexported fields
}
Touch provides touch input control.
func NewTouch ¶
func NewTouch(client *BiDiClient, browsingContext string) *Touch
NewTouch creates a new Touch controller.
type VerificationError ¶ added in v0.8.0
type VerificationError struct {
Type string `json:"type"`
Message string `json:"message"`
Selector string `json:"selector,omitempty"`
Expected string `json:"expected,omitempty"`
Actual string `json:"actual,omitempty"`
}
VerificationError is returned when a verification fails.
func (*VerificationError) Error ¶ added in v0.8.0
func (e *VerificationError) Error() string
type VerifyTextOptions ¶ added in v0.8.0
type VerifyTextOptions struct {
// Exact requires an exact match instead of contains.
Exact bool
}
VerifyTextOptions configures text verification.
type Video ¶
type Video struct {
// FilePath is the file path where the video will be saved.
FilePath string `json:"path,omitempty"`
// contains filtered or unexported fields
}
Video represents an ongoing or completed video recording.
type VideoOptions ¶
type VideoOptions struct {
// Dir is the directory to save videos to. Defaults to a temp directory.
Dir string `json:"dir,omitempty"`
// Size specifies the video dimensions. Defaults to viewport size.
Size *VideoSize `json:"size,omitempty"`
}
VideoOptions configures video recording.
type WebSocketCloseHandler ¶
WebSocketCloseHandler is called when a WebSocket connection is closed.
type WebSocketHandler ¶
type WebSocketHandler func(*WebSocketInfo)
WebSocketHandler is called when a new WebSocket connection is opened.
type WebSocketInfo ¶
type WebSocketInfo struct {
URL string `json:"url"`
IsClosed bool `json:"isClosed"`
// contains filtered or unexported fields
}
WebSocketInfo represents a WebSocket connection made by the page.
func (*WebSocketInfo) OnClose ¶
func (ws *WebSocketInfo) OnClose(handler WebSocketCloseHandler)
OnClose registers a handler for when the WebSocket closes.
func (*WebSocketInfo) OnMessage ¶
func (ws *WebSocketInfo) OnMessage(handler WebSocketMessageHandler)
OnMessage registers a handler for WebSocket messages.
type WebSocketMessage ¶
type WebSocketMessage struct {
SocketID string `json:"socketId"`
Data string `json:"data"`
IsBinary bool `json:"isBinary"`
Direction string `json:"direction"` // "sent" or "received"
}
WebSocketMessage represents a message sent or received on a WebSocket.
type WebSocketMessageHandler ¶
type WebSocketMessageHandler func(*WebSocketMessage)
WebSocketMessageHandler is called when a WebSocket message is sent or received.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cdp provides a Chrome DevTools Protocol client.
|
Package cdp provides a Chrome DevTools Protocol client. |
|
cmd
|
|
|
genscriptschema
command
Command genscriptschema generates JSON Schema from Go types.
|
Command genscriptschema generates JSON Schema from Go types. |
|
w3pilot
command
Command w3pilot provides a CLI for browser automation.
|
Command w3pilot provides a CLI for browser automation. |
|
w3pilot-mcp
command
Command w3pilot-mcp provides an MCP server for browser automation.
|
Command w3pilot-mcp provides an MCP server for browser automation. |
|
w3pilot-rpa
command
|
|
|
Package mcp provides an MCP (Model Context Protocol) server for browser automation.
|
Package mcp provides an MCP (Model Context Protocol) server for browser automation. |
|
report
Package report provides test result tracking and report generation.
|
Package report provides test result tracking and report generation. |
|
Package rpa provides a Robotic Process Automation platform for browser automation.
|
Package rpa provides a Robotic Process Automation platform for browser automation. |
|
activity
Package activity provides the activity system for RPA workflow execution.
|
Package activity provides the activity system for RPA workflow execution. |
|
Package script defines the test script format for Vibium automation.
|
Package script defines the test script format for Vibium automation. |
|
Package session provides shared browser session management for CLI and MCP.
|
Package session provides shared browser session management for CLI and MCP. |