Documentation
¶
Overview ¶
Package cdp controls an existing Chrome browser over the DevTools Protocol. Closing a Client disconnects; it never closes the browser or its tabs.
Index ¶
- type ActionResult
- type Client
- type ControlID
- type Error
- type EvalResult
- type Node
- type Page
- func (p *Page) Click(ctx context.Context, id ControlID) (_ ActionResult, err error)
- func (p *Page) Eval(ctx context.Context, expression string) (EvalResult, error)
- func (p *Page) Fill(ctx context.Context, id ControlID, text string) (_ ActionResult, err error)
- func (p *Page) Info(ctx context.Context) (PageInfo, error)
- func (p *Page) Navigate(ctx context.Context, address string) error
- func (p *Page) Press(ctx context.Context, key string) (_ ActionResult, err error)
- func (p *Page) Read(ctx context.Context, opts ReadOptions) (ReadResult, error)
- func (p *Page) Select(ctx context.Context, id ControlID, value string) (_ ActionResult, err error)
- type PageID
- type PageInfo
- type PagesResult
- type ReadOptions
- type ReadResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionResult ¶
type ActionResult struct {
Action string `json:"action"`
Page PageInfo `json:"page"`
Target ControlID `json:"target,omitempty"`
NewPages []PageInfo `json:"newPages"`
Warnings []string `json:"warnings,omitempty"`
}
ActionResult reports completed browser input, not application business success. NewPages contains newly observed tabs; it does not change a saved selection.
func (ActionResult) String ¶
func (r ActionResult) String() string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client owns one browser connection. Its methods are safe for concurrent use. Calls on the same page are serialized; other clients are not globally locked.
func Connect ¶
Connect discovers or directly connects to a browser-level endpoint. ctx bounds establishment only. The returned connection lives until Close or failure.
func (*Client) Close ¶
Close releases the connection and waits for its reader. It sends no browser or tab close command. Repeated Close calls are harmless.
func (*Client) Open ¶
Open reuses the sole eligible tab. With zero or multiple eligible tabs it creates a new tab. It waits for the requested document to load.
type ControlID ¶
type ControlID int
ControlID is a page-wide accessibility-tree preorder ordinal, starting at 1. Each input operation resolves it afresh, then binds to that native node.
type Error ¶
Error describes a failure without including endpoint credentials or raw protocol data. Context cancellation and deadlines retain their standard errors. Code distinguishes invalid_input, connection, protocol, overflow, page, ambiguous, navigation, dialog, unavailable, stale, blocked, javascript, and unsupported failures.
type EvalResult ¶
type EvalResult struct {
Type string `json:"type"`
Value json.RawMessage `json:"value,omitempty"`
UnserializableValue string `json:"unserializableValue,omitempty"`
}
EvalResult contains copied JSON or an explicit non-JSON JavaScript value. It contains no connection-scoped remote handle.
func (EvalResult) String ¶
func (r EvalResult) String() string
type Node ¶
type Node struct {
ID ControlID `json:"id,omitempty"`
Role string `json:"role"`
Name string `json:"name,omitempty"`
Text string `json:"text,omitempty"`
Description string `json:"description,omitempty"`
Value *string `json:"value,omitempty"`
URL string `json:"url,omitempty"`
Level int `json:"level,omitempty"`
State map[string]any `json:"state,omitempty"`
Children []*Node `json:"children,omitempty"`
// contains filtered or unexported fields
}
Node is native accessible content. A zero ID denotes context, not a control. State retains explicit false values and native mixed/grammar/spelling tokens.
type Page ¶
type Page struct {
// contains filtered or unexported fields
}
Page is bound to one Client and tab. Multiple Page handles for the same tab share a lock and session. Closing the Client invalidates all of its Pages.
func (*Page) Click ¶
Click resolves the current control ordinal, scrolls its native target and ancestor frames, then hit-tests before one native mouse press/release pair.
func (*Page) Eval ¶
Eval evaluates JavaScript in this page and awaits a returned promise. It does not replay evaluation after a timeout or disconnect. Exceptions are errors.
func (*Page) Fill ¶
Fill replaces text in text-like inputs, textarea, and contenteditable elements with trusted browser input. It does not submit the field or await app timers.
func (*Page) Navigate ¶
Navigate waits for the main-frame load belonging to this navigation, including redirects. It does not wait for network idle or future application timers.
func (*Page) Press ¶
Press sends one key (for example Enter or ArrowDown) or modifier combination (for example Control+A or Shift+Tab) to the tab's focused element.
func (*Page) Read ¶
func (p *Page) Read(ctx context.Context, opts ReadOptions) (ReadResult, error)
Read captures the full native AX hierarchy, including offscreen content.
type PageID ¶
type PageID int
PageID is a current eligible-tab ordinal, starting at 1. Zero selects the sole eligible tab. Ordinals are enumerated afresh, never remembered.
type PagesResult ¶
type PagesResult struct {
Pages []PageInfo `json:"pages"`
}
PagesResult contains eligible tabs in native-target order, numbered from 1.
func (PagesResult) String ¶
func (r PagesResult) String() string
type ReadOptions ¶
ReadOptions filters a page-wide observation without changing control numbers.
type ReadResult ¶
type ReadResult struct {
Page PageInfo `json:"page"`
Complete bool `json:"complete"`
Tree *Node `json:"tree"`
Warnings []string `json:"warnings,omitempty"`
}
ReadResult is one captured value; String performs no browser I/O.
func (ReadResult) String ¶
func (r ReadResult) String() string