cdp

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func Connect(ctx context.Context, endpoint string) (*Client, error)

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

func (c *Client) Close() error

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

func (c *Client) Open(ctx context.Context, address string) (*Page, error)

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.

func (*Client) Page

func (c *Client) Page(ctx context.Context, id PageID) (*Page, error)

Page resolves a current eligible-tab ordinal, or the sole eligible tab for zero. The returned handle stays bound to that native tab even if ordinals change. Negative IDs are invalid; an unavailable explicit ID never falls back.

func (*Client) Pages

func (c *Client) Pages(ctx context.Context) (PagesResult, error)

Pages lists ordinary page targets, excluding browser-internal tabs.

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

type Error struct {
	Code    string
	Message string
}

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.

func (*Error) Error

func (e *Error) Error() string

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

func (p *Page) Click(ctx context.Context, id ControlID) (_ ActionResult, err error)

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

func (p *Page) Eval(ctx context.Context, expression string) (EvalResult, error)

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

func (p *Page) Fill(ctx context.Context, id ControlID, text string) (_ ActionResult, err error)

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) Info

func (p *Page) Info(ctx context.Context) (PageInfo, error)

Info captures the tab's current metadata and checks that it is still eligible.

func (*Page) Navigate

func (p *Page) Navigate(ctx context.Context, address string) error

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

func (p *Page) Press(ctx context.Context, key string) (_ ActionResult, err error)

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.

func (*Page) Select

func (p *Page) Select(ctx context.Context, id ControlID, value string) (_ ActionResult, err error)

Select chooses one native select option by exact value or label. Matches across both fields must be unique. Custom comboboxes use Click/Fill/Press.

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 PageInfo

type PageInfo struct {
	ID    PageID `json:"id"`
	URL   string `json:"url"`
	Title string `json:"title"`
}

PageInfo captures a tab's current ordinal and metadata.

func (PageInfo) String

func (p PageInfo) String() string

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

type ReadOptions struct {
	Selector     string
	ControlsOnly bool
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL