chrome

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const MaxMessageSize = 1024 * 1024

MaxMessageSize is Chrome's native messaging limit (1 MB).

Variables

This section is empty.

Functions

func ReadMessage

func ReadMessage(r io.Reader) ([]byte, error)

ReadMessage reads a Chrome native messaging frame: 4-byte LE length + JSON payload.

func SocketDir

func SocketDir() (string, error)

SocketDir returns the directory where Chrome MCP bridge sockets are created. It follows the same convention as the Claude MCP browser bridge: /tmp/claude-mcp-browser-bridge-<username>/

func WriteMessage

func WriteMessage(w io.Writer, data []byte) error

WriteMessage writes a Chrome native messaging frame: 4-byte LE length + payload.

Types

type Bridge

type Bridge struct {
	Dialer  Dialer
	Addr    string // HUMAN_CHROME_ADDR (TCP address of daemon's chrome proxy)
	Token   string
	Version string
	Logger  zerolog.Logger
}

Bridge creates a fake Unix socket inside a container and tunnels traffic over TCP to the daemon on the host, which connects to the real Chrome native messaging socket.

func (*Bridge) ListenAndServe

func (b *Bridge) ListenAndServe(ctx context.Context) error

ListenAndServe creates a Unix socket in SocketDir() and accepts connections, tunneling each to the daemon's chrome proxy server over TCP.

type DefaultDialer

type DefaultDialer struct{}

DefaultDialer uses the standard net.Dialer.

func (DefaultDialer) DialContext

func (DefaultDialer) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

DialContext dials using the standard library.

type Dialer

type Dialer interface {
	DialContext(ctx context.Context, network, addr string) (net.Conn, error)
}

Dialer abstracts TCP connection creation for testability.

type McpTranslator added in v0.11.0

type McpTranslator struct {
	// ClaudePath is the absolute path to the claude binary.
	ClaudePath string
	Logger     zerolog.Logger
}

McpTranslator bridges a net.Conn speaking the native host socket protocol (4-byte LE framing) to a claude --claude-in-chrome-mcp subprocess speaking JSON-RPC over stdio. It translates only the envelope — payloads are opaque.

func (*McpTranslator) Serve added in v0.11.0

func (t *McpTranslator) Serve(ctx context.Context, conn net.Conn) error

Serve handles one bridge connection. It spawns a fresh MCP subprocess, performs the JSON-RPC init handshake, then runs the bidirectional translation loop until conn closes or the subprocess exits.

type ProxyAck

type ProxyAck struct {
	OK    bool   `json:"ok"`
	Error string `json:"error,omitempty"`
}

ProxyAck is sent by the chrome proxy server to acknowledge a connection request.

type Server

type Server struct {
	Addr       string
	Token      string
	Translator *McpTranslator
	Logger     zerolog.Logger
}

Server listens for chrome-proxy connections on its own TCP port.

func (*Server) ListenAndServe

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

ListenAndServe starts the TCP listener and blocks until ctx is cancelled.

type SocketConnector

type SocketConnector struct {
	SocketDir string
	Logger    zerolog.Logger
}

SocketConnector implements ProcessSpawner by connecting to a Unix socket in the socket directory. It is used by the daemon to connect to the Chrome native messaging bridge socket created by the bridge command.

func (*SocketConnector) Spawn

Spawn connects to the first reachable .sock file in SocketDir.

type SocketRelay

type SocketRelay struct {
	SocketDir string
	Logger    zerolog.Logger
	// contains filtered or unexported fields
}

SocketRelay implements ProcessSpawner by creating a Unix socket and accepting connections from Chrome's native messaging host. When Spawn is called (by ForwardProxy via chrome.Server), it dequeues a waiting Chrome connection and returns it as stdin/stdout, pairing it with the bridge connection.

func NewSocketRelay

func NewSocketRelay(socketDir string, logger zerolog.Logger) *SocketRelay

NewSocketRelay creates a SocketRelay with a buffered pending channel.

func (*SocketRelay) ListenAndServe

func (r *SocketRelay) ListenAndServe(ctx context.Context) error

ListenAndServe creates a Unix socket in SocketDir and accepts connections, queuing them in the pending channel. It blocks until ctx is cancelled.

func (*SocketRelay) Spawn

func (r *SocketRelay) Spawn(ctx context.Context) (io.WriteCloser, io.ReadCloser, func() error, error)

Spawn implements ProcessSpawner. It blocks until a Chrome native messaging connection is available (or ctx is cancelled) and returns it as stdin/stdout.

Jump to

Keyboard shortcuts

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