Documentation
¶
Index ¶
- Constants
- func IsStdinTTY() bool
- type Config
- type Daemon
- type Navigation
- type REPL
- type ReadyCallback
- type RingBuffer
- type SessionManager
- func (m *SessionManager) Active() *ipc.PageSession
- func (m *SessionManager) ActiveID() string
- func (m *SessionManager) Add(sessionID, targetID, url, title string)
- func (m *SessionManager) All() []ipc.PageSession
- func (m *SessionManager) ClaimNetworkEnable(sessionID string) (first bool)
- func (m *SessionManager) Clear()
- func (m *SessionManager) ClearNetworkEnabled(sessionID string)
- func (m *SessionManager) Count() int
- func (m *SessionManager) FindByQuery(query string) []ipc.PageSession
- func (m *SessionManager) Get(sessionID string) *ipc.PageSession
- func (m *SessionManager) GetByTargetID(targetID string) *ipc.PageSession
- func (m *SessionManager) NetworkEnabled(sessionID string) bool
- func (m *SessionManager) Remove(sessionID string) (newActiveID string, activeChanged bool)
- func (m *SessionManager) SetActive(sessionID string) bool
- func (m *SessionManager) TargetID(sessionID string) string
- func (m *SessionManager) Update(sessionID, url, title string)
- func (m *SessionManager) UpdateByTargetID(targetID, url, title string)
- type SessionProvider
Constants ¶
const DefaultBufferSize = 10000
DefaultBufferSize is the default capacity for event buffers.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Headless bool
Port int
// UserDataDir is the resolved browser profile selection, passed straight to
// browser.LaunchOptions. The CLI owns mode resolution; the daemon only
// carries the value. Empty means a throwaway temp profile, the
// browser.UserDataDirDefault sentinel means the user's system Chrome
// profile, and any other value is a concrete persistent directory.
UserDataDir string
SocketPath string
PIDPath string
BufferSize int
Debug bool
// CommandExecutor is called by REPL for CLI command execution with flags.
// If nil, REPL falls back to basic IPC-only execution.
CommandExecutor ipc.CommandExecutor
// ReadyCallback, if non-nil, is invoked once from Run when the daemon
// reaches operational readiness (IPC serving). Mirrors CommandExecutor in
// being optional and nil-safe: a caller that leaves it unset is unaffected.
ReadyCallback ReadyCallback
}
Config holds daemon configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default daemon configuration.
type Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
Daemon is the persistent webctl daemon process.
type Navigation ¶
type Navigation struct {
// contains filtered or unexported fields
}
Navigation represents one in-flight or just-completed navigation for a session.
Each milestone is a broadcast: a channel closed exactly once when the milestone is reached. Awaiting an already-reached milestone returns immediately and any number of waiters observe it, so "the event already happened" and "I am waiting for it" collapse into a single receive. Mark operations are idempotent and safe under concurrent calls, which removes the use-after-close hazard by construction.
func (*Navigation) CancelReason ¶
func (n *Navigation) CancelReason() cancelReason
CancelReason returns why the navigation was cancelled. Call only after the Cancelled milestone has closed.
func (*Navigation) Cancelled ¶
func (n *Navigation) Cancelled() <-chan struct{}
Cancelled returns the Cancelled milestone, closed when this navigation is superseded or its session detaches. CancelReason is readable once it closes.
func (*Navigation) DOMReady ¶
func (n *Navigation) DOMReady() <-chan struct{}
DOMReady returns the DOM-ready milestone, closed on Page.domContentEventFired or Page.loadEventFired (load implies DOM-ready).
func (*Navigation) FrameNavigated ¶
func (n *Navigation) FrameNavigated() <-chan struct{}
FrameNavigated returns the FrameNavigated milestone, closed on a main-frame Page.frameNavigated.
func (*Navigation) Loaded ¶
func (n *Navigation) Loaded() <-chan struct{}
Loaded returns the Loaded milestone, closed on Page.loadEventFired.
type REPL ¶
type REPL struct {
// contains filtered or unexported fields
}
REPL provides an interactive command interface for the daemon.
func NewREPL ¶
func NewREPL(handler ipc.Handler, cmdExec ipc.CommandExecutor, shutdown func()) *REPL
NewREPL creates a new REPL with the given handler, command executor, and shutdown callback. The cmdExec function executes CLI commands with full flag support. If cmdExec is nil, REPL falls back to basic IPC-only command execution.
func (*REPL) Close ¶
Close closes the readline instance if it exists. Safe to call multiple times (idempotent). Returns the error from the first close attempt on all subsequent calls.
func (*REPL) SetSessionProvider ¶
func (r *REPL) SetSessionProvider(sp SessionProvider)
SetSessionProvider sets the session provider for dynamic prompt generation.
type ReadyCallback ¶
type ReadyCallback func(port int)
ReadyCallback is invoked once from Run the moment the daemon is serving IPC: the browser is launched, CDP is connected, and the IPC socket is accepting commands. port is the CDP port actually bound, which may differ from the requested port when auto-selection is used. It fires before any terminal-mode change, so readiness output is identical whether or not stdin is a TTY.
type RingBuffer ¶
type RingBuffer[T any] struct { // contains filtered or unexported fields }
RingBuffer is a thread-safe circular buffer with fixed capacity. When the buffer is full, new items overwrite the oldest items.
func NewRingBuffer ¶
func NewRingBuffer[T any](capacity int, stamp func(*T, uint64)) *RingBuffer[T]
NewRingBuffer creates a new ring buffer with the specified capacity. stamp, if non-nil, is invoked under the write lock in Push to record each entry's assigned sequence number; pass nil for element types without a seq field.
func (*RingBuffer[T]) All ¶
func (b *RingBuffer[T]) All() []T
All returns all items in the buffer, oldest first. Allocates a new slice on each call. This is acceptable for the current request-response IPC pattern where each query is a discrete operation.
func (*RingBuffer[T]) Clear ¶
func (b *RingBuffer[T]) Clear()
Clear removes all items from the buffer.
func (*RingBuffer[T]) Len ¶
func (b *RingBuffer[T]) Len() int
Len returns the current number of items in the buffer.
func (*RingBuffer[T]) Push ¶
func (b *RingBuffer[T]) Push(item T)
Push adds an item to the buffer. If the buffer is full, the oldest item is overwritten.
func (*RingBuffer[T]) RemoveIf ¶
func (b *RingBuffer[T]) RemoveIf(fn func(*T) bool)
RemoveIf removes all items for which fn returns true. Items are compacted in-place, maintaining order.
func (*RingBuffer[T]) Update ¶
func (b *RingBuffer[T]) Update(fn func(*T) bool)
Update iterates through buffer items from newest to oldest, calling fn with a pointer to each item. Iteration stops when fn returns true. This allows in-place modification of buffer entries.
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager tracks CDP page sessions and the tab attach/detach rendezvous.
func NewSessionManager ¶
func NewSessionManager() *SessionManager
NewSessionManager creates a new session manager.
func (*SessionManager) Active ¶
func (m *SessionManager) Active() *ipc.PageSession
Active returns the active session info, or nil if none.
func (*SessionManager) ActiveID ¶
func (m *SessionManager) ActiveID() string
ActiveID returns the current active session ID (empty if none).
func (*SessionManager) Add ¶
func (m *SessionManager) Add(sessionID, targetID, url, title string)
Add adds a new session. If it's the first session, it becomes active.
func (*SessionManager) All ¶
func (m *SessionManager) All() []ipc.PageSession
All returns all sessions as IPC PageSession list.
func (*SessionManager) ClaimNetworkEnable ¶
func (m *SessionManager) ClaimNetworkEnable(sessionID string) (first bool)
ClaimNetworkEnable marks the session's Network domain as enabled if it was not already, returning true only for the caller that wins the claim. The winner performs Network.enable outside the lock and, on failure, calls ClearNetworkEnabled so a later caller can retry. Returns false if the session is unknown.
func (*SessionManager) Clear ¶
func (m *SessionManager) Clear()
Clear removes all sessions and resets the manager state. Used when browser connection is lost.
func (*SessionManager) ClearNetworkEnabled ¶
func (m *SessionManager) ClearNetworkEnabled(sessionID string)
ClearNetworkEnabled clears the session's Network-enabled flag so a failed enable can be retried.
func (*SessionManager) Count ¶
func (m *SessionManager) Count() int
Count returns the number of sessions.
func (*SessionManager) FindByQuery ¶
func (m *SessionManager) FindByQuery(query string) []ipc.PageSession
FindByQuery searches for sessions matching the query. Query is matched against session ID prefix (case-sensitive) or title substring (case-insensitive). Returns matching sessions.
func (*SessionManager) Get ¶
func (m *SessionManager) Get(sessionID string) *ipc.PageSession
Get returns a session by ID, or nil if not found.
func (*SessionManager) GetByTargetID ¶
func (m *SessionManager) GetByTargetID(targetID string) *ipc.PageSession
GetByTargetID returns the session matching the given targetID, or nil if not found.
func (*SessionManager) NetworkEnabled ¶
func (m *SessionManager) NetworkEnabled(sessionID string) bool
NetworkEnabled reports whether Network.enable succeeded for the session.
func (*SessionManager) Remove ¶
func (m *SessionManager) Remove(sessionID string) (newActiveID string, activeChanged bool)
Remove removes a session. If it was active, switches to most recent remaining. Returns the new active session ID (empty if none remain) and true if active changed.
func (*SessionManager) SetActive ¶
func (m *SessionManager) SetActive(sessionID string) bool
SetActive sets the active session by ID. Returns false if the session doesn't exist.
func (*SessionManager) TargetID ¶
func (m *SessionManager) TargetID(sessionID string) string
TargetID returns the targetID for the given sessionID, or empty string if not found.
func (*SessionManager) Update ¶
func (m *SessionManager) Update(sessionID, url, title string)
Update updates a session's URL and title by session ID.
func (*SessionManager) UpdateByTargetID ¶
func (m *SessionManager) UpdateByTargetID(targetID, url, title string)
UpdateByTargetID updates a session's URL and title by target ID.
type SessionProvider ¶
type SessionProvider func() (active *ipc.PageSession, count int)
SessionProvider returns the active session info and total count.