ipc

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConsoleTypeLog     = "log"
	ConsoleTypeDebug   = "debug"
	ConsoleTypeInfo    = "info"
	ConsoleTypeError   = "error"
	ConsoleTypeWarning = "warning"
)

Console type constants matching CDP Runtime.consoleAPICalled types.

View Source
const MultiElementSeparator = "--"

MultiElementSeparator is the separator string used between multiple elements in text output for observation commands (html, css inline, css computed).

Variables

View Source
var ErrDaemonNotRunning = errors.New("daemon is not running")

ErrDaemonNotRunning is returned when the daemon is not running.

Functions

func DefaultPIDPath

func DefaultPIDPath() string

DefaultPIDPath returns the XDG-compliant PID file path.

func DefaultSocketPath

func DefaultSocketPath() string

DefaultSocketPath returns the XDG-compliant socket path.

func IsDaemonRunning

func IsDaemonRunning() bool

IsDaemonRunning checks if the daemon is running by checking for the socket.

func IsDaemonRunningAt

func IsDaemonRunningAt(socketPath string) bool

IsDaemonRunningAt checks if the daemon is running at the specified socket path.

func NormalizeConsoleType

func NormalizeConsoleType(t string) string

NormalizeConsoleType converts a console type string to its canonical CDP form.

Types

type CSSData

type CSSData struct {
	CSS           string              `json:"css,omitempty"`           // For save/matched actions
	Styles        map[string]string   `json:"styles,omitempty"`        // For computed action (single element, JSON format)
	ComputedMulti []ElementWithStyles `json:"computedMulti,omitempty"` // For computed action (multiple elements with metadata)
	Value         string              `json:"value,omitempty"`         // For get action
	InlineMulti   []ElementWithStyles `json:"inlineMulti,omitempty"`   // For inline action (with metadata)
	Inline        []string            `json:"inline,omitempty"`        // Deprecated: For inline action (style attributes only)
	Matched       []CSSMatchedRule    `json:"matched,omitempty"`       // For matched action
}

CSSData is the response data for the "css" command.

type CSSMatchedRule

type CSSMatchedRule struct {
	Selector   string            `json:"selector"`
	Properties map[string]string `json:"properties"`
	Source     string            `json:"source,omitempty"` // stylesheet URL or "inline"
}

CSSMatchedRule represents a CSS rule matched to an element.

type CSSParams

type CSSParams struct {
	Action   string `json:"action"`             // "save", "computed", "get", "inline", or "matched"
	Selector string `json:"selector,omitempty"` // CSS selector for computed/get/inline/matched
	Property string `json:"property,omitempty"` // CSS property for get action
}

CSSParams represents parameters for the "css" command.

type ClickParams

type ClickParams struct {
	Selector string `json:"selector"`
}

ClickParams represents parameters for the "click" command.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a Unix socket IPC client.

func Dial

func Dial() (*Client, error)

Dial connects to the daemon at the default socket path.

func DialPath

func DialPath(socketPath string) (*Client, error)

DialPath connects to the daemon at the specified socket path.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection.

func (*Client) Send

func (c *Client) Send(req Request) (Response, error)

Send sends a request to the daemon and returns the response.

func (*Client) SendCmd

func (c *Client) SendCmd(cmd string) (Response, error)

SendCmd is a convenience method for sending a simple command.

type CommandExecutor

type CommandExecutor func(args []string) (recognized bool, err error)

CommandExecutor executes CLI commands with arguments. Returns true if the command was recognized, false otherwise. Used by the REPL to execute commands via Cobra.

type ConsoleData

type ConsoleData struct {
	Entries []ConsoleEntry `json:"entries"`
	Count   int            `json:"count"`
}

ConsoleData is the response data for the "console" command.

type ConsoleEntry

type ConsoleEntry struct {
	SessionID string   `json:"sessionId,omitempty"`
	Type      string   `json:"type"`
	Text      string   `json:"text"`
	Args      []string `json:"args,omitempty"`
	Timestamp int64    `json:"timestamp"`
	URL       string   `json:"url,omitempty"`
	Line      int      `json:"line,omitempty"`
	Column    int      `json:"column,omitempty"`
}

ConsoleEntry represents a console log entry.

type Cookie struct {
	Name         string  `json:"name"`
	Value        string  `json:"value"`
	Domain       string  `json:"domain"`
	Path         string  `json:"path"`
	Expires      float64 `json:"expires"`
	Size         int     `json:"size"`
	HTTPOnly     bool    `json:"httpOnly"`
	Secure       bool    `json:"secure"`
	Session      bool    `json:"session"`
	SameSite     string  `json:"sameSite,omitempty"`
	Priority     string  `json:"priority,omitempty"`
	SameParty    bool    `json:"sameParty,omitempty"`
	SourceScheme string  `json:"sourceScheme,omitempty"`
	SourcePort   int     `json:"sourcePort,omitempty"`
}

Cookie represents a browser cookie with all CDP attributes.

type CookiesData

type CookiesData struct {
	Cookies []Cookie `json:"cookies,omitempty"`
	Count   int      `json:"count,omitempty"`
	// For ambiguous delete errors
	Matches []Cookie `json:"matches,omitempty"`
}

CookiesData is the response data for the "cookies" command.

type CookiesParams

type CookiesParams struct {
	Action   string `json:"action"` // "list", "set", or "delete"
	Name     string `json:"name,omitempty"`
	Value    string `json:"value,omitempty"`
	Domain   string `json:"domain,omitempty"`
	Path     string `json:"path,omitempty"`
	Secure   bool   `json:"secure,omitempty"`
	HTTPOnly bool   `json:"httpOnly,omitempty"`
	MaxAge   int    `json:"maxAge,omitempty"`   // seconds
	SameSite string `json:"sameSite,omitempty"` // "Strict", "Lax", or "None"
}

CookiesParams represents parameters for the "cookies" command.

type ElementMeta

type ElementMeta struct {
	Tag   string `json:"tag"`             // lowercase tag name (div, span, svg, etc.)
	ID    string `json:"id,omitempty"`    // id attribute value (sanitized, if present)
	Class string `json:"class,omitempty"` // first class name only (sanitized, if present)
}

ElementMeta contains element identification metadata extracted from DOM elements. The identification follows CSS selector notation for developer familiarity.

Identification Priority:

  1. ID attribute (if present) -> #id
  2. First class name (if present) -> .class:N
  3. Tag name (always present) -> tag:N

Note: Only the first class is captured when an element has multiple classes. Special characters in IDs/classes are sanitized to valid CSS identifier characters.

type ElementWithHTML

type ElementWithHTML struct {
	ElementMeta
	HTML string `json:"html"`
}

ElementWithHTML combines element metadata with HTML

type ElementWithStyles

type ElementWithStyles struct {
	ElementMeta
	Styles map[string]string `json:"styles,omitempty"` // for computed
	Inline string            `json:"inline,omitempty"` // for inline
}

ElementWithStyles combines element metadata with styles

type EvalData

type EvalData struct {
	Value    any  `json:"value,omitempty"`
	HasValue bool `json:"hasValue,omitempty"`
}

EvalData is the response data for the "eval" command.

type EvalParams

type EvalParams struct {
	Expression string `json:"expression"`
	Timeout    int    `json:"timeout,omitempty"` // timeout in seconds
}

EvalParams represents parameters for the "eval" command.

type FocusParams

type FocusParams struct {
	Selector string `json:"selector"`
}

FocusParams represents parameters for the "focus" command.

type HTMLData

type HTMLData struct {
	HTML      string            `json:"html,omitempty"`      // single result or legacy
	HTMLMulti []ElementWithHTML `json:"htmlMulti,omitempty"` // multi-element with metadata
}

HTMLData is the response data for the "html" command.

type HTMLParams

type HTMLParams struct {
	Selector string `json:"selector,omitempty"`
}

HTMLParams represents parameters for the "html" command.

type Handler

type Handler func(req Request) Response

Handler processes IPC requests and returns responses.

type HistoryParams

type HistoryParams struct {
	Wait    bool `json:"wait"`    // wait for page load completion
	Timeout int  `json:"timeout"` // timeout in seconds (when wait=true)
}

HistoryParams represents parameters for the "back" and "forward" commands.

type KeyParams

type KeyParams struct {
	Key   string `json:"key"`
	Ctrl  bool   `json:"ctrl,omitempty"`
	Alt   bool   `json:"alt,omitempty"`
	Shift bool   `json:"shift,omitempty"`
	Meta  bool   `json:"meta,omitempty"`
}

KeyParams represents parameters for the "key" command.

type NavigateData struct {
	URL   string `json:"url"`
	Title string `json:"title"`
}

NavigateData is the response data for the "navigate" command.

type NavigateParams struct {
	URL     string `json:"url"`
	Wait    bool   `json:"wait"`    // wait for page load completion
	Timeout int    `json:"timeout"` // timeout in seconds (when wait=true)
}

NavigateParams represents parameters for the "navigate" command.

type NetworkData

type NetworkData struct {
	Entries []NetworkEntry `json:"entries"`
	Count   int            `json:"count"`
}

NetworkData is the response data for the "network" command.

type NetworkEntry

type NetworkEntry struct {
	SessionID       string            `json:"sessionId,omitempty"`
	RequestID       string            `json:"requestId"`
	URL             string            `json:"url"`
	Method          string            `json:"method"`
	Type            string            `json:"type,omitempty"`
	Status          int               `json:"status,omitempty"`
	StatusText      string            `json:"statusText,omitempty"`
	MimeType        string            `json:"mimeType,omitempty"`
	RequestTime     int64             `json:"requestTime"`
	ResponseTime    int64             `json:"responseTime,omitempty"`
	Duration        float64           `json:"duration,omitempty"`
	Size            int64             `json:"size,omitempty"`
	RequestHeaders  map[string]string `json:"requestHeaders,omitempty"`
	ResponseHeaders map[string]string `json:"responseHeaders,omitempty"`
	Body            string            `json:"body,omitempty"`
	BodyTruncated   bool              `json:"bodyTruncated,omitempty"`
	BodyPath        string            `json:"bodyPath,omitempty"`
	Failed          bool              `json:"failed"`
	Error           string            `json:"error,omitempty"`
}

NetworkEntry represents a network request/response entry.

type PageSession

type PageSession struct {
	ID     string `json:"id"`
	Title  string `json:"title"`
	URL    string `json:"url"`
	Active bool   `json:"active,omitempty"`
	Status int    `json:"status,omitempty"` // HTTP status of last document load
}

PageSession represents an active CDP page session.

type ReadyParams

type ReadyParams struct {
	Timeout     int    `json:"timeout"`     // timeout in seconds
	Selector    string `json:"selector"`    // CSS selector to wait for (optional)
	NetworkIdle bool   `json:"networkIdle"` // wait for network idle
	Eval        string `json:"eval"`        // JavaScript expression to evaluate (optional)
}

ReadyParams represents parameters for the "ready" command.

type ReloadParams

type ReloadParams struct {
	IgnoreCache bool `json:"ignoreCache"`
	Wait        bool `json:"wait"`    // wait for page load completion
	Timeout     int  `json:"timeout"` // timeout in seconds (when wait=true)
}

ReloadParams represents parameters for the "reload" command.

type Request

type Request struct {
	Cmd    string          `json:"cmd"`
	Target string          `json:"target,omitempty"`
	Params json.RawMessage `json:"params,omitempty"`
	Debug  bool            `json:"debug,omitempty"` // Enable debug output for this request
}

Request represents a command sent from the CLI to the daemon.

type Response

type Response struct {
	OK    bool            `json:"ok"`
	Data  json.RawMessage `json:"data,omitempty"`
	Error string          `json:"error,omitempty"`
}

Response represents a response sent from the daemon to the CLI.

func ErrorResponse

func ErrorResponse(msg string) Response

ErrorResponse creates an error response with the given message.

func SuccessResponse

func SuccessResponse(data any) Response

SuccessResponse creates a successful response with the given data.

type ScreenshotData

type ScreenshotData struct {
	Data []byte `json:"data"`
}

ScreenshotData is the response data for the "screenshot" command.

type ScreenshotParams

type ScreenshotParams struct {
	FullPage bool `json:"fullPage"`
}

ScreenshotParams represents parameters for the "screenshot" command.

type ScrollParams

type ScrollParams struct {
	Selector string `json:"selector,omitempty"`
	ToX      int    `json:"toX,omitempty"`
	ToY      int    `json:"toY,omitempty"`
	ByX      int    `json:"byX,omitempty"`
	ByY      int    `json:"byY,omitempty"`
	Mode     string `json:"mode"` // "element", "to", or "by"
}

ScrollParams represents parameters for the "scroll" command.

type SelectParams

type SelectParams struct {
	Selector string `json:"selector"`
	Value    string `json:"value"`
}

SelectParams represents parameters for the "select" command.

type ServeData

type ServeData struct {
	Running bool   `json:"running"`
	Mode    string `json:"mode,omitempty"`
	URL     string `json:"url,omitempty"`
	Port    int    `json:"port,omitempty"`
}

ServeData is the response data for the "serve" command.

type ServeParams

type ServeParams struct {
	Action      string   `json:"action"`                // "start" or "stop"
	Mode        string   `json:"mode,omitempty"`        // "static" or "proxy"
	Directory   string   `json:"directory,omitempty"`   // Directory to serve (static mode)
	ProxyURL    string   `json:"proxyURL,omitempty"`    // Backend URL to proxy (proxy mode)
	Port        int      `json:"port,omitempty"`        // Server port (0 = auto-detect)
	Host        string   `json:"host,omitempty"`        // Bind host ("localhost" or "0.0.0.0")
	WatchPaths  []string `json:"watchPaths,omitempty"`  // Paths to watch for changes
	IgnorePaths []string `json:"ignorePaths,omitempty"` // Glob patterns to ignore
}

ServeParams represents parameters for the "serve" command.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a Unix socket IPC server.

func NewServer

func NewServer(socketPath string, handler Handler) (*Server, error)

NewServer creates a new Unix socket server. The socket file is created at the specified path.

func (*Server) Close

func (s *Server) Close() error

Close stops the server and cleans up resources. Safe to call multiple times concurrently.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve starts accepting connections. Blocks until Close is called.

func (*Server) SocketPath

func (s *Server) SocketPath() string

SocketPath returns the path to the Unix socket.

type StatusData

type StatusData struct {
	Running       bool          `json:"running"`
	PID           int           `json:"pid,omitempty"`
	ActiveSession *PageSession  `json:"activeSession,omitempty"`
	Sessions      []PageSession `json:"sessions,omitempty"`
}

StatusData is the response data for the "status" command.

type TargetData

type TargetData struct {
	ActiveSession string        `json:"activeSession,omitempty"`
	Sessions      []PageSession `json:"sessions"`
}

TargetData is the response data for the "target" command.

type TypeParams

type TypeParams struct {
	Selector string `json:"selector,omitempty"`
	Text     string `json:"text"`
	Key      string `json:"key,omitempty"`
	Clear    bool   `json:"clear,omitempty"`
}

TypeParams represents parameters for the "type" command.

Jump to

Keyboard shortcuts

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