act

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package act performs actions on page elements the way a person would: it scrolls the target into view, waits for its box to stop moving, verifies with a hit test that nothing covers it, lets the pre-action hook run (the Cockpit's ghost cursor), dispatches trusted CDP input, and then waits for the page to settle. Every step is reported on the activity bus.

Index

Constants

View Source
const (
	Click    = "click"
	DblClick = "dblclick"
	Hover    = "hover"
	Type     = "type"
	Clear    = "clear"
	Select   = "select"
	Check    = "check"
	Uncheck  = "uncheck"
	Press    = "press"
	Scroll   = "scroll"
	Drag     = "drag"
	Upload   = "upload"
	// Set fills a form field the way its kind needs: types into text fields, picks an option
	// of a select, checks or unchecks a checkbox/radio/switch ("true"/"false").
	Set = "set"
)

Actions accepted by Run.

View Source
const (
	ModAlt   = 1
	ModCtrl  = 2
	ModMeta  = 4
	ModShift = 8
)

Modifier bits for CDP input events.

Variables

View Source
var ErrCockpitFocused = errors.New("the keyboard focus is on the Daisybell card the human answers in the page; no key was sent. Wait for the human to answer, or press with ref= to focus a page element")

ErrCockpitFocused: the keyboard focus is on the Cockpit's own UI in the page (an approval or question card). Keys sent there could answer the human's card for them, so none are sent.

View Source
var ErrGone = errors.New("element is gone (the page re-rendered or navigated); call snapshot for current refs")

ErrGone means the ref's element no longer exists.

View Source
var ErrNotSecret = errors.New("not a password, code or card field")

ErrNotSecret: a replayed secret step resolved to a field that isn't a credential field. Typing its (empty) value would silently clear whatever field the flow healed onto.

Functions

func CallOnRef

func CallOnRef(ctx context.Context, tab *browser.Tab, info perceive.RefInfo, fn string, out any) error

call runs fn on the node and decodes its JSON result into out (may be nil). CallOnRef runs fn on a ref's element and decodes its result into out. It resolves the element like actions do: in its own frame's session, in the isolated world when it can (page scripts can't see or tamper with the call), falling back to the default world for same-process child frames. ErrGone when the element no longer exists.

func HideOverlay

func HideOverlay(ctx context.Context, tab *browser.Tab) (restore func())

HideOverlay hides the overlay and returns a func that shows it again (always safe to call).

func Locate

func Locate(ctx context.Context, tab *browser.Tab, info perceive.RefInfo) (activity.Box, error)

Locate scrolls a ref's element into view and returns its visible box in top-level viewport CSS pixels (used for element screenshots and by observers).

func SetOverlayVisible

func SetOverlayVisible(ctx context.Context, tab *browser.Tab, visible bool) (bool, error)

SetOverlayVisible shows or hides the Cockpit overlay of the tab's top document, from Daisybell's isolated world (the page sees at most an attribute flip). It reports whether the tab has an overlay. Used around the AI's screenshots and around input aimed under the pill.

func ValidateUploadPath

func ValidateUploadPath(home, p string) (string, error)

ValidateUploadPath accepts only an existing regular file inside home (after resolving symlinks and "~"), so a page or a confused agent cannot exfiltrate system files. It returns the cleaned absolute path.

Types

type CoveredError

type CoveredError struct {
	By  string // div#cookie-banner "We use cookies"
	Ref string // ref of the covering element, when it has one
	At  point
	// contains filtered or unexported fields
}

CoveredError reports that another element would receive the pointer event.

func (*CoveredError) Error

func (e *CoveredError) Error() string

type Engine

type Engine struct {
	Bus    activity.Bus
	Hook   activity.PreActionHook
	Settle SettleOptions
	Log    *slog.Logger
	// Downloads reports downloads in progress (nil means none).
	Downloads func() int
	// Guard reviews risky actions and credential fields before input (nil: the engine still
	// refuses to type into credential fields).
	Guard Guard
}

Engine runs actions. The zero value works (no bus, no hook, default settle options).

func (*Engine) Run

func (e *Engine) Run(ctx context.Context, st Step) (Result, error)

Run performs the step.

func (*Engine) SettleDOM

func (e *Engine) SettleDOM(ctx context.Context, tab *browser.Tab) SettleResult

SettleDOM waits only for the DOM to go quiet (bounded by DOMCap): for a parsed document whose subresources (images, ads) are still loading, where waiting on the network would only add a warning.

func (*Engine) SettleTab

func (e *Engine) SettleTab(ctx context.Context, tab *browser.Tab) SettleResult

SettleTab waits for the tab to settle with the engine's options.

type Guard

type Guard interface {
	Review(ctx context.Context, r *Review) error
}

Guard reviews an action right before its input fires (SPEC invariants 6 and 7): after the pre-action hook (the ghost cursor is on the target, so an approval card can point at it) and before any trusted input. It may block while it asks the human. Returning an error stops the action; it may also change r.Value (the human edited the value to type).

type Key

type Key struct {
	Key  string // DOM key value: "Enter", "a", "ArrowDown"
	Code string // DOM code: "Enter", "KeyA", "ArrowDown"
	VK   int64  // Windows virtual key code
	Text string // text inserted by the key (empty for non-printing keys)
}

Key is one key press as CDP Input.dispatchKeyEvent needs it.

func CharKey

func CharKey(r rune) Key

CharKey returns the key event that types r (US layout codes; other characters are sent as text only, which Chrome inserts all the same).

func KeyFor

func KeyFor(name string) (Key, error)

KeyFor returns the key for a name ("Enter", "ArrowDown") or a single character.

func ParseCombo

func ParseCombo(s string) (Key, int64, error)

ParseCombo parses "Enter", "Control+a", "Shift+Tab", "Meta+Shift+K".

type Probe

type Probe interface {
	// Busy is the number of requests keeping the page busy (long-polls, sockets and analytics
	// excluded) and how long the network has been idle.
	Busy() (pending int, idle time.Duration)
	// Loading reports whether the main frame is loading a document.
	Loading() bool
	// DOMQuiet is how long the DOM has not changed. An error (e.g. the document is being
	// replaced) counts as "still changing".
	DOMQuiet(ctx context.Context) (time.Duration, error)
	// Blocked reports a JavaScript dialog: the page cannot change until it is answered.
	Blocked() bool
	// Downloads is the number of downloads still in progress.
	Downloads() int
}

Probe reports the page signals the settle engine waits on.

type Result

type Result struct {
	// Line is the one-line result: `clicked button "Save"`.
	Line   string
	Settle SettleResult
	// Value is the value that was used: the step's, or the one the human edited in the approval.
	Value string
}

Result is the outcome of a step.

type Review

type Review struct {
	// Event is the "before" event (target box and point when known).
	Event activity.Event
	// Action is the guard's view of the action; Verb the engine's (click, type, press...).
	Action guard.Action
	Verb   string
	// Value is the value about to be typed (or the key pressed).
	Value  string
	Target guard.Target
	Ref    string
	Tab    *browser.Tab
}

Review is what the guard sees of an action.

type SettleOptions

type SettleOptions struct {
	// Min is waited at least, so effects scheduled right after the input (fetch in a click
	// handler, navigation) have started before we look.
	Min time.Duration
	// NetQuiet and DOMQuiet are the required quiet periods.
	NetQuiet, DOMQuiet time.Duration
	// Cap bounds the wait; Settle then returns Settled=false rather than an error.
	Cap time.Duration
	// DOMCap is the shorter bound when only the DOM keeps changing (tickers, live counters):
	// the network is idle, so waiting longer rarely helps.
	DOMCap time.Duration
	Poll   time.Duration
}

SettleOptions tunes Settle. Zero values take the defaults.

type SettleResult

type SettleResult struct {
	Settled bool
	Waited  time.Duration
	// Reason is what was still going on at the cap ("2 requests pending").
	Reason string
}

SettleResult tells whether the page settled and, if not, why.

func Settle

Settle waits until the network and the DOM are quiet, no document is loading and no download is running — or until the cap.

func (SettleResult) Warning

func (r SettleResult) Warning() string

Warning is the line to show the model when the page did not settle.

type Step

type Step struct {
	Tab    *browser.Tab
	Kind   activity.Kind
	Action string
	// Target is nil for page-level actions (press or scroll without a ref).
	Target *perceive.RefInfo
	// Dest is the drop target of a drag.
	Dest  *perceive.RefInfo
	Value string
	Why   string
	// RefOf names covering elements in error messages.
	RefOf func(perceive.NodeKey) (string, bool)
	// NoSettle skips the settle wait (fill settles once at the end).
	NoSettle bool
	// Secret: the step was a credential the human typed (a flow replay). The element must be a
	// credential field, which hands off; anything else fails with ErrNotSecret before input.
	Secret bool
}

Step is one action.

Jump to

Keyboard shortcuts

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