Documentation
¶
Index ¶
- Constants
- func ForwardProxy(ctx context.Context, conn net.Conn, spawner ProcessSpawner, ...) error
- func ReadMessage(r io.Reader) ([]byte, error)
- func SocketDir() (string, error)
- func WriteMessage(w io.Writer, data []byte) error
- type Bridge
- type DefaultDialer
- type Dialer
- type ProcessSpawner
- type ProxyAck
- type Server
- type SocketConnector
- type SocketRelay
Constants ¶
const MaxMessageSize = 1024 * 1024
MaxMessageSize is Chrome's native messaging limit (1 MB).
Variables ¶
This section is empty.
Functions ¶
func ForwardProxy ¶
func ForwardProxy(ctx context.Context, conn net.Conn, spawner ProcessSpawner, logger zerolog.Logger) error
ForwardProxy bridges a TCP connection to a spawned native host process. It performs bidirectional io.Copy: conn→stdin and stdout→conn.
func ReadMessage ¶
ReadMessage reads a Chrome native messaging frame: 4-byte LE length + JSON 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.
type DefaultDialer ¶
type DefaultDialer struct{}
DefaultDialer uses the standard net.Dialer.
func (DefaultDialer) DialContext ¶
DialContext dials using the standard library.
type ProcessSpawner ¶
type ProcessSpawner interface {
Spawn(ctx context.Context) (stdin io.WriteCloser, stdout io.ReadCloser, wait func() error, err error)
}
ProcessSpawner creates a child process for the real Chrome native host.
type Server ¶
type Server struct {
Addr string
Token string
Spawner ProcessSpawner
Logger zerolog.Logger
}
Server listens for chrome-proxy connections on its own TCP port.
type SocketConnector ¶
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 ¶
func (sc *SocketConnector) Spawn(_ context.Context) (io.WriteCloser, io.ReadCloser, func() error, error)
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.