Documentation
¶
Overview ¶
Package web is the Chrome DevTools Protocol execution surface.
Spec 02-device-drivers.md §4 defines it: the hierarchy comes from an injected script, actions are pointer and key input, and settling is document.readyState == "complete". Everything a browser has no notion of — apps, permissions, airplane mode, orientation, media — returns device.ErrUnsupported so preflight refuses such a flow before it runs rather than failing halfway through it.
Index ¶
- Constants
- func DeclaredCapabilities() device.Capabilities
- func DefaultChromeBinary() string
- type Chrome
- type ChromeOptions
- type Driver
- func (driver *Driver) AddMedia(context.Context, device.AddMediaRequest) error
- func (driver *Driver) BackPress(ctx context.Context) error
- func (driver *Driver) Capabilities() device.Capabilities
- func (driver *Driver) ClearAppState(context.Context, device.AppRequest) error
- func (driver *Driver) ClearKeychain(context.Context) error
- func (driver *Driver) Close(context.Context) error
- func (driver *Driver) CollectCrashArtifacts(context.Context, device.ArtifactRequest) ([]device.Artifact, error)
- func (driver *Driver) ContentDescriptor(ctx context.Context, _ device.ContentDescriptorRequest) (device.TreeNode, error)
- func (driver *Driver) DeviceInfo(ctx context.Context) (device.DeviceInfo, error)
- func (driver *Driver) EraseText(ctx context.Context, request device.EraseTextRequest) error
- func (driver *Driver) HideKeyboard(context.Context) error
- func (driver *Driver) InputText(ctx context.Context, request device.InputTextRequest) error
- func (driver *Driver) IsAirplaneModeEnabled(context.Context) (bool, error)
- func (driver *Driver) IsKeyboardVisible(context.Context, device.KeyboardRequest) (bool, error)
- func (driver *Driver) IsShutdown(context.Context) (bool, error)
- func (driver *Driver) KillApp(context.Context, device.AppRequest) error
- func (driver *Driver) LaunchApp(ctx context.Context, request device.LaunchAppRequest) error
- func (driver *Driver) LongPress(ctx context.Context, request device.LongPressRequest) error
- func (driver *Driver) Name() string
- func (driver *Driver) Open(ctx context.Context) error
- func (driver *Driver) OpenLink(ctx context.Context, request device.OpenLinkRequest) error
- func (driver *Driver) PressKey(ctx context.Context, request device.PressKeyRequest) error
- func (driver *Driver) QueryOnDeviceElements(ctx context.Context, request device.QueryRequest) ([]device.TreeNode, error)
- func (driver *Driver) ResetProxy(context.Context) error
- func (driver *Driver) ScrollVertical(ctx context.Context, request device.ScrollVerticalRequest) error
- func (driver *Driver) SetAirplaneMode(context.Context, device.AirplaneModeRequest) error
- func (driver *Driver) SetAndroidChromeDevToolsEnabled(context.Context, device.ChromeDevToolsRequest) error
- func (driver *Driver) SetLocation(ctx context.Context, location device.Location) error
- func (driver *Driver) SetOrientation(context.Context, device.Orientation) error
- func (driver *Driver) SetPermissions(context.Context, device.PermissionsRequest) error
- func (driver *Driver) SetProxy(context.Context, device.Proxy) error
- func (driver *Driver) StartDeviceLogCapture(context.Context, device.DeviceLogRequest) (device.CaptureID, error)
- func (driver *Driver) StartScreenRecording(context.Context, device.ScreenRecordingRequest) (device.CaptureID, error)
- func (driver *Driver) StopApp(ctx context.Context, request device.AppRequest) error
- func (driver *Driver) StopDeviceLogCapture(context.Context, device.CaptureID) ([]device.Artifact, error)
- func (driver *Driver) Swipe(ctx context.Context, request device.SwipeRequest) error
- func (driver *Driver) TakeScreenshot(ctx context.Context, _ device.ScreenshotRequest) ([]byte, error)
- func (driver *Driver) Tap(ctx context.Context, request device.TapRequest) error
- func (driver *Driver) WaitForAppToSettle(ctx context.Context, request device.SettleRequest) (*device.ViewHierarchy, error)
- func (driver *Driver) WaitUntilScreenIsStatic(ctx context.Context, request device.ScreenStaticRequest) (bool, error)
Constants ¶
const DefaultSettleTimeout = 10 * time.Second
DefaultSettleTimeout bounds a readyState wait. A page that never completes must report an unconfirmed settle rather than block the run forever.
const Platform = device.Platform("web")
Variables ¶
This section is empty.
Functions ¶
func DeclaredCapabilities ¶
func DeclaredCapabilities() device.Capabilities
DeclaredCapabilities is the non-mutating Web capability document used by both the driver and selected-platform flow preflight.
func DefaultChromeBinary ¶
func DefaultChromeBinary() string
DefaultChromeBinary is where the browser lives on this platform.
Types ¶
type Chrome ¶
type Chrome struct {
BaseURL string
// contains filtered or unexported fields
}
Chrome is a browser this process started and is responsible for stopping.
func LaunchChrome ¶
func LaunchChrome(ctx context.Context, options ChromeOptions) (*Chrome, error)
LaunchChrome starts the browser and waits for DevTools to answer.
It waits for the endpoint rather than returning immediately: a driver that attaches before the browser is listening fails with a connection error that reads like a missing browser rather than a race.
type ChromeOptions ¶
type ChromeOptions struct {
// Binary is the browser executable; empty picks the platform default.
Binary string
// Port is the DevTools port to listen on.
Port int
// UserDataDir isolates the run's profile.
UserDataDir string
// Headless selects --headless=new.
Headless bool
// WindowSize is the "width,height" the spec passes through.
WindowSize string
}
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver drives one attached browser page over CDP.
func NewDriver ¶
NewDriver builds a driver for a browser already listening for DevTools on baseURL (for example http://127.0.0.1:9222). A nil client uses the default.
func NewLaunchingDriver ¶
func NewLaunchingDriver(options ChromeOptions) *Driver
NewLaunchingDriver builds a driver that starts its own browser on Open and stops it on Close. This is what a CLI run needs: it is handed flows, not a DevTools endpoint.
func (*Driver) Capabilities ¶
func (driver *Driver) Capabilities() device.Capabilities
func (*Driver) ClearAppState ¶
func (*Driver) CollectCrashArtifacts ¶
func (*Driver) ContentDescriptor ¶
func (driver *Driver) ContentDescriptor( ctx context.Context, _ device.ContentDescriptorRequest, ) (device.TreeNode, error)
ContentDescriptor runs the injected walker and converts its payload.
func (*Driver) DeviceInfo ¶
func (*Driver) InputText ¶
InputText types the text as one insertion. Input.insertText is what a page's input handlers see as real typing, including for non-ASCII text a synthetic per-key sequence would mangle.
func (*Driver) IsAirplaneModeEnabled ¶
func (*Driver) IsKeyboardVisible ¶
func (*Driver) LaunchApp ¶
LaunchApp opens the flow's page.
specs/01-core-engine.md:17 makes `url` the web flow's effective appId, so the target arrives here in AppID. A value that is not an http(s) url is a mobile flow aimed at a browser: navigating to it anyway would resolve it as a relative path and run the whole suite against some other page.
func (*Driver) Open ¶
Open attaches to the browser's page target, starting one first when this driver owns it.
func (*Driver) PressKey ¶
PressKey maps the neutral key codes a browser can act on. A code with no web meaning (LOCK, HOME on a phone) is refused rather than silently dropped.
func (*Driver) QueryOnDeviceElements ¶
func (driver *Driver) QueryOnDeviceElements( ctx context.Context, request device.QueryRequest, ) ([]device.TreeNode, error)
QueryOnDeviceElements resolves a CSS expression in the page. This is the driver-side resolver a css selector needs: CSS is a query, not a value, so it cannot be matched against a captured attribute.
func (*Driver) ScrollVertical ¶
func (*Driver) SetAirplaneMode ¶
func (*Driver) SetAndroidChromeDevToolsEnabled ¶
func (*Driver) SetLocation ¶
SetLocation overrides geolocation, which a browser genuinely supports.
func (*Driver) SetOrientation ¶
func (*Driver) SetPermissions ¶
func (*Driver) StartDeviceLogCapture ¶
func (*Driver) StartScreenRecording ¶
func (*Driver) StopApp ¶
StopApp unloads the page.
specs/06-launch-app-semantics.md has launchApp stop the app before starting it unless the flow says otherwise, so every web run reaches this on its way to its first page. about:blank is the browser's version of stopping: it drops the document, its scripts and its timers. Returning nil without navigating would leave the old page live and let a stale assertion pass against it.
func (*Driver) StopDeviceLogCapture ¶
func (*Driver) Swipe ¶
Swipe is touch input: move to the start, press, move to the end, release (spec §4). Direction-only and element-anchored swipes are resolved against the viewport before dispatch.
func (*Driver) TakeScreenshot ¶
func (*Driver) Tap ¶
Tap is the full pointer sequence: a page listening for mousedown/mouseup never sees a click sent as one event (spec §4 pointer input).
func (*Driver) WaitForAppToSettle ¶
func (driver *Driver) WaitForAppToSettle( ctx context.Context, request device.SettleRequest, ) (*device.ViewHierarchy, error)
WaitForAppToSettle polls document.readyState (spec §4). A nil hierarchy means settling could not be confirmed, which the contract separates from settled.