daemon

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package daemon runs a background process that holds one CDP connection and serves Browser calls over a Unix socket. Keeping a single long-lived connection means Chrome's "Allow debugging?" prompt fires once per session (not once per command) and each command is a fast socket round-trip.

Protocol: one JSON request/response per connection (NDJSON), where a request names a Browser method and carries its positional args as JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Remote

func Remote(c *Client) chrome.Browser

Remote returns a chrome.Browser backed by the given daemon Client.

func RunDaemon

func RunDaemon(sockPath string, opts chrome.Options, idle time.Duration) error

RunDaemon connects Chrome and serves sockPath until idle or stopped. Used by the hidden `__daemon` invocation.

func Serve

func Serve(ln net.Listener, b chrome.Browser, idle time.Duration)

Serve accepts connections on ln and dispatches each to b until an idle period of `idle` elapses or a stop request arrives.

func SocketPath

func SocketPath(key string) string

SocketPath returns the daemon socket path for an endpoint key, under the XDG runtime/state dir. Liveness is discovered by connecting (no PID file).

Types

type Client

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

Client talks to a running daemon over its Unix socket (one connection per call).

func Ensure

func Ensure(sockPath, exePath string, env []string) (*Client, error)

Ensure connects to a running daemon, or spawns one (detached) and waits for it to come up. env carries the connection options (CHROME_CDP_*) for the daemon.

func TryConnect

func TryConnect(sockPath string) *Client

TryConnect returns a Client if a daemon is already listening on sockPath.

func (*Client) Status

func (c *Client) Status() error

Status pings the daemon; nil error means it's alive.

func (*Client) StatusInfo

func (c *Client) StatusInfo() (map[string]any, error)

StatusInfo returns the daemon's status payload: {connected, targets}.

func (*Client) Stop

func (c *Client) Stop() error

Stop asks the daemon to shut down.

type Request

type Request struct {
	Method    string            `json:"method"`
	Args      []json.RawMessage `json:"args,omitempty"`
	TimeoutMs int64             `json:"timeout_ms,omitempty"`
}

Request is a Browser method call. Args are the positional arguments (after ctx) as JSON. TimeoutMs carries the client's remaining deadline so the daemon bounds the action instead of running (and blocking the client) forever.

type Response

type Response struct {
	Result json.RawMessage `json:"result,omitempty"`
	Error  string          `json:"error,omitempty"`
}

Response is the method result (or an error string).

Jump to

Keyboard shortcuts

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