Documentation
¶
Overview ¶
Package host owns the parts of kitty-browse's native control API that every host shares: the typed action bridge, target pinning and the host-managed operations a visible pane and a headless host must perform identically.
Page actions are executed by internal/action exactly once for both hosts, so a headless browser cannot drift from the visible pane's semantics.
Index ¶
- Variables
- func BrowserScopedAction(name string) bool
- func CacheTitle(titles map[*browser.Session]string, sess *browser.Session)
- func CheckViewport(width, height int) error
- func ClientError(code, message string) *action.Error
- func CloseTab(tabs *browser.Tabs, index int) error
- func DisplayedTabID(info action.Info, value string) (string, error)
- func HostManagedAction(name string) bool
- func Navigate(ctx context.Context, sess *browser.Session, name, url string, ...) error
- func NewBrowserID() string
- func NewTab(ctx context.Context, tabs *browser.Tabs, url string, load time.Duration) error
- func PruneTitles(titles map[*browser.Session]string, sessions []*browser.Session)
- func ResolveTabID(info action.Info, req *action.Request) error
- func SelectTab(tabs *browser.Tabs, index int) error
- func SessionFor(tabs *browser.Tabs, target action.TabInfo) (*browser.Session, error)
- func SetViewport(sess *browser.Session, width, height int) error
- func ViewportDocument(width, height int) (json.RawMessage, error)
- type Bridge
- func (b *Bridge) CloseInteraction()
- func (b *Bridge) ContinuationOutcome(req ContinueRequest) string
- func (b *Bridge) ContinueChecked(ctx context.Context, req ContinueRequest) error
- func (b *Bridge) Execute(ctx context.Context, raw json.RawMessage) (json.RawMessage, error)
- func (b *Bridge) ExecuteOperator(ctx context.Context, raw json.RawMessage) (json.RawMessage, error)
- func (b *Bridge) Information(context.Context) (json.RawMessage, error)
- func (b *Bridge) Interaction() InteractionState
- func (b *Bridge) Load() *Snapshot
- func (b *Bridge) ManualTarget(ctx context.Context, requested action.Target, ...) error
- func (b *Bridge) NoteInputConflict()
- func (b *Bridge) ObserveIntervention(ctx context.Context, sess *browser.Session)
- func (b *Bridge) Pause(reason string)
- func (b *Bridge) RecordExplicitSelection(tab action.TabInfo)
- func (b *Bridge) Resume()
- func (b *Bridge) Update(tabs *browser.Tabs, titles map[*browser.Session]string)
- type Call
- type ContinueRequest
- type InteractionState
- type Quit
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
var ( // ResultDone is the "done" action result: action mode ended, browser stays. ResultDone = json.RawMessage(`{"released":true}`) // ResultQuitting is the "quit" action result: the host is shutting down. ResultQuitting = json.RawMessage(`{"quitting":true}`) )
Result documents every host returns unchanged, so a client cannot tell the visible pane from a headless host.
Functions ¶
func BrowserScopedAction ¶
BrowserScopedAction reports whether an action addresses the browser rather than one tab.
func CacheTitle ¶
CacheTitle records one tab's title, bounded so a busy page cannot stall the caller. It is a cache: failures leave the previous title in place.
func CheckViewport ¶
CheckViewport enforces the set.viewport contract for both hosts. The visible pane then renders that size into its cell box; a headless host applies it directly.
func ClientError ¶
ClientError builds the API error the contract uses for rejected requests.
func CloseTab ¶
CloseTab closes one tab by displayed index. The last tab is refused with the contract's last_tab error rather than a generic failure.
func DisplayedTabID ¶
DisplayedTabID resolves the CLI's 1-based displayed tab number to the stable tab ID. Anything that is not a number is already an opaque ID.
func HostManagedAction ¶
HostManagedAction reports whether an action must run on the goroutine that owns the browser's UI state.
func Navigate ¶
func Navigate(ctx context.Context, sess *browser.Session, name, url string, load time.Duration) error
Navigate runs one host-managed navigation action on a session.
func NewBrowserID ¶
func NewBrowserID() string
NewBrowserID returns a fresh opaque browser identity.
func NewTab ¶
NewTab opens url in a new tab and leaves it active. An empty URL opens the same blank page the pane's own new-tab control uses.
func PruneTitles ¶
PruneTitles drops cached titles for sessions that are no longer live. The cache is keyed by session pointer, so a session closed by an external client or a closed popup would otherwise stay in the map, and in the tab-strip document, for as long as the browser lives. Tab sets that reconcile against Chromium call this after every reconcile.
func ResolveTabID ¶
ResolveTabID turns the tabId convenience parameter into the stable target ID before the request is queued. The typed target stays authoritative.
func SessionFor ¶
SessionFor returns the session of a previously advertised target. A tab that closed, or whose target moved to another ID, is rejected instead of acted on.
func SetViewport ¶
SetViewport validates and applies set.viewport dimensions.
func ViewportDocument ¶
func ViewportDocument(width, height int) (json.RawMessage, error)
ViewportDocument is the set.viewport result.
Types ¶
type Bridge ¶
type Bridge struct {
ID string
LoginProfile string // immutable, assigned by the trusted launcher
Calls chan Call
Active atomic.Int64
// InputBlocked counts mutating actions only. Read-only observation may run
// while a person types; it must not cause the pane to discard their keys.
InputBlocked atomic.Int64
// contains filtered or unexported fields
}
Bridge publishes immutable discovery snapshots. Native page operations run outside the host loop; tab/navigation/viewport changes are posted back to that loop, which remains the sole owner of models and screencast selection.
func (*Bridge) CloseInteraction ¶ added in v0.2.12
func (b *Bridge) CloseInteraction()
Closing a view revokes decisions and receipts in the same critical section used by checked recovery. An already accepted request cannot revive it.
func (*Bridge) ContinuationOutcome ¶ added in v0.2.12
func (b *Bridge) ContinuationOutcome(req ContinueRequest) string
func (*Bridge) ContinueChecked ¶ added in v0.2.12
func (b *Bridge) ContinueChecked(ctx context.Context, req ContinueRequest) error
ContinueChecked performs a generation compare-and-swap after mutations drain. It neither sends page input nor replays a rejected action.
func (*Bridge) Execute ¶
func (b *Bridge) Execute(ctx context.Context, raw json.RawMessage) (json.RawMessage, error)
Execute serves /v1/actions.
func (*Bridge) ExecuteOperator ¶ added in v0.2.11
func (b *Bridge) ExecuteOperator(ctx context.Context, raw json.RawMessage) (json.RawMessage, error)
ExecuteOperator is an authenticated embedding seam, never a control-API action. Only bounded browser chrome operations are accepted by its caller.
func (*Bridge) Information ¶
Information serves /v1/info.
func (*Bridge) Interaction ¶ added in v0.2.7
func (b *Bridge) Interaction() InteractionState
func (*Bridge) ManualTarget ¶ added in v0.2.9
func (b *Bridge) ManualTarget(ctx context.Context, requested action.Target, operation func(*browser.Session) error) error
ManualTarget runs an operator-originated operation on a pinned live tab. It is an in-process primitive, not an action or a control-socket endpoint. An embedding application must authenticate the operator and must never expose this function as a general-purpose automation capability.
A pause blocks automatic mutations, not a person's input. The per-target gate prevents a manual operation from interleaving with an automated action on that target; an already-running mutation on another target also blocks it.
func (*Bridge) NoteInputConflict ¶ added in v0.2.7
func (b *Bridge) NoteInputConflict()
func (*Bridge) ObserveIntervention ¶ added in v0.2.7
ObserveIntervention latches a pause; disappearance of the challenge alone never authorizes automatic retries. A person explicitly resumes instead.
func (*Bridge) RecordExplicitSelection ¶ added in v0.2.9
RecordExplicitSelection is called by the host loop only after an explicit control-API tab activation succeeds. Passive or manual selections must not publish it: other surfaces may be intentionally showing a different tab.
type Call ¶
Call is one host-managed action posted to the goroutine that owns the browser's UI state.
type ContinueRequest ¶ added in v0.2.12
type ContinueRequest struct {
BrowserID string `json:"browserId"`
InstanceEpoch string `json:"instanceEpoch"`
PauseGeneration uint64 `json:"pauseGeneration"`
RequestID string `json:"requestId"`
ExpiresAt time.Time `json:"expiresAt"`
}
ContinueRequest is accepted only by the private operator seam. Public automation may observe its generation, but cannot submit a decision.
type InteractionState ¶ added in v0.2.7
type InteractionState struct {
Busy bool `json:"busy"`
Action string `json:"action,omitempty"`
ReadOnly bool `json:"readOnly,omitempty"`
Completed bool `json:"completed,omitempty"`
Paused bool `json:"paused"`
Closed bool `json:"closed,omitempty"`
Reason string `json:"reason,omitempty"`
InputConflict bool `json:"inputConflict,omitempty"`
BrowserID string `json:"browserId"`
InstanceEpoch string `json:"instanceEpoch"`
PauseGeneration uint64 `json:"pauseGeneration"`
PauseSource string `json:"pauseSource,omitempty"`
ResumedGeneration uint64 `json:"resumedGeneration,omitempty"`
ContinuationVersion int `json:"continuationVersion"`
RetryAfterMS int64 `json:"retryAfterMs,omitempty"`
}
InteractionState contains labels only, never selectors, typed text or URLs. It is safe to render in the footer or return with browser metadata.
type Quit ¶
type Quit struct {
// contains filtered or unexported fields
}
Quit is the one-shot shutdown request shared by the /v1/quit endpoint, the typed "quit" action and a host's own context. Request is safe to call from any goroutine and any number of times.