Documentation
¶
Overview ¶
Package session provides shared browser session management for CLI and MCP.
Package session provides shared browser session management for CLI and MCP.
Index ¶
- Constants
- func Clear(path string) error
- func DefaultSessionPath() string
- func Exists(path string) bool
- func Save(path string, info *Info) error
- type Config
- type Info
- type Manager
- func (m *Manager) Close(ctx context.Context) error
- func (m *Manager) Detach() error
- func (m *Manager) IsConnected() bool
- func (m *Manager) LaunchIfNeeded(ctx context.Context) error
- func (m *Manager) Pilot(ctx context.Context) (*w3pilot.Pilot, error)
- func (m *Manager) Refresh(ctx context.Context) error
- func (m *Manager) State() State
- type State
- type Status
Constants ¶
const ( // DefaultSessionDir is the default directory for session files. DefaultSessionDir = ".w3pilot" // DefaultSessionFile is the default session file name. DefaultSessionFile = "session.json" )
Variables ¶
This section is empty.
Functions ¶
func DefaultSessionPath ¶
func DefaultSessionPath() string
DefaultSessionPath returns the default session file path.
Types ¶
type Config ¶
type Config struct {
// Headless runs the browser without a visible window.
Headless bool
// DefaultTimeout for browser operations.
DefaultTimeout time.Duration
// InitScripts are JavaScript files to inject before page scripts.
InitScripts []string
// SessionFile is the path to the session persistence file.
// Defaults to ~/.w3pilot/session.json
SessionFile string
// AutoReconnect attempts to reconnect to an existing session on launch.
AutoReconnect bool
}
Config holds session configuration options.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type Info ¶
type Info struct {
// WebSocketURL is the BiDi WebSocket endpoint for reconnection.
WebSocketURL string `json:"websocket_url,omitempty"`
// ClickerPort is the port clicker is listening on (WebSocket mode).
ClickerPort int `json:"clicker_port,omitempty"`
// CDPPort is the Chrome DevTools Protocol port.
CDPPort int `json:"cdp_port,omitempty"`
// UserDataDir is the Chrome user data directory.
UserDataDir string `json:"user_data_dir,omitempty"`
// Headless indicates if the browser is running in headless mode.
Headless bool `json:"headless"`
// PID is the browser process ID.
PID int `json:"pid,omitempty"`
// ClickerPID is the clicker process ID (WebSocket mode).
ClickerPID int `json:"clicker_pid,omitempty"`
// LaunchedAt is when the session was started.
LaunchedAt time.Time `json:"launched_at"`
// InitScripts are JavaScript files injected before page scripts.
InitScripts []string `json:"init_scripts,omitempty"`
}
Info stores information about a running browser session for persistence.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles browser session lifecycle with optional persistence. It provides lazy launch, reconnection, and graceful shutdown.
func NewManager ¶
NewManager creates a new session manager with the given config.
func (*Manager) Detach ¶
Detach detaches from the browser without closing it. The session info is preserved for later reconnection.
func (*Manager) IsConnected ¶
IsConnected returns true if a browser is connected.
func (*Manager) LaunchIfNeeded ¶
LaunchIfNeeded launches a new browser or reconnects to an existing session.
type State ¶
type State struct {
Status Status `json:"status"`
Info *Info `json:"info,omitempty"`
Pilot *w3pilot.Pilot `json:"-"`
Error error `json:"error,omitempty"`
}
State provides current session state information.
type Status ¶
type Status string
Status represents the current session state.
const ( // StatusDisconnected means no browser is connected. StatusDisconnected Status = "disconnected" // StatusConnected means a browser is connected and ready. StatusConnected Status = "connected" // StatusReconnecting means attempting to reconnect to an existing session. StatusReconnecting Status = "reconnecting" )