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
- Variables
- func CallOnRef(ctx context.Context, tab *browser.Tab, info perceive.RefInfo, fn string, ...) error
- func HideOverlay(ctx context.Context, tab *browser.Tab) (restore func())
- func Locate(ctx context.Context, tab *browser.Tab, info perceive.RefInfo) (activity.Box, error)
- func SetOverlayVisible(ctx context.Context, tab *browser.Tab, visible bool) (bool, error)
- func ValidateUploadPath(home, p string) (string, error)
- type CoveredError
- type Engine
- type Guard
- type Key
- type Probe
- type Result
- type Review
- type SettleOptions
- type SettleResult
- type Step
Constants ¶
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.
const ( ModAlt = 1 ModCtrl = 2 ModMeta = 4 ModShift = 8 )
Modifier bits for CDP input events.
Variables ¶
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.
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.
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 ¶
HideOverlay hides the overlay and returns a func that shows it again (always safe to call).
func Locate ¶
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 ¶
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 ¶
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).
type Guard ¶
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 ¶
CharKey returns the key event that types r (US layout codes; other characters are sent as text only, which Chrome inserts all the same).
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 ¶
func Settle(ctx context.Context, p Probe, o SettleOptions) SettleResult
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.