@burdenoff/ui-engine 2026.1127.2 → 2026.1127.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +74 -4
  2. package/dist/capture.js +3 -2
  3. package/dist/dom-runtime/actions.d.ts +65 -0
  4. package/dist/dom-runtime/iife.d.ts +1 -0
  5. package/dist/dom-runtime/index.d.ts +7 -0
  6. package/dist/dom-runtime/runtime.d.ts +79 -0
  7. package/dist/dom-runtime.d.ts +2 -0
  8. package/dist/dom-runtime.iife.js +1 -0
  9. package/dist/dom-runtime.js +30 -0
  10. package/dist/drivers/dom-driver.d.ts +44 -0
  11. package/dist/drivers/index.d.ts +7 -0
  12. package/dist/drivers/snapshot-driver.d.ts +59 -0
  13. package/dist/drivers.d.ts +2 -0
  14. package/dist/drivers.js +170 -0
  15. package/dist/{index-n5amgh31.js → index-2kgsgn1c.js} +1 -1
  16. package/dist/index-3f1j8386.js +334 -0
  17. package/dist/index-3jymbm5t.js +315 -0
  18. package/dist/index-5k26keah.js +815 -0
  19. package/dist/index-77pcz6n3.js +303 -0
  20. package/dist/index-895kscx3.js +741 -0
  21. package/dist/{index-phd8yhyg.js → index-bnvmt4wf.js} +7 -5
  22. package/dist/{index-c6pmt2rg.js → index-cs6acyjn.js} +6 -59
  23. package/dist/index-ct2xctrq.js +229 -0
  24. package/dist/index-h88y5qgv.js +400 -0
  25. package/dist/index-mgztm37r.js +57 -0
  26. package/dist/{index-tqffkt91.js → index-pm13mvvc.js} +26 -1009
  27. package/dist/index-vg8r40y7.js +220 -0
  28. package/dist/index-ycs2bz1a.js +589 -0
  29. package/dist/index-zzhysbkj.js +1731 -0
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.js +130 -42
  32. package/dist/interpret/compile.d.ts +58 -0
  33. package/dist/interpret/driver.d.ts +171 -0
  34. package/dist/interpret/errors.d.ts +194 -0
  35. package/dist/interpret/events.d.ts +73 -0
  36. package/dist/interpret/expr.d.ts +35 -0
  37. package/dist/interpret/index.d.ts +13 -0
  38. package/dist/interpret/run.d.ts +77 -0
  39. package/dist/interpret.d.ts +2 -0
  40. package/dist/interpret.js +84 -0
  41. package/dist/recording.js +1 -1
  42. package/dist/replay.js +2 -2
  43. package/dist/script/adapters/browser-action-contract.d.ts +5 -2
  44. package/dist/script/limits.d.ts +2 -0
  45. package/dist/script.js +44 -38
  46. package/dist/target/aria.d.ts +31 -0
  47. package/dist/target/dom.d.ts +35 -0
  48. package/dist/target/index.d.ts +13 -0
  49. package/dist/target/markers.d.ts +18 -0
  50. package/dist/target/methods.d.ts +52 -0
  51. package/dist/target/resolve.d.ts +63 -0
  52. package/dist/target/snapshot.d.ts +57 -0
  53. package/dist/target/text.d.ts +23 -0
  54. package/dist/target/types.d.ts +88 -0
  55. package/dist/target.d.ts +2 -0
  56. package/dist/target.js +96 -0
  57. package/dist/testing/fake-web-driver.d.ts +28 -0
  58. package/dist/testing/fixtures/ambiguous.d.ts +7 -0
  59. package/dist/testing/fixtures/iframe.d.ts +6 -0
  60. package/dist/testing/fixtures/index.d.ts +26 -0
  61. package/dist/testing/fixtures/invoices-v2.d.ts +8 -0
  62. package/dist/testing/fixtures/invoices-v3.d.ts +7 -0
  63. package/dist/testing/fixtures/invoices.d.ts +6 -0
  64. package/dist/testing/fixtures/login.d.ts +6 -0
  65. package/dist/testing/fixtures/shadow.d.ts +7 -0
  66. package/dist/testing/index.d.ts +7 -0
  67. package/dist/testing/mount.d.ts +18 -0
  68. package/dist/testing.d.ts +2 -0
  69. package/dist/testing.js +379 -0
  70. package/package.json +29 -5
package/README.md CHANGED
@@ -14,7 +14,7 @@ bun add @burdenoff/ui-engine zod
14
14
 
15
15
  ## Modules
16
16
 
17
- Each module is a subpath export, and the root entry re-exports all of them.
17
+ Each module is a subpath export. The root entry re-exports the data and planning modules (`recording` to `script`, and `interpret`); the DOM modules (`target`, `dom-runtime`, `drivers`, `testing`) are subpath-only, so a consumer without DOM types, such as a service, never loads them through the root.
18
18
 
19
19
  | Import | What it holds |
20
20
  |---|---|
@@ -24,6 +24,12 @@ Each module is a subpath export, and the root entry re-exports all of them.
24
24
  | `@burdenoff/ui-engine/replay` | The pure replay planner: `replayStateFrom`, `planReplay`, `afterReplayCall`, `finishFallback`, `markFallbackAsked`, `replayReasons`, `readReplayState` |
25
25
  | `@burdenoff/ui-engine/script` | UI script v1: types, `uiScriptSchema`, `parseUiScript`, `UI_SCRIPT_SCHEMA_HASH`, `requiredCapabilities`, the adapters and `describeStep` (see below) |
26
26
  | `@burdenoff/ui-engine/schema/ui-script-v1.schema.json` | The JSON Schema (draft 2020-12) of UI script v1 |
27
+ | `@burdenoff/ui-engine/target` | The multi-method web target resolver (`resolveWebTarget`, and `resolveAllWebTargets` for reads of every match), accessible role and name helpers, and value-free tree snapshots (`serializeTreeSnapshot`, `hydrateTreeSnapshot`) |
28
+ | `@burdenoff/ui-engine/dom-runtime` | The DOM runtime a desk injects into a page (`createDomRuntime`, `installDomRuntime`): resolve, act, highlight, snapshot |
29
+ | `@burdenoff/ui-engine/dom-runtime.iife.js` | The same runtime as one self-contained script (at most 60 KB minified) that installs itself on `globalThis.__burdenoffUiRuntime` |
30
+ | `@burdenoff/ui-engine/interpret` | The UI script interpreter (`runUiScript`), the compiler a worker runs before it parks a node (`compileUiScript`, `applyPins`, `inlineCalls`, `stripBreakpoints`), the expression evaluator, the desk driver interface and every run-time error code with its node error family (`UI_ERROR_CODES`) |
31
+ | `@burdenoff/ui-engine/drivers` | Desk drivers over a DOM: `createDomDriver` (the DOM runtime in the interpreter's own world) and `createSnapshotDriver` with `replayUiScriptOnSnapshot` (snapshot replay with no browser) |
32
+ | `@burdenoff/ui-engine/testing` | Copies of the RPA playground fixture pages (`RPA_FIXTURES`), `mountFixture` for test DOMs, and `createFakeWebDriver`, a fake web desk over them |
27
33
 
28
34
  ## UI script v1
29
35
 
@@ -53,11 +59,75 @@ A UI script is the portable form of a UI sequence that a desk runs: a paired bro
53
59
  |---|---|---|
54
60
  | `fromRecording`, `toRecording` | Stewards saved-step recording v1 | Lossless both ways, fingerprints included; `toRecording` returns null for a script a recording cannot express |
55
61
  | `fromBrowserActionSteps` | Run in Browser steps (`internal:browser-action`) | Keeps every field a 0.3.0 extension reads |
56
- | `toBrowserActionSteps` | Lowering to Run in Browser steps | Null unless the script fits the legacy contract: at most 100 steps and 256 KB, only the 14 legacy actions, one CSS selector per target (or one text for click and wait), literal or supplied input values, no script wait or screenshot settings beyond the defaults, and no flow steps, verification, retries or breakpoints |
62
+ | `toBrowserActionSteps` | Lowering to Run in Browser steps | Null unless the script fits the legacy contract: at most 100 steps and 256 KB, only the 14 legacy actions, one CSS selector per target (or one text for click and wait), step waits of at most 60 s (the legacy extension's cap), literal or supplied input values, no script wait or screenshot settings beyond the defaults, and no flow steps, verification, retries or breakpoints |
57
63
  | `fromRemoteBrowserSteps` | Remote Browser `runSteps` (`store/remotebrowser` 1.0.0) | Playwright `css=`, `text=`, `xpath=`, `id=` and `data-testid=` selectors; other engines are refused |
58
64
 
59
65
  **Descriptions.** `describeStep(step, elements)` returns `{ key, vars, fallback }`, with keys under `fluidgrids.uiScript.step.*` for `tr(key, vars)` and an English fallback; `UI_SCRIPT_STEP_MESSAGES` holds every English template.
60
66
 
67
+ ## Web targets and the DOM runtime
68
+
69
+ The resolver and the runtime implement spec 05 section 3 for web pages (plan P1-01, BOFF-17144). They read no globals, so the same code runs in a content script, a CDP isolated world, a test DOM and a document rebuilt from a snapshot.
70
+
71
+ **Resolution.** `resolveWebTarget(root, target, { state })` follows the frame and shadow-root chain (`target.frame`: each CSS selector names one same-origin iframe or one open shadow host), then tries the methods in order and uses the first that finds exactly one element in the required state (`interactable`, the default: visible and enabled; `visible`; or `attached`). It returns the element with the method that found it, `fallback: true` when that was not the first enabled method, the element's report form (`candidate`) and one attempt per method (`found`, `none`, `ambiguous`, `notInteractable`, `invalid`, `unsupported`, `disabled`, `notTried`).
72
+
73
+ **Never the first of several.** Several matches are settled only by a rule the target states: an explicit `nth` on `role` and `text`, or a clearly best score for `fuzzy` (the best similarity must lead the next by 0.05) and the spatial `anchor` relations (the nearest element must lead the next by 4 px). Otherwise the method is ambiguous and the next one is tried. When no method finds exactly one element the result is a failure with `code`:
74
+
75
+ | Code | When | Candidates |
76
+ |---|---|---|
77
+ | `ELEMENT_NOT_FOUND` | No method matched, or the frame chain failed (`frame.reason`: `notFound`, `ambiguous`, `invalid`, `notAFrame`, `inaccessible`) | none |
78
+ | `ELEMENT_AMBIGUOUS` | A method matched several elements and no later method found one | up to 5, from the first ambiguous method |
79
+ | `ELEMENT_NOT_INTERACTABLE` | Elements matched but none is visible and enabled (disabled, inside a disabled control or fieldset, `inert`, `aria-disabled`, hidden, or in a hidden or inert frame); for a pointer action also `reason` `covered`, `offscreen` (still outside the viewport after scrolling into view) or `noPointerEvents` | up to 5 |
80
+
81
+ A candidate carries `role`, `name` (cut to 200 characters; empty for sensitive elements; for typed content, an editor or a text area or anything inside one, only the name its labels give), `bounds` (CSS pixels in the top viewport) and the matching `method` and `methodIndex`. The interpreter maps the codes to node error families (see below).
82
+
83
+ **Methods on the web.** `role` compares the computed role and accessible name (a compact accname subset; form fields never take a name from their value) after NFKC, whitespace and case normalisation; `app` and `window` are desktop fields and are ignored. `css` and `xpath` use the page's engines (`xpath` is `unsupported` where the DOM has none). `testId` compares an attribute (default `data-testid`). `fuzzy` scores the edit-distance similarity of names (threshold 0.8 by default, never below 0.5). `anchor` finds a text or role anchor, then the element `inside` it (or inside the heading's container) or the nearest element `leftOf`, `rightOf`, `above`, `below` or on the `sameRow`, from element bounds. `text` matches the innermost element whose visible text contains (or, with `exact`, equals) the text.
84
+
85
+ **The runtime.** `createDomRuntime(document)` returns `{ version, resolve, act, highlight, clearHighlight, snapshot }`; every result is plain JSON. `act(target, action)` resolves first and acts only on exactly one element: `click` (left, middle, right), `doubleClick`, `hover`, `focus`, `type` (through the value setter, with `input` and `change`; `append` optional), `clear`, `select` (by value, effective label or index), `check` (confirmed afterwards), `pressKey` (with the browser's defaults: Enter activates a button, link or summary or performs implicit submission through the default button; Space activates a button, checkbox, radio or summary), `scroll`, `scrollIntoView`, `getText`, `getValue`, `getAttribute` and `exists`. Pointer events follow a real mouse: entry events on every element entered, the held button in `buttons` on press, the click count in `detail`, the element centre as coordinates, focus moved to the nearest focusable element, and cancelled `pointerdown` or `mousedown` honoured. Action problems are `INVALID_ACTION`, `NOT_EDITABLE`, `NOT_SELECTABLE`, `NOT_CHECKABLE`, `OPTION_NOT_FOUND`, `STATE_NOT_CHANGED` (a handler cancelled a `check`) and `SENSITIVE_ELEMENT` (reads of password, one-time-code, card and secret-named fields, of content inside them, and of elements under `data-sensitive`, `data-private` or `data-fg-sensitive`, across shadow roots, slots and frames, are refused). Typed text and read values never appear in a result's report fields. `highlight` outlines the element, or numbers the candidates of an ambiguous target, in a closed shadow root using the system `Highlight` colour; the overlay is removed before every resolve, act or snapshot.
86
+
87
+ The runtime must be injected into an isolated world (a content script, or a CDP world from `Page.createIsolatedWorld`), never the page's main world. `dist/dom-runtime.iife.js` has no imports, needs no `eval`, and keeps an installed runtime of the same protocol version (`DOM_RUNTIME_VERSION`) when it is injected again after a navigation. `bun run check:runtime-size` (a `boff sanity` step) and a unit test hold it to 60 KB minified.
88
+
89
+ **Tree snapshots.** `serializeTreeSnapshot(document)` keeps tag names, an allow-list of attributes, visible text, bounds and a hidden flag, across open shadow roots and same-origin frames, up to 5,000 nodes. It never keeps form-field values (input, text-area and select values, editable-region text, checked and selected state), any text of a sensitive element, scripts, styles, event handlers, or URL queries and fragments, and all kept text passes through `redactCredentials` (threat review R7). `hydrateTreeSnapshot(document, snapshot)` rebuilds the tree into an empty, inert document and returns the probe (`rectOf`, `isVisible`) that makes `resolveWebTarget` see the recorded bounds and visibility; frames are rebuilt where the DOM gives a `srcdoc` frame a document synchronously (a server-side DOM such as happy-dom).
90
+
91
+ **Fixtures.** `@burdenoff/ui-engine/testing` holds copies of the playground pages (`invoices`, `invoices-v2` with renamed ids and moved elements, `invoices-v3` with slightly changed wording, `ambiguous` with two identical Save buttons and a counter, `iframe`, `shadow`, `login`) for the same pages the live suites use (plan P0-08); `mountFixture(document, name)` loads one into a test DOM, attaching declarative shadow roots and filling `srcdoc` frames where the DOM does not.
92
+
93
+ ## The interpreter
94
+
95
+ `runUiScript(script, driver, options)` runs a compiled UI script on a desk and reports step events (plan P1-02, BOFF-17167). It never throws for a script problem: the result carries `status` (`succeeded`, `failed`, `cancelled`, `stopped`), `outputs`, `results` (every `saveAs` value), a `stepLog`, the `error` (`code`, `family`, `message`, `stepPath`, `stepId`), `lastCompletedStepPath` (the checkpoint after the last action step that passed) and event counts.
96
+
97
+ **Compile first.** A worker compiles a stored script with `compileUiScript(script, { elements, sequences, mode, capabilities })`: it fills each pinned element's target from `workerResolveUiAssets`, inlines every shared-sequence `call` (the call becomes a one-attempt retry scope with the call's id, so no other step's path moves; the sequence's names get the reserved prefix `__c<n>_`, which the run leaves out of `results`), removes breakpoints unless `mode` is `test`, and parses the result with `resolved: true`. Problems are `UiRunError` with `INVALID_SCRIPT` or `UNSUPPORTED_ON_DESK`.
98
+
99
+ **Semantics.**
100
+
101
+ - *Preflight*: the run parses the script with `resolved: true`, checks the driver's capabilities, the step range and the inputs, and refuses a masked `type` step without a value. A problem ends the run before any step runs, with only a FINISHED event.
102
+ - *Waits*: a step that needs a target polls the driver (every 250 ms) until the target resolves to exactly one element in the required state or the wait runs out: the step's `timeoutMs`, else `settings.firstWaitMs` (30 s) for the first targeted step on a screen and `settings.waitMs` (10 s) afterwards. An ambiguous target is never acted on. Action problems (`NOT_EDITABLE` and the others) and sensitive reads end the wait at once.
103
+ - *Retries and verification*: `retry.attempts` more attempts after a failure (default delay 1 s); a failed `verify` fails the attempt with `VERIFY_FAILED`. Failures of the VALIDATION, AUTHORIZATION and CANCELLED families are not retried. `onError: continue` records the failure, stores null under `saveAs` and goes on.
104
+ - *Flow*: `if` (a condition, or an element that exists once), `forEach` (a list, or the visible text of every element a target matches; `max` caps it), `while` (stops at `maxIterations` with a warning), `retryScope`, `set` and `log` (messages pass through `redactCredentials`). Reads that may legitimately be empty (`elementExists`, the first page of `extractList`) wait only when the step sets `timeoutMs`. Existence checks fail with `ELEMENT_AMBIGUOUS` when several elements match, like the runtime's `exists`: make the target match one element. A `waitFor` with `state: hidden` and a `verify` of `elementGone` count an element that is still in the page but hidden as gone; `state: detached` needs it removed.
105
+ - *Clean-up*: `cleanup` steps run when the main steps end, after a failure, a cancel or a STOP too (`skipCleanupOnCancel` skips them after a cancel). A failing clean-up step fails a run that had succeeded, and never hides an earlier failure.
106
+ - *TEST runs*: with `mode: 'test'` and `waitForCommand`, the run pauses before a step with `breakpoint` (and before the first step with `stepThrough`), emits PAUSED, and follows NEXT (run the step, pause again), SKIP, CONTINUE and STOP (`STOPPED_BY_USER`, also during clean-up). A `waitForCommand` that rejects fails that step with `DRIVER_ERROR`, and the clean-up still runs. A production run never pauses.
107
+ - *Step ranges*: `startAt` and `stopAfter` are step paths. Steps before `startAt` are skipped with STEP_SKIPPED (`reason: outsideRange`); a block around it is entered (an `if` takes the branch that holds it without evaluating the condition, a loop skips the earlier steps in its first pass only); the run ends after `stopAfter` completes. The window is in walk order, so the clean-up block runs only when the range reaches it. A range whose start is never reached (a disabled block, a loop with no pass) fails `INVALID_STEP_RANGE` instead of succeeding. Variables earlier steps would have set must be given as inputs.
108
+ - *Cancel*: `signal` aborts waits and pauses; the run ends `CANCELLED`.
109
+
110
+ **Events** have the contract's `UiTaskEventInput` shape: `seq` from 1, `kind` (`STEP_STARTED`, `STEP_PASSED`, `STEP_FAILED`, `STEP_SKIPPED`, `PAUSED`, `RESUMED`, `LOG`, `FINISHED`), `stepPath`, `stepId`, `action`, `resolvedBy`, `durationMs`, `errorCode`, `message`, `screenshotFileId`, `detail` and `at`. A failure's `detail` holds what was looked for: `waitedMs`, the method `attempts`, up to five `candidates` with `candidateCount`, the frame problem, `reason` or the desk `problem`, and `stepAttempts`. Events never carry typed text, read values or secrets. After `maxEvents - 1` events (default 10,000) one LOG summary with `detail.truncated` is emitted and the rest are dropped, except FINISHED. The `stepLog` keeps at most 500 entries of `path`, `stepId`, `action`, `status`, `method`, `durationMs`, `elementId`, `screenshotFileId` and the short `error` code.
111
+
112
+ **Error codes.** Every code and its node error family is in `UI_ERROR_CODES` (`errors.ts`):
113
+
114
+ | Family | Codes |
115
+ |---|---|
116
+ | DEPENDENCY | `ELEMENT_NOT_FOUND`, `ELEMENT_AMBIGUOUS`, `WINDOW_NOT_FOUND`, `UNEXPECTED_WINDOW`, `ACTION_FAILED` (the desk problem in `detail.problem`), `SECRET_UNAVAILABLE` |
117
+ | TRANSIENT | `ELEMENT_NOT_INTERACTABLE`, `VERIFY_FAILED`, `NAVIGATION_TIMEOUT`, `NAVIGATION_FAILED`, `WAIT_TIMEOUT`, `APPLICATION_NOT_RESPONDING`, `ROBOT_LOST`, `INTERRUPTED`, `DRIVER_ERROR` |
118
+ | VALIDATION | `UNSUPPORTED_ON_DESK`, `INVALID_SCRIPT`, `INVALID_INPUT` and `INVALID_STEP_RANGE` (all four before any step runs), `EXPRESSION_ERROR`, `SENSITIVE_ELEMENT`, `URL_NOT_ALLOWED` |
119
+ | AUTHORIZATION | `LOGIN_FAILED` |
120
+ | DISPATCH_FAILED | `DESK_UNAVAILABLE` |
121
+ | CANCELLED | `CANCELLED`, `STOPPED_BY_USER` |
122
+
123
+ `ELEMENT_AMBIGUOUS` is DEPENDENCY, not VALIDATION: ambiguity is observed on the live page at run time, like `ELEMENT_NOT_FOUND`, and is never raised before a step runs (BOFF-17109).
124
+
125
+ **Drivers.** A desk implements `UiDriver` (`driver.ts`): `resolve`, `act`, `read`, `readAll`, `listItems`, `pressKeys`, navigation, page text and HTML, `scrollPage`, and optionally `typeSecret`, `login` and `screenshot`, plus its `capabilities` and an optional `clock`. A driver makes one attempt per call; the interpreter owns waiting. A desk failure is a thrown `UiDriverError` with an engine code; anything else becomes `DRIVER_ERROR`. `createDomDriver` never reads a sensitive element, and its page text and HTML leave sensitive content, scripts, handlers and field values out.
126
+
127
+ **Snapshot replay.** `replayUiScriptOnSnapshot(script, { document, snapshot, stepPath?, elementKeys? })` rebuilds a tree snapshot into an empty, inert document and replays a resolved script on it with a dry-run DOM driver, a virtual clock and one attempt per target. Verification, paging and waits that are not for a target to appear are skipped. A run snapshot taken at a step checks only that step; an element version's snapshot checks the steps that use the given element keys. It returns `{ passed, failedStepPath, errorCode, steps: [{ stepPath, verdict, resolvedBy }] }` with verdicts `passed`, `failed`, `skipped` and `unchecked` (contract `UiSnapshotReplay`).
128
+
129
+ **Expressions.** `evaluateExpression` implements every operator of `UI_EXPRESSION_OPS`. Comparison of two texts is by code unit, otherwise by number; `add`, `sub`, `mul`, `div`, `mod` take numbers or numeric text; `concat` joins text; `replace` replaces every literal occurrence (no regular expressions); `join` uses `,` by default; dates are ISO 8601 text in UTC (`formatDate` tokens `YYYY`, `MM`, `DD`, `HH`, `mm`, `ss`). Results are bounded (1,000,000 characters, 10,000 list items, finite numbers), and errors are `EXPRESSION_ERROR` with messages that name the operator, never a value.
130
+
61
131
  ## Compatibility with Stewards
62
132
 
63
133
  The modules were copied from `wspace-botmanor-svc` `src/modules/stewards/teach/` at commit `6558d8b` (BOFF-16873). The differences are:
@@ -78,13 +148,13 @@ Recordings that capture produces, in either copy, still parse here, and the gold
78
148
 
79
149
  ## Browser safety
80
150
 
81
- Nothing under `src/` may import a Node built-in. ESLint enforces this, `tests/browser-safe.test.ts` checks every source file, and `bun run check:browser-safe` (a `boff sanity` extra step) checks the built `dist/` for Node built-ins and for any bare import other than `zod` and `@noble/hashes`.
151
+ Nothing under `src/` may import a Node built-in. ESLint enforces this, `tests/browser-safe.test.ts` checks every source file, and `bun run check:browser-safe` (a `boff sanity` extra step) checks the built `dist/` for Node built-ins and for any bare import other than `zod` and `@noble/hashes`. `bun run check:runtime-size` checks that `dist/dom-runtime.iife.js` is self-contained and within its budget.
82
152
 
83
153
  ## Development
84
154
 
85
155
  ```bash
86
156
  bun install
87
- bun run sanity # format, lint, typecheck, build, tests with the coverage gate, browser-safety check
157
+ bun run sanity # format, lint, typecheck, build, tests with the coverage gate, browser-safety and runtime-size checks
88
158
  bun test # unit tests only
89
159
  bun run build # dist/ (ESM, browser target) and .d.ts files
90
160
  ```
package/dist/capture.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import {
2
2
  maskUrl2,
3
3
  captureRecording2
4
- } from "./index-phd8yhyg.js";
4
+ } from "./index-bnvmt4wf.js";
5
+ import"./index-cs6acyjn.js";
5
6
  import {
6
7
  REDACTED2,
7
8
  redactCredentials2
8
- } from "./index-c6pmt2rg.js";
9
+ } from "./index-mgztm37r.js";
9
10
  export {
10
11
  REDACTED2 as REDACTED,
11
12
  captureRecording2 as captureRecording,
@@ -0,0 +1,65 @@
1
+ /** Longest text a read returns. */
2
+ export declare const MAX_READ_TEXT = 65536;
3
+ /** Longest text a `type` action accepts. */
4
+ export declare const MAX_TYPED_TEXT = 65536;
5
+ /** The actions the runtime performs on a resolved element. */
6
+ export type DomAction = {
7
+ kind: 'click';
8
+ button?: 'left' | 'middle' | 'right';
9
+ } | {
10
+ kind: 'doubleClick';
11
+ } | {
12
+ kind: 'hover';
13
+ } | {
14
+ kind: 'focus';
15
+ } | {
16
+ kind: 'type';
17
+ text: string;
18
+ append?: boolean;
19
+ } | {
20
+ kind: 'clear';
21
+ } | {
22
+ kind: 'select';
23
+ value?: string;
24
+ label?: string;
25
+ index?: number;
26
+ } | {
27
+ kind: 'check';
28
+ checked: boolean;
29
+ } | {
30
+ kind: 'pressKey';
31
+ key: string;
32
+ } | {
33
+ kind: 'scroll';
34
+ dx?: number;
35
+ dy?: number;
36
+ } | {
37
+ kind: 'scrollIntoView';
38
+ } | {
39
+ kind: 'getText';
40
+ } | {
41
+ kind: 'getValue';
42
+ } | {
43
+ kind: 'getAttribute';
44
+ name: string;
45
+ } | {
46
+ kind: 'exists';
47
+ };
48
+ export type DomActionKind = DomAction['kind'];
49
+ /** Actions that only read; they need the element visible, not enabled. */
50
+ export declare const READ_ACTIONS: ReadonlySet<DomActionKind>;
51
+ /** Actions a pointer performs (`check` toggles by clicking); the runtime checks that nothing covers the element first. */
52
+ export declare const POINTER_ACTIONS: ReadonlySet<DomActionKind>;
53
+ /** Why an action could not be performed on the element it resolved to. */
54
+ export type DomActionProblem = 'INVALID_ACTION' | 'NOT_EDITABLE' | 'NOT_SELECTABLE' | 'NOT_CHECKABLE' | 'OPTION_NOT_FOUND' | 'SENSITIVE_ELEMENT'
55
+ /** The control was activated but did not reach the requested state (a handler cancelled it). */
56
+ | 'STATE_NOT_CHANGED';
57
+ export type DomActionOutcome = {
58
+ ok: true;
59
+ value?: string | boolean | null;
60
+ } | {
61
+ ok: false;
62
+ problem: DomActionProblem;
63
+ };
64
+ /** Perform one action on a resolved element. */
65
+ export declare function performDomAction(element: Element, action: DomAction): DomActionOutcome;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * `@burdenoff/ui-engine/dom-runtime`: the DOM runtime for bundling into a
3
+ * content script or an isolated-world script. The same code ships prebuilt as
4
+ * `@burdenoff/ui-engine/dom-runtime.iife.js` (see `iife.ts`).
5
+ */
6
+ export { type CreateDomRuntimeOptions, DOM_RUNTIME_GLOBAL, DOM_RUNTIME_VERSION, type DomActResult, type DomHighlightOptions, type DomResolution, type DomResolutionFound, type DomResolveOptions, type DomRuntime, HIGHLIGHT_HOST_TAG, MAX_HIGHLIGHT_MS, createDomRuntime, installDomRuntime, isRuntimeTarget, } from './runtime.js';
7
+ export { type DomAction, type DomActionKind, type DomActionOutcome, type DomActionProblem, MAX_READ_TEXT, MAX_TYPED_TEXT, POINTER_ACTIONS, READ_ACTIONS, performDomAction, } from './actions.js';
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The DOM runtime (plan P1-01): what a desk injects into a page to resolve
3
+ * targets, highlight them, act on them and take tree snapshots. The paired
4
+ * browser (the FluidGrids extension, P1-09) and the remote-browser executor
5
+ * (P1-07) load the same code, either bundled (`createDomRuntime`) or as the
6
+ * self-contained script `dist/dom-runtime.iife.js`, which installs itself on
7
+ * `globalThis[DOM_RUNTIME_GLOBAL]`.
8
+ *
9
+ * It must be injected into an isolated world (a content script, or a CDP world
10
+ * from `Page.createIsolatedWorld`), never into the page's main world, where
11
+ * page scripts could replace it (threat review S2, C4).
12
+ *
13
+ * Every result is plain JSON. `act` resolves the target first and acts only
14
+ * when exactly one element was found in the required state: an ambiguous,
15
+ * missing or non-interactable target is reported and nothing happens to the
16
+ * page.
17
+ */
18
+ import type { UiTarget } from '../script/types.js';
19
+ import type { WebSearchRoot } from '../target/dom.js';
20
+ import { type ResolveWebTargetOptions } from '../target/resolve.js';
21
+ import { type SerializeTreeSnapshotOptions, type UiTreeSnapshot } from '../target/snapshot.js';
22
+ import type { WebElementState, WebTargetErrorCode, WebTargetFailed, WebTargetFound } from '../target/types.js';
23
+ import { type DomAction, type DomActionProblem } from './actions.js';
24
+ /** The protocol version of the runtime object. A host checks it before calling. */
25
+ export declare const DOM_RUNTIME_VERSION = 1;
26
+ /** The global the IIFE build installs the runtime on. */
27
+ export declare const DOM_RUNTIME_GLOBAL = "__burdenoffUiRuntime";
28
+ /** Longest a highlight stays without being cleared. */
29
+ export declare const MAX_HIGHLIGHT_MS = 60000;
30
+ /** The tag of the highlight overlay host; its boxes live in a closed shadow root. */
31
+ export declare const HIGHLIGHT_HOST_TAG = "fg-ui-highlight";
32
+ /** A found resolution without the element reference: what crosses the world boundary. */
33
+ export type DomResolutionFound = Omit<WebTargetFound<never>, 'element'>;
34
+ export type DomResolution = DomResolutionFound | WebTargetFailed;
35
+ /**
36
+ * The result of `act`. On success `resolution` is the found resolution, or the
37
+ * not-found one for `exists` (whose `value` is then false). On failure `code`
38
+ * is a resolution error code or an action problem, and nothing was done.
39
+ */
40
+ export type DomActResult = {
41
+ ok: true;
42
+ resolution: DomResolution;
43
+ value?: string | boolean | null;
44
+ } | {
45
+ ok: false;
46
+ code: WebTargetErrorCode | DomActionProblem;
47
+ resolution?: DomResolution;
48
+ reason?: 'covered' | 'noPointerEvents' | 'offscreen';
49
+ };
50
+ export interface DomResolveOptions {
51
+ state?: WebElementState;
52
+ }
53
+ export interface DomHighlightOptions extends DomResolveOptions {
54
+ /** A short caption shown under the box (text only). */
55
+ label?: string;
56
+ /** Clear the highlight after this many milliseconds (at most `MAX_HIGHLIGHT_MS`). Absent means until cleared. */
57
+ durationMs?: number;
58
+ }
59
+ export interface DomRuntime {
60
+ version: number;
61
+ resolve(target: UiTarget, options?: DomResolveOptions): DomResolution;
62
+ act(target: UiTarget, action: DomAction, options?: DomResolveOptions): DomActResult;
63
+ highlight(target: UiTarget, options?: DomHighlightOptions): DomResolution;
64
+ clearHighlight(): void;
65
+ snapshot(options?: Pick<SerializeTreeSnapshotOptions, 'maxNodes'>): UiTreeSnapshot;
66
+ }
67
+ export interface CreateDomRuntimeOptions extends Pick<ResolveWebTargetOptions, 'rectOf' | 'isVisible'> {
68
+ /** Where targets are searched. Absent means the document itself. */
69
+ root?: WebSearchRoot;
70
+ }
71
+ /** A light structural check of a target from the host; the host has already parsed the script. */
72
+ export declare function isRuntimeTarget(value: unknown): value is UiTarget;
73
+ /** Create a runtime over a document. */
74
+ export declare function createDomRuntime(document: Document, options?: CreateDomRuntimeOptions): DomRuntime;
75
+ /**
76
+ * Install a runtime on a global object, unless one of the same or a newer
77
+ * protocol version is already there. Returns the installed runtime.
78
+ */
79
+ export declare function installDomRuntime(scope: object, document: Document): DomRuntime;
@@ -0,0 +1,2 @@
1
+ /** `@burdenoff/ui-engine/dom-runtime`: the DOM runtime a desk injects into a page. */
2
+ export * from './dom-runtime/index.js';
@@ -0,0 +1 @@
1
+ (()=>{var U=["data-fg-sensitive","data-sensitive","data-private"];function Z(e){return U.some((t)=>e.hasAttribute(t))}function D(e){let t=e.assignedSlot;if(t!==void 0)return t;let n=e.parentElement?.shadowRoot;if(!n)return null;for(let o of Array.from(n.querySelectorAll("slot")))if((typeof o.assignedNodes==="function"?o.assignedNodes():[]).includes(e))return o;return null}function x(e){let t=D(e);if(t)return t;if(e.parentElement)return e.parentElement;let n=e.getRootNode();if(n&&"host"in n)return n.host;try{return e.ownerDocument.defaultView?.frameElement??null}catch{return null}}function y(e){for(let t=e;t;t=x(t))if(Z(t))return!0;return!1}var Y=256;function g(e){return(e??"").normalize("NFKC").replace(/\s+/g," ").trim().toLowerCase()}function P(e,t){return g(e)===g(t)}function fe(e,t){let n=g(t);return n.length>0&&g(e).includes(n)}function qe(e,t){if(e===t)return 0;if(e.length===0)return t.length;if(t.length===0)return e.length;let n=Array.from({length:t.length+1},(o,r)=>r);for(let o=1;o<=e.length;o+=1){let r=[o];for(let i=1;i<=t.length;i+=1){let s=e[o-1]===t[i-1]?0:1;r[i]=Math.min((n[i]??0)+1,(r[i-1]??0)+1,(n[i-1]??0)+s)}n=r}return n[t.length]??0}function me(e,t){let n=g(e).slice(0,256),o=g(t).slice(0,256),r=Math.max(n.length,o.length);if(r===0)return 0;return 1-qe(n,o)/r}function _(e,t){return e.length<=t?e:`${e.slice(0,Math.max(0,t-1))}…`}var Q=512,Ze=65536,Ye={button:"button",submit:"button",reset:"button",image:"button",checkbox:"checkbox",radio:"radio",range:"slider",number:"spinbutton",search:"searchbox",email:"textbox",tel:"textbox",text:"textbox",url:"textbox",password:"textbox",date:"textbox","datetime-local":"textbox",month:"textbox",time:"textbox",week:"textbox",color:"textbox",file:"button"},Je={article:"article",aside:"complementary",button:"button",datalist:"listbox",dd:"definition",details:"group",dialog:"dialog",dt:"term",fieldset:"group",figure:"figure",h1:"heading",h2:"heading",h3:"heading",h4:"heading",h5:"heading",h6:"heading",hr:"separator",li:"listitem",main:"main",menu:"list",meter:"meter",nav:"navigation",ol:"list",optgroup:"group",option:"option",output:"status",p:"paragraph",progress:"progressbar",summary:"button",table:"table",tbody:"rowgroup",td:"cell",textarea:"textbox",tfoot:"rowgroup",thead:"rowgroup",tr:"row",ul:"list"},Qe=new Set(["button","cell","checkbox","columnheader","gridcell","heading","link","menuitem","menuitemcheckbox","menuitemradio","option","radio","row","rowheader","switch","tab","tooltip","treeitem"]),et=new Set(["button","input","meter","output","progress","select","textarea"]),tt=new Set(["script","style","noscript","template","head","title","meta","link"]);function A(e){return e.localName.toLowerCase()}function be(e){return e.parentElement?.closest("article, aside, main, nav, section")!=null}function nt(e){let t=A(e);switch(t){case"a":case"area":return e.hasAttribute("href")?"link":"";case"input":{let n=(e.getAttribute("type")??"text").toLowerCase();if(n==="hidden")return"";if(e.hasAttribute("list")&&["text","search","email","tel","url"].includes(n))return"combobox";return Ye[n]??"textbox"}case"select":{let n=Number(e.getAttribute("size")??"0");return e.hasAttribute("multiple")||n>1?"listbox":"combobox"}case"img":return e.getAttribute("alt")===""?"presentation":"img";case"th":return e.getAttribute("scope")==="row"?"rowheader":"columnheader";case"header":return be(e)?"":"banner";case"footer":return be(e)?"":"contentinfo";case"section":case"form":return e.hasAttribute("aria-label")||e.hasAttribute("aria-labelledby")?t==="form"?"form":"region":"";default:return Je[t]??""}}function R(e){let t=e.getAttribute("role")?.trim().split(/\s+/)[0];return t?t.toLowerCase():nt(e)}function ot(e,t){let n=e.getRootNode();return typeof n.getElementById==="function"?n.getElementById(t):null}function rt(e){return e.hasAttribute("hidden")||e.getAttribute("aria-hidden")==="true"}function it(e){let t=e.ownerDocument.defaultView;if(!t)return"none";let n=t.getComputedStyle(e);if(n.display==="none")return"subtree";return n.visibility==="hidden"||n.visibility==="collapse"?"self":"none"}function I(e){let t=e.getAttribute("contenteditable");if(t===null)return!1;let n=t.trim().toLowerCase();return n===""||n==="true"||n==="plaintext-only"}function st(e){if(e.shadowRoot)return Array.from(e.shadowRoot.childNodes);if(A(e)==="slot"){let t=e,n=typeof t.assignedNodes==="function"?t.assignedNodes({flatten:!0}):[];if(n.length>0)return n}return Array.from(e.childNodes)}var at=/^(div|p|li|tr|td|th|br|h[1-6]|section|article|header|footer)$/;function O(e,t){if(e.remaining<=0||t.length===0)return;let n=t.slice(0,e.remaining);e.parts.push(n),e.remaining-=n.length}function pe(e,t,n,o,r,i=!1){if(t>32||n.remaining<=0)return;if(e.nodeType===3){if(!i)O(n,e.textContent??"");return}if(e.nodeType!==1)return;let s=e,a=A(s);if(tt.has(a)||Z(s))return;if(!r&&rt(s))return;let l=!1;if(t>0&&!r){let d=o?.isVisible?.(s);if(d===!1)l=!0;else if(d===void 0){let c=it(s);if(c==="subtree")return;l=c==="self"}}let u=s.getAttribute("aria-label")?.trim();if(u&&t>0&&!l){O(n,` ${u} `);return}if(a==="img"||a==="input"&&s.getAttribute("type")==="image"){if(!l)O(n,` ${s.getAttribute("alt")??""} `);return}if(a==="input"||a==="textarea"||a==="select")return;if(t>0&&I(s))return;let f=t>0&&at.test(a);if(f)O(n," ");for(let d of st(s))pe(d,t+1,n,o,r,l);if(f)O(n," ")}function he(e){if(A(e)==="textarea"||I(e))return!0;for(let n=x(e);n;n=x(n))if(A(n)==="textarea"||I(n))return!0;return!1}function Ee(e){for(let t=x(e);t;t=x(t)){let n=A(t);if(n==="textarea"||n==="select"||I(t))return!0}return!1}function H(e,t,n=!1){let o=A(e);if(o==="textarea"||o==="select"||I(e)||Ee(e)||y(e))return"";return E(e.getAttribute("aria-label")??"")||V(e,t,Q,n)}function V(e,t,n=Q,o=!1){if(e.nodeType===1&&y(e))return"";let r={parts:[],remaining:n*2+64};return pe(e,0,r,t,o),E(r.parts.join(""),n)}function E(e,t=Q){return e.replace(/\s+/g," ").trim().slice(0,t)}function lt(e,t){let n=[],o=e.getAttribute("id");if(o){let i=e.getRootNode();for(let s of Array.from(i.querySelectorAll("label")))if(s.getAttribute("for")===o)n.push(H(s,t,!0))}let r=e.closest("label");if(r&&!r.hasAttribute("for"))n.push(H(r,t,!0));return E(n.join(" "))}function J(e,t,n){let o=Array.from(e.children).find((r)=>A(r)===t);return o?H(o,n):""}function k(e,t){return Te(e,t,!0)}function ge(e,t){return Te(e,t,!1)}function ut(e,t){let n=Array.from(e.children).find((o)=>A(o)==="title");if(!n||y(n)||Ee(n))return"";return E(Array.from(n.childNodes).map((o)=>V(o,t)).join(" "))}function Te(e,t,n){let o=e.getAttribute("aria-labelledby");if(o){let l=o.split(/\s+/).filter(Boolean).map((u)=>ot(e,u)).filter((u)=>u!==null).map((u)=>H(u,t,!0)).join(" ");if(E(l))return E(l)}let r=e.getAttribute("aria-label");if(r&&E(r))return E(r);let i=A(e);if(et.has(i)){let l=lt(e,t);if(l)return l}if(i==="input"){let l=(e.getAttribute("type")??"text").toLowerCase();if(l==="button"||l==="submit"||l==="reset"){let u=e.getAttribute("value");if(u!==null)return E(u);return l==="submit"?"Submit":l==="reset"?"Reset":""}if(l==="image")return E(e.getAttribute("alt")??"")}if(i==="img"||i==="area"){let l=e.getAttribute("alt");if(l)return E(l)}if(i==="svg"){let l=ut(e,t);if(l)return l}if(i==="fieldset"){let l=J(e,"legend",t);if(l)return l}if(i==="table"){let l=J(e,"caption",t);if(l)return l}if(i==="option"){let l=E(e.getAttribute("label")??"");if(l)return l}if(i==="figure"){let l=J(e,"figcaption",t);if(l)return l}if(n&&Qe.has(R(e))){let l=V(e,t);if(l)return l}let s=e.getAttribute("title");if(s&&E(s))return E(s);let a=e.getAttribute("placeholder");if(a&&E(a))return E(a);return""}function F(e,t){if(A(e)==="input"){let o=(e.getAttribute("type")??"text").toLowerCase();return o==="button"||o==="submit"||o==="reset"?k(e,t):""}return V(e,t,Ze)}function ee(e,t,n,o){return R(e)===t.trim().toLowerCase()&&g(k(e,o))===g(n)}function ct(e){return e.ownerDocument.defaultView}function B(e){let t=D(e);if(t)return t;if(e.parentElement)return e.parentElement;let n=e.getRootNode();return n&&"host"in n?n.host:null}function N(e,t){let n=t?.isVisible?.(e);if(n!==void 0)return n;if(!e.isConnected)return!1;let o=ct(e),r=e;while(r){if(r.hasAttribute("hidden"))return!1;if(r.localName==="input"&&r.getAttribute("type")?.toLowerCase()==="hidden")return!1;if(o&&o.getComputedStyle(r).display==="none")return!1;r=B(r)}if(o){let s=o.getComputedStyle(e);if(s.visibility==="hidden"||s.visibility==="collapse")return!1;if(s.display==="contents")return!0}let i=e.checkVisibility;return typeof i==="function"?i.call(e):!0}function w(e){for(let n=e;n;n=x(n))if(n.getAttribute("aria-disabled")==="true"||n.hasAttribute("inert"))return!1;if(!dt.has(e.localName)){let n=e.parentElement?.closest("button, select, option, optgroup, textarea");return n?w(n):!0}if(e.hasAttribute("disabled"))return!1;let t=e.parentElement?.closest("fieldset[disabled]");if(t){if(!Array.from(t.children).find((o)=>o.localName==="legend")?.contains(e))return!1}try{return!e.matches(":disabled")}catch{return!0}}var dt=new Set(["button","input","select","textarea","optgroup","option","fieldset"]);function C(e,t,n){let r=t?.rectOf?.(e)??e.getBoundingClientRect();return{x:Math.round(r.x+(n?.x??0)),y:Math.round(r.y+(n?.y??0)),width:Math.round(r.width),height:Math.round(r.height)}}function v(e){let t=Array.from(e.querySelectorAll("*"));return e.nodeType===1?[e,...t]:t}var ft=/password|passcode|passwd|\bpin\b|otp|one[\s-]?time|verification|security code|auth(?:entication)? code|\bcvv\b|\bcvc\b|card number|secret|token|recovery/i,mt=/password|one-time-code|^cc-/i;function bt(e){return ft.test(e)}function S(e){if(y(e))return!0;if(xe(e))return!0;for(let t=x(e);t;t=x(t))if(xe(t))return!0;return!1}function xe(e){let t=e.localName,n=e.getAttribute("contenteditable"),o=n!==null&&n.trim().toLowerCase()!=="false";if(t!=="input"&&t!=="textarea"&&t!=="select"&&!o)return!1;if(e.getAttribute("type")?.toLowerCase()==="password")return!0;if((e.getAttribute("autocomplete")??"").trim().split(/\s+/).filter(Boolean).some((i)=>mt.test(i)))return!0;return pt(e).some((i)=>i.length>0&&bt(i.replace(/[-_]/g," ")))}function pt(e){let t=(a)=>(a??"").slice(0,512),n=[k(e),t(e.getAttribute("aria-label")),t(e.getAttribute("placeholder")),t(e.getAttribute("title")),t(e.getAttribute("name")),t(e.getAttribute("id"))],o=e.getRootNode(),r=(a)=>typeof o.getElementById==="function"?o.getElementById(a):null;for(let a of(e.getAttribute("aria-labelledby")??"").split(/\s+/).filter(Boolean)){let l=r(a);if(l)n.push(t(l.getAttribute("aria-label")),t(l.textContent))}let i=e.getAttribute("id"),s=Array.from(o.querySelectorAll("label")).filter((a)=>i!==null&&a.getAttribute("for")===i||!a.hasAttribute("for")&&a.contains(e));for(let a of s)n.push(t(a.getAttribute("aria-label")),t(a.textContent));return n}var ht=0.8,Et=0.05,gt=4,Ae=1000,z=2,Tt=new Set(["button","checkbox","combobox","link","listbox","menuitem","menuitemcheckbox","menuitemradio","option","radio","searchbox","slider","spinbutton","switch","tab","textbox","treeitem"]),xt=/^[A-Za-z_][\w:.-]{0,127}$/;function At(e){return e.nodeType===9?e:e.ownerDocument}function yt(e,t){return{kind:"list",elements:v(t.root).filter((o)=>ee(o,e.role,e.name,t.probe)),...e.nth!==void 0?{nth:e.nth}:{}}}function St(e,t){try{return{kind:"list",elements:Array.from(t.root.querySelectorAll(e))}}catch{return{kind:"invalid"}}}function Mt(e,t){let n=e.attribute??"data-testid";if(!xt.test(n))return{kind:"invalid"};return{kind:"list",elements:v(t.root).filter((r)=>r.getAttribute(n)===e.value)}}function Rt(e,t){if(e.nodeType===9)return t.ownerDocument===e&&t.getRootNode()===e;return e===t||e.contains(t)}function kt(e,t){let n=At(t.root);if(typeof n.evaluate!=="function")return{kind:"unsupported"};let o;try{o=n.evaluate(e.xpath,t.root,null,7,null)}catch{return{kind:"invalid"}}let r=[],i=Math.min(o.snapshotLength,Ae);for(let s=0;s<i;s+=1){let a=o.snapshotItem(s);if(a&&a.nodeType===1&&Rt(t.root,a))r.push(a)}return{kind:"list",elements:r,...o.snapshotLength>Ae?{overflow:!0}:{}}}function Nt(e,t,n){let o=Math.min(g(e).length,Y),r=Math.max(o,t);return r>0&&Math.abs(o-t)<=(1-n)*r}function wt(e,t){let n=Math.min(1,Math.max(0.5,e.threshold??ht)),o=e.role?.trim().toLowerCase(),r=Math.min(g(e.name).length,Y),i=[];for(let s of v(t.root)){let a=R(s);if(o?a!==o:a==="")continue;let l=k(s,t.probe);if(!Nt(l,r,n))continue;let u=me(l,e.name);if(u>=n)i.push({element:s,score:u})}return{kind:"ranked",scored:i,margin:Et}}function Me(e,t){let n=v(e.root).filter((i)=>t(F(i,e.probe))),o=e.keep??(()=>!0),r=n.filter(o);return n.filter((i)=>!r.some((s)=>s!==i&&i.contains(s)))}function vt(e,t){let n=e.exact?(o)=>P(o,e.text):(o)=>fe(o,e.text);if(g(e.text).length===0)return{kind:"list",elements:[]};return{kind:"list",elements:Me(t,n),...e.nth!==void 0?{nth:e.nth}:{}}}function te(e){return g(e).replace(/[\s:*]+$/u,"")}function Ct(e,t){return(e.kind==="role"?v(t.root).filter((o)=>ee(o,e.role,e.name,t.probe)):Me(t,(o)=>te(o)===te(e.text)&&te(o)!=="")).filter((o)=>N(o,t.probe))}function Re(e,t,n){let o=e.role?.trim().toLowerCase();return v(t.root).filter((r)=>{let i=R(r);if(o?i!==o:!Tt.has(i))return!1;return!n.some((s)=>s===r||r.contains(s))})}var Dt=new Set(["h1","h2","h3","h4","h5","h6","legend","caption","figcaption","summary","dt"]);function _t(e){return Dt.has(e.localName)||R(e)==="heading"}function Ot(e){for(let t=e;t;t=t.parentElement)if(_t(t))return t;return null}function It(e,t,n){let o=Re(e,t,n),r=new Set;for(let i of n){let a=Ot(i)?.parentElement??i;for(let l of o)if(a.contains(l))r.add(l)}return{kind:"list",elements:o.filter((i)=>r.has(i))}}function ye(e,t,n,o){return e<o&&n<t}function Lt(e,t,n){let o=t.x+t.width,r=t.y+t.height,i=n.x+n.width,s=n.y+n.height,a=ye(t.y,r,n.y,s),l=ye(t.x,o,n.x,i);switch(e){case"rightOf":return a&&n.x>=o-z?Math.max(0,n.x-o):null;case"leftOf":return a&&i<=t.x+z?Math.max(0,t.x-i):null;case"below":return l&&n.y>=r-z?Math.max(0,n.y-r):null;case"above":return l&&s<=t.y+z?Math.max(0,t.y-s):null;case"sameRow":return a?Math.abs(n.x+n.width/2-(t.x+t.width/2)):null;default:return null}}function Se(e){return e.width>0&&e.height>0}function Wt(e,t){let n=Ct(e.anchor,t);if(n.length===0)return{kind:"list",elements:[]};if(e.relation==="inside")return It(e,t,n);let o=n.map((i)=>C(i,t.probe)).filter(Se);if(o.length===0)return{kind:"unsupported"};let r=[];for(let i of Re(e,t,n)){let s=C(i,t.probe);if(!Se(s))continue;let a=null;for(let l of o){let u=Lt(e.relation,l,s);if(u!==null&&(a===null||u<a))a=u}if(a!==null)r.push({element:i,score:-a})}return{kind:"ranked",scored:r,margin:gt}}function ke(e,t){switch(e.kind){case"role":return yt(e,t);case"css":return St(e.selector,t);case"testId":return Mt(e,t);case"xpath":return kt(e,t);case"fuzzy":return wt(e,t);case"anchor":return Wt(e,t);case"text":return vt(e,t);default:return{kind:"unsupported"}}}var Ne=5,we=200;var Ut={x:0,y:0,width:0,height:0};function Pt(e,t,n){let o={root:e,offset:Ut,hidden:!1,disabled:!1};for(let[r,i]of(t??[]).entries()){let s;try{s=Array.from(o.root.querySelectorAll(i))}catch{return{index:r,reason:"invalid"}}if(s.length===0)return{index:r,reason:"notFound"};if(s.length>1)return{index:r,reason:"ambiguous"};let a=s[0],l=a.localName;if(l==="iframe"||l==="frame"){let u=a,f=null;try{f=u.contentDocument}catch{f=null}if(!f)return{index:r,reason:"inaccessible"};let d=C(a,n,o.offset);o={root:f,offset:{x:d.x+u.clientLeft,y:d.y+u.clientTop,width:0,height:0},hidden:o.hidden||!N(a,n),disabled:o.disabled||!w(a)}}else if(a.shadowRoot)o={root:a.shadowRoot,offset:o.offset,hidden:o.hidden,disabled:o.disabled};else return{index:r,reason:"notAFrame"}}return o}function Ht(e,t,n,o){if(t==="attached")return!0;if(n.hidden||!N(e,o))return!1;return t==="visible"||!n.disabled&&w(e)}function ve(e,t,n,o,r){return{role:R(e),name:S(e)?"":_(he(e)?ge(e,r):k(e,r),we),bounds:C(e,r,o),method:t.kind,methodIndex:n}}function Vt(e,t,n,o=!1){if(t.length===0)return e.length>0?{outcome:"notInteractable",elements:e,matches:0}:{outcome:"none",elements:[],matches:0};if(o)return{outcome:"ambiguous",elements:t,matches:t.length};if(n!==void 0){let r=t[n];return r?{outcome:"found",element:r,matches:t.length}:{outcome:"none",elements:[],matches:t.length}}return t.length===1?{outcome:"found",element:t[0],matches:1}:{outcome:"ambiguous",elements:t,matches:t.length}}function Ft(e,t,n){if(t.length===0)return e.length>0?{outcome:"notInteractable",elements:e.map((a)=>a.element),matches:0}:{outcome:"none",elements:[],matches:0};let o=[...t].sort((a,l)=>l.score-a.score),r=o[0],i=o[1];if(!i||r.score-i.score>=n)return{outcome:"found",element:r.element,matches:t.length};let s=o.filter((a)=>r.score-a.score<n).map((a)=>a.element);return{outcome:"ambiguous",elements:s,matches:s.length}}function Bt(e,t){switch(e.kind){case"invalid":case"unsupported":return e.kind;case"list":return Vt(e.elements,e.elements.filter(t),e.nth,e.overflow);case"ranked":return Ft(e.scored,e.scored.filter((n)=>t(n.element)),e.margin)}}function X(e,t,n=[],o=0,r){return{status:"failed",code:e,candidates:n,candidateCount:o,attempts:t,...r?{frame:r}:{}}}function Ce(e,t,n={}){let o=n.state??"interactable",r=Pt(e,t.frame,n);if(!("root"in r)){let d=t.methods.map((c,b)=>({index:b,method:c.kind,outcome:"notTried",matches:0}));return X("ELEMENT_NOT_FOUND",d,[],0,r)}let i=[],s=t.methods.findIndex((d)=>d.enabled!==!1),a,l,u;for(let[d,c]of t.methods.entries()){if(u){i.push({index:d,method:c.kind,outcome:"notTried",matches:0});continue}if(c.enabled===!1){i.push({index:d,method:c.kind,outcome:"disabled",matches:0});continue}let b=(p)=>Ht(p,o,r,n),m=Bt(ke(c,{root:r.root,probe:n,keep:b}),b);if(m==="invalid"||m==="unsupported"){i.push({index:d,method:c.kind,outcome:m,matches:0});continue}if(i.push({index:d,method:c.kind,outcome:m.outcome,matches:m.matches}),m.outcome==="found")u={element:m.element,method:c,index:d};else if(m.outcome==="ambiguous"&&!a)a={elements:m.elements,method:c,index:d,count:m.matches};else if(m.outcome==="notInteractable"&&!l)l={elements:m.elements,method:c,index:d}}if(u)return{status:"found",element:u.element,method:u.method.kind,methodIndex:u.index,fallback:u.index!==s,candidate:ve(u.element,u.method,u.index,r.offset,n),attempts:i};let f=(d)=>d.elements.slice(0,Ne).map((c)=>ve(c,d.method,d.index,r.offset,n));if(a)return X("ELEMENT_AMBIGUOUS",i,f(a),a.count);if(l)return X("ELEMENT_NOT_INTERACTABLE",i,f(l),l.elements.length);return X("ELEMENT_NOT_FOUND",i)}var ne="[REDACTED]",zt=[/\b(?:Bearer|Basic)\s+[^\s"'`,;)\]}]+/gi,/\b(?:sk|pk|rk|xai)-[^\s"'`,;)\]}]+/gi,/\b(?:gsk|hf|ghp|gho|ghs|ghu|glpat)_[^\s"'`,;)\]}]+/gi,/\bAIza[\w-]{10,}/g,/\b(?:AKIA|ASIA)[0-9A-Z]{12,}/g],Xt=/([\s"'`,;:=()[\]{}]+)/,Kt=/^(?:api[_-]?key|access[_-]?key|secret|secret[_-]?key|client[_-]?secret|token|password)$/i;function jt(e){let t=e.indexOf("…");return e.includes("***")||t!==-1&&t<e.length-1}function $t(e){let t=e.split(Xt);for(let n=0;n<t.length;n+=2){let o=t[n]??"";if(o&&o!=="[REDACTED]"&&jt(o))t[n]="[REDACTED]";let r=t[n+1]??"";if(t[n+2]&&Kt.test(o)&&/[:=]/.test(r))t[n+2]="[REDACTED]"}return t.join("")}function oe(e){if(!e)return e;let t=e;for(let n of zt)t=t.replace(n,"[REDACTED]");return t=$t(t),t.replace(/(?:\[REDACTED\]){2,}/g,"[REDACTED]")}var De="";function K(e){if(!e)return!1;let t=e.replaceAll("[REDACTED]",De);return oe(t).replaceAll(De,"[REDACTED]")!==e}function re(e){try{return decodeURIComponent(e.replaceAll("+"," "))}catch{return e}}function _e(e){return K(re(e).replace(/[/?&#]/g," "))}var Gt=1,qt=5000,Zt=64,Ie=500,Yt=new Set(["script","style","noscript","template","link","meta","base","head","object","embed"]),Jt=new Set(["textarea"]),Qt=new Set(["id","class","role","name","type","for","title","alt","placeholder","label","autocomplete","tabindex","disabled","readonly","hidden","inert","contenteditable","list","multiple","size","scope","slot","part","lang","dir","data-testid","data-test","data-test-id","data-qa","data-cy","data-automation-id",...U]),en=new Set(["aria-valuenow","aria-valuetext","aria-checked","aria-selected","aria-pressed"]),tn=new Set(["button","submit","reset"]),Le=/reset|recover|verify|verification|magic|confirm|activate|invite|unsubscribe/i,nn=/^[a-z][a-z0-9-]{0,63}$/;var on=/^[a-z][a-z0-9_:.-]{0,127}$/;function We(e){let t=e.getAttribute("contenteditable");return t!==null&&t.trim().toLowerCase()!=="false"}function Ue(e){for(let t=x(e);t;t=x(t))if(t.localName==="textarea"||We(t))return!0;return!1}function rn(e){if(!e.parentElement?.shadowRoot)return!1;let t=D(e);return t!==null&&(S(t)||Ue(t))}function j(e){return _(oe(e),Ie)}function sn(e){let t=e;for(let n=0;n<3;n+=1){let o=re(t);if(o===t)break;t=o}return t}function an(e){let t=e.split(/[/?#;]/),n=t.findIndex((r)=>Le.test(r));return t.slice(0,n+1).map((r)=>K(r)?ne:r).join("/")}function Pe(e){let t=e.trim();if(t==="")return null;let n=/^[a-z][a-z0-9+.-]*:/i.test(t)||t.startsWith("//"),o="",r;if(n){let f;try{f=new URL(t.startsWith("//")?`https:${t}`:t)}catch{return null}if(f.protocol!=="http:"&&f.protocol!=="https:")return null;o=t.startsWith("//")?`//${f.host}`:f.origin,r=f.pathname}else r=t.split(/[?#]/)[0]??"";let i=r.split("/"),s=i.map(sn),a=s.findIndex((f)=>Le.test(f)),u=(a>=0?i.slice(0,a+1):i).map((f,d)=>{let c=s[d]??f;if(d===a)return an(c);return K(c)||_e(f)?ne:f}).join("/");return _(`${o}${u}`,Ie)}var ln=new Set(["alt","label","title","placeholder","value","aria-label","aria-description","aria-roledescription","aria-placeholder"]),un=new Set(["aria-hidden","aria-disabled","aria-expanded","aria-haspopup","aria-controls","aria-owns","aria-labelledby","aria-describedby","aria-level","aria-current","aria-modal","aria-multiline","aria-multiselectable","aria-orientation","aria-readonly","aria-required","aria-invalid","aria-busy","aria-live","aria-atomic","aria-posinset","aria-setsize","aria-colcount","aria-colindex","aria-colspan","aria-rowcount","aria-rowindex","aria-rowspan","aria-sort"]);function cn(e,t){let n={},o=e.localName;for(let r of Array.from(e.attributes)){let i=r.name.toLowerCase();if(i.startsWith("on")||!on.test(i))continue;if(t&&(ln.has(i)||i==="href"||i.startsWith("aria-")&&!un.has(i)))continue;if(Qt.has(i)||i.startsWith("aria-")&&!en.has(i))n[i]=j(r.value);else if(i==="href"&&(o==="a"||o==="area")){let s=Pe(r.value);if(s!==null)n[i]=s}else if(i==="value"&&o==="input"&&tn.has((e.getAttribute("type")??"").toLowerCase()))n[i]=j(r.value)}return Object.keys(n).length>0?n:void 0}function dn(e,t){let n=t?.rectOf?.(e)??e.getBoundingClientRect(),o=[Math.round(n.x),Math.round(n.y),Math.round(n.width),Math.round(n.height)];return o[2]>0||o[3]>0?o:void 0}function Oe(e,t,n,o,r){let i=[];for(let s of Array.from(e.childNodes)){if(t.count>=t.max){t.truncated=!0;break}if(s.nodeType===3){if(!o||rn(s))continue;let a=s.textContent??"";if(a.length===0)continue;let l=a.trim()===""?" ":j(a);t.count+=1,i.push(l)}else if(s.nodeType===1){let a=G(s,t,n+1,o,r);if(a)i.push(a)}}return i}function G(e,t,n,o,r){let i=e.localName.toLowerCase();if(Yt.has(i)||!nn.test(i))return null;if(n>Zt)return t.truncated=!0,null;t.count+=1;let s={t:i},a=Ue(e),l=r||a||y(e),u=cn(e,l);if(u)s.a=u;if(N(e,t.probe)){let p=dn(e,t.probe);if(p)s.r=p}else s.h=1;let f=S(e),d=o&&!a&&!f&&!Jt.has(i)&&!We(e),c=l||!d;if(i==="svg"){let p=Array.from(e.children).find((T)=>T.localName==="title"),h=p?G(p,t,n+1,d,c):null;if(h)s.c=[h];return s}if(i==="iframe"||i==="frame"){let p=null;try{p=e.contentDocument}catch{p=null}let h=p?.documentElement;if(h){let T=G(h,t,n+1,d,c);if(T)s.f=T}return s}let b=Oe(e,t,n,d,c);if(b.length>0)s.c=b;let m=e.shadowRoot;if(m){let p=Oe(m,t,n,d,c);if(p.length>0)s.s=p}return s}function fn(e){let t=e.querySelector("title");if(t&&y(t))return"";return j(e.title??"")}function He(e,t={}){let n={count:0,max:Math.max(1,t.maxNodes??qt),truncated:!1,probe:t},o=G(e.documentElement,n,0,!0,!1)??{t:"html"},r=e.defaultView;return{snapshotVersion:Gt,url:Pe(e.URL)??"",title:fn(e),viewport:{width:Math.round(r?.innerWidth??0),height:Math.round(r?.innerHeight??0)},root:o,nodeCount:n.count,truncated:n.truncated}}var ie=65536,mn=65536,Fe=new Set(["getText","getValue","getAttribute","exists"]),Be=new Set(["click","doubleClick","hover","check"]);function bn(e){return e.ownerDocument.defaultView}var pn={left:0,middle:1,right:2},hn={left:1,middle:4,right:2};function se(e,t,n){let o=e.getBoundingClientRect();return{bubbles:!0,cancelable:!0,composed:!0,view:t,button:pn[n],buttons:0,clientX:o.x+o.width/2,clientY:o.y+o.height/2,pointerId:1,pointerType:"mouse",isPrimary:!0}}function ze(e,t,n){let o=typeof t.PointerEvent==="function"?t.PointerEvent:t.MouseEvent,r=[];for(let s=e;s;s=B(s))r.unshift(s);let i={...n,bubbles:!1};e.dispatchEvent(new o("pointerover",n));for(let s of r)s.dispatchEvent(new o("pointerenter",i));e.dispatchEvent(new t.MouseEvent("mouseover",n));for(let s of r)s.dispatchEvent(new t.MouseEvent("mouseenter",i))}var En='a[href], area[href], button, input, select, textarea, iframe, summary, [tabindex], [contenteditable]:not([contenteditable="false"])';function gn(e,t){for(let o=e;o;o=B(o))if(o.matches(En)&&w(o)&&o instanceof t.HTMLElement){o.focus();return}let n=e.ownerDocument.activeElement;if(n instanceof t.HTMLElement&&n!==e.ownerDocument.body)n.blur()}function Tn(e,t,n,o,r){let i=typeof t.PointerEvent==="function"?t.PointerEvent:t.MouseEvent,s={...n,buttons:hn[o],detail:r},a={...n,detail:r};ze(e,t,n);let l=e.dispatchEvent(new i("pointerdown",s));if(l&&e.dispatchEvent(new t.MouseEvent("mousedown",s)))gn(e,t);if(e.dispatchEvent(new i("pointerup",a)),l)e.dispatchEvent(new t.MouseEvent("mouseup",a))}function L(e,t,n,o=1){let r=se(e,t,n);Tn(e,t,r,n,o);let i=n==="left"?"click":n==="right"?"contextmenu":"auxclick";e.dispatchEvent(new t.MouseEvent(i,{...r,detail:o}))}function Xe(e,t){if(e instanceof t.HTMLTextAreaElement)return!0;if(!(e instanceof t.HTMLInputElement))return!1;return!["button","submit","reset","image","checkbox","radio","file","range","color","hidden"].includes(e.type)}function xn(e,t,n){let o=e instanceof t.HTMLTextAreaElement?t.HTMLTextAreaElement.prototype:t.HTMLInputElement.prototype,r=Object.getOwnPropertyDescriptor(o,"value")?.set;if(r)r.call(e,n);else e.value=n;e.dispatchEvent(new t.Event("input",{bubbles:!0,composed:!0})),e.dispatchEvent(new t.Event("change",{bubbles:!0}))}function An(e,t){if(!(e instanceof t.HTMLElement))return!1;if(e.isContentEditable)return!0;let n=e.closest("[contenteditable]")?.getAttribute("contenteditable")?.toLowerCase();return n===""||n==="true"||n==="plaintext-only"}function Ve(e,t,n,o){if(n.length>mn)return{ok:!1,problem:"INVALID_ACTION"};if(Xe(e,t)){if(e.readOnly)return{ok:!1,problem:"NOT_EDITABLE"};return e.focus(),xn(e,t,o?`${e.value}${n}`:n),{ok:!0}}if(An(e,t))return e.focus(),e.textContent=o?`${e.textContent??""}${n}`:n,e.dispatchEvent(new t.Event("input",{bubbles:!0,composed:!0})),{ok:!0};return{ok:!1,problem:"NOT_EDITABLE"}}function yn(e){let t=e.getAttribute("label");return t!==null&&t.trim()!==""?t:e.textContent??""}function Sn(e,t,n){if(!(e instanceof t.HTMLSelectElement))return{ok:!1,problem:"NOT_SELECTABLE"};let o=Array.from(e.options),r=n.value!==void 0?o.find((i)=>i.value===n.value):n.label!==void 0?o.find((i)=>P(yn(i),n.label)):n.index!==void 0?o[n.index]:void 0;if(!r||r.disabled||r.closest("optgroup")?.hasAttribute("disabled"))return{ok:!1,problem:"OPTION_NOT_FOUND"};return e.focus(),r.selected=!0,e.dispatchEvent(new t.Event("input",{bubbles:!0,composed:!0})),e.dispatchEvent(new t.Event("change",{bubbles:!0})),{ok:!0}}function Mn(e,t,n){if(e instanceof t.HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){if(e.checked!==n){if(e.type==="radio"&&!n)return{ok:!1,problem:"NOT_CHECKABLE"};L(e,t,"left")}return e.checked===n?{ok:!0}:{ok:!1,problem:"STATE_NOT_CHANGED"}}let o=e.getAttribute("role");if(o==="checkbox"||o==="switch"||o==="radio"||o==="menuitemcheckbox"){let r=()=>e.getAttribute("aria-checked")==="true";if(r()!==n)L(e,t,"left");return r()===n?{ok:!0}:{ok:!1,problem:"STATE_NOT_CHANGED"}}return{ok:!1,problem:"NOT_CHECKABLE"}}var Rn=/^(?:[\s\S]|[A-Z][A-Za-z0-9]{1,23})$/u;function kn(e,t){if(e instanceof t.HTMLButtonElement)return!0;if(e instanceof t.HTMLInputElement)return["submit","button","reset","image"].includes(e.type);let n=e.localName;return n==="a"&&e.hasAttribute("href")||n==="summary"}function Nn(e,t){if(e instanceof t.HTMLButtonElement)return!0;if(e instanceof t.HTMLInputElement)return["submit","button","reset","image","checkbox","radio"].includes(e.type);return e.localName==="summary"}function ae(e,t){e.dispatchEvent(new t.MouseEvent("click",{bubbles:!0,cancelable:!0,composed:!0,view:t,detail:0}))}function wn(e,t,n){if(!Rn.test(n))return{ok:!1,problem:"INVALID_ACTION"};let o=n==="Space"?" ":n;if(e instanceof t.HTMLElement)e.focus();let r={key:o,bubbles:!0,cancelable:!0,composed:!0},i=e.dispatchEvent(new t.KeyboardEvent("keydown",r));if(o==="Enter"&&i){if(kn(e,t))ae(e,t);else if(e instanceof t.HTMLInputElement&&Xe(e,t)&&e.form)Dn(e.form,t)}let s=e.dispatchEvent(new t.KeyboardEvent("keyup",r));if(o===" "&&i&&s&&Nn(e,t))ae(e,t);return{ok:!0}}var vn=new Set(["submit","image"]),Cn=new Set(["text","search","url","tel","email","password","date","month","week","time","datetime-local","number"]);function Dn(e,t){let n=Array.from(e.elements),o=e.getRootNode(),r=Array.from(o.querySelectorAll("button, input")).find((s)=>(s instanceof t.HTMLButtonElement&&s.type==="submit"||s instanceof t.HTMLInputElement&&vn.has(s.type))&&s.form===e);if(r){if(w(r))ae(r,t);return}if(n.filter((s)=>s instanceof t.HTMLInputElement&&Cn.has(s.type)).length===1)e.requestSubmit()}function _n(e,t){if(e instanceof t.HTMLInputElement&&(e.type==="checkbox"||e.type==="radio"))return e.checked;if(e instanceof t.HTMLInputElement||e instanceof t.HTMLTextAreaElement||e instanceof t.HTMLSelectElement)return e.value.slice(0,ie);let n=e.getAttribute("aria-checked");if(n==="true"||n==="false")return n==="true";return e.getAttribute("aria-valuenow")??e.getAttribute("aria-valuetext")}var On=/^[A-Za-z_][\w:.-]{0,127}$/;function Ke(e,t){let n=bn(e);if(!n)return{ok:!1,problem:"INVALID_ACTION"};switch(t.kind){case"click":return L(e,n,t.button??"left"),{ok:!0};case"doubleClick":return L(e,n,"left",1),L(e,n,"left",2),e.dispatchEvent(new n.MouseEvent("dblclick",{...se(e,n,"left"),detail:2})),{ok:!0};case"hover":{let o=se(e,n,"left"),r=typeof n.PointerEvent==="function"?n.PointerEvent:n.MouseEvent;return ze(e,n,o),e.dispatchEvent(new r("pointermove",o)),e.dispatchEvent(new n.MouseEvent("mousemove",o)),{ok:!0}}case"focus":if(e instanceof n.HTMLElement)e.focus();return{ok:!0};case"type":return typeof t.text==="string"?Ve(e,n,t.text,t.append===!0):{ok:!1,problem:"INVALID_ACTION"};case"clear":return Ve(e,n,"",!1);case"select":return Sn(e,n,t);case"check":return Mn(e,n,t.checked===!0);case"pressKey":return typeof t.key==="string"?wn(e,n,t.key):{ok:!1,problem:"INVALID_ACTION"};case"scroll":return e.scrollBy?.({left:Number(t.dx??0)||0,top:Number(t.dy??0)||0}),{ok:!0};case"scrollIntoView":return e.scrollIntoView?.({block:"center",inline:"nearest"}),{ok:!0};case"getText":if(S(e))return{ok:!1,problem:"SENSITIVE_ELEMENT"};return{ok:!0,value:F(e).slice(0,ie)};case"getValue":if(S(e))return{ok:!1,problem:"SENSITIVE_ELEMENT"};return{ok:!0,value:_n(e,n)};case"getAttribute":{if(typeof t.name!=="string"||!On.test(t.name))return{ok:!1,problem:"INVALID_ACTION"};let o=t.name.toLowerCase();if(S(e))return{ok:!1,problem:"SENSITIVE_ELEMENT"};return{ok:!0,value:e.getAttribute(o)?.slice(0,ie)??null}}case"exists":return{ok:!0,value:!0};default:return{ok:!1,problem:"INVALID_ACTION"}}}var $e=1,je="__burdenoffUiRuntime",In=60000,Ln="fg-ui-highlight",Wn=new Set(["role","css","testId","xpath","fuzzy","anchor","text"]);function le(e){if(!e||typeof e!=="object")return!1;let t=e;if(!Array.isArray(t.methods)||t.methods.length===0||t.methods.length>8)return!1;if(t.frame!==void 0&&!(Array.isArray(t.frame)&&t.frame.every((n)=>typeof n==="string")))return!1;return t.methods.every((n)=>!!n&&typeof n==="object"&&Wn.has(String(n.kind)))}function ue(){return{status:"failed",code:"ELEMENT_NOT_FOUND",candidates:[],candidateCount:0,attempts:[]}}function ce(e){return{status:e.status,method:e.method,methodIndex:e.methodIndex,fallback:e.fallback,candidate:e.candidate,attempts:e.attempts}}function Un(e){try{return e.defaultView?.frameElement??null}catch{return null}}function Pn(e,t,n,o){let r=e.getRootNode();if(typeof r.elementFromPoint!=="function")return null;let i=r.elementFromPoint(t,n);if(!i)return"offscreen";if(i===e||e.contains(i))return null;return o.some((s)=>s.contains(i))?null:"covered"}function Hn(e,t){let n=t.x+t.width/2,o=t.y+t.height/2,r=Array.from(e.labels??[]),i=e;for(let s=0;s<32;s+=1){let a=Pn(i,n,o,s===0?r:[]);if(a)return a;let l=i.getRootNode();if(l&&"host"in l){i=l.host;continue}let u=Un(i.ownerDocument);if(!u)return null;let f=u.getBoundingClientRect();n+=f.x+u.clientLeft,o+=f.y+u.clientTop,i=u}return null}function Vn(e,t){let n=e.ownerDocument.defaultView;if(!n)return!1;let o=t.x+t.width/2,r=t.y+t.height/2;return o<0||r<0||o>=n.innerWidth||r>=n.innerHeight}function Fn(e){let t=e.ownerDocument.defaultView;if(t&&t.getComputedStyle(e).pointerEvents==="none")return"noPointerEvents";let n=e.getBoundingClientRect();if(n.width<=0||n.height<=0)return null;if(Vn(e,n)&&typeof e.scrollIntoView==="function")e.scrollIntoView({block:"center",inline:"center"}),n=e.getBoundingClientRect();return Hn(e,n)}function Bn(e,t={}){let n=t.root??e,o={...t.rectOf?{rectOf:t.rectOf}:{},...t.isVisible?{isVisible:t.isVisible}:{}},r=null,i=null,s=()=>{if(i!==null)clearTimeout(i),i=null;r?.remove(),r=null},a=(c,b)=>(s(),Ce(n,c,{...o,...b?{state:b}:{}})),l=(c,b={})=>{if(!le(c))return ue();let m=a(c,b.state);return m.status==="found"?ce(m):m},u=(c,b,m={})=>{if(!b||typeof b!=="object"||typeof b.kind!=="string")return{ok:!1,code:"INVALID_ACTION"};if(!le(c))return{ok:!1,code:"ELEMENT_NOT_FOUND",resolution:ue()};let p=m.state??(Fe.has(b.kind)?"visible":"interactable"),h=a(c,p);if(h.status!=="found"){if(b.kind==="exists"&&h.code==="ELEMENT_NOT_FOUND")return{ok:!0,value:!1,resolution:h};return{ok:!1,code:h.code,resolution:h}}let T=ce(h),W=Be.has(b.kind)?Fn(h.element):null;if(W)return{ok:!1,code:"ELEMENT_NOT_INTERACTABLE",reason:W,resolution:{status:"failed",code:"ELEMENT_NOT_INTERACTABLE",candidates:[h.candidate],candidateCount:1,attempts:h.attempts}};let M=Ke(h.element,b);if(!M.ok)return{ok:!1,code:M.problem,resolution:T};return M.value===void 0?{ok:!0,resolution:T}:{ok:!0,resolution:T,value:M.value}},f=(c,b,m)=>{let p=e.createElement(Ln);p.setAttribute("aria-hidden","true"),p.setAttribute("style","all: initial; position: fixed; inset: 0; pointer-events: none; z-index: 2147483647;");let h=p.attachShadow({mode:"closed"});c.forEach((T,W)=>{let M=e.createElement("div");M.setAttribute("style",`position: fixed; left: ${T.bounds.x-3}px; top: ${T.bounds.y-3}px; width: ${T.bounds.width+6}px; height: ${T.bounds.height+6}px; outline: 3px solid Highlight; border-radius: 4px; box-sizing: border-box;`);let de=m?`${W+1}${b?` ${b}`:""}`:b;if(de){let q=e.createElement("span");q.textContent=de.slice(0,120),q.setAttribute("style","position: absolute; left: 0; top: 100%; margin-top: 4px; padding: 2px 6px; font: 600 11px system-ui, sans-serif; background: Highlight; color: HighlightText; border-radius: 3px; white-space: nowrap;"),M.appendChild(q)}h.appendChild(M)}),e.documentElement.appendChild(p),r=p};return{version:$e,resolve:l,act:u,highlight:(c,b={})=>{if(!le(c))return ue();let m=a(c,b.state??"visible");if(m.status==="found")f([m.candidate],b.label,!1);else if(m.candidates.length>0)f(m.candidates,b.label,!0);let p=Math.min(In,Math.max(0,Number(b.durationMs??0)||0));if(r&&p>0)i=setTimeout(s,p);return m.status==="found"?ce(m):m},clearHighlight:s,snapshot:(c={})=>(s(),He(e,{...o,...c.maxNodes?{maxNodes:c.maxNodes}:{}}))}}function Ge(e,t){let n=Reflect.get(e,je);if(n&&typeof n==="object"&&typeof n.version==="number"&&n.version>=$e)return n;let o=Object.freeze(Bn(t));return Object.defineProperty(e,je,{value:o,configurable:!0,enumerable:!1,writable:!1}),o}Ge(globalThis,globalThis.document);})();
@@ -0,0 +1,30 @@
1
+ import {
2
+ DOM_RUNTIME_VERSION2,
3
+ DOM_RUNTIME_GLOBAL2,
4
+ MAX_HIGHLIGHT_MS2,
5
+ HIGHLIGHT_HOST_TAG2,
6
+ isRuntimeTarget2,
7
+ createDomRuntime2,
8
+ installDomRuntime2
9
+ } from "./index-ct2xctrq.js";
10
+ import {
11
+ MAX_READ_TEXT2,
12
+ MAX_TYPED_TEXT2,
13
+ READ_ACTIONS2,
14
+ POINTER_ACTIONS2,
15
+ performDomAction2
16
+ } from "./index-77pcz6n3.js";
17
+ export {
18
+ DOM_RUNTIME_GLOBAL2 as DOM_RUNTIME_GLOBAL,
19
+ DOM_RUNTIME_VERSION2 as DOM_RUNTIME_VERSION,
20
+ HIGHLIGHT_HOST_TAG2 as HIGHLIGHT_HOST_TAG,
21
+ MAX_HIGHLIGHT_MS2 as MAX_HIGHLIGHT_MS,
22
+ MAX_READ_TEXT2 as MAX_READ_TEXT,
23
+ MAX_TYPED_TEXT2 as MAX_TYPED_TEXT,
24
+ POINTER_ACTIONS2 as POINTER_ACTIONS,
25
+ READ_ACTIONS2 as READ_ACTIONS,
26
+ createDomRuntime2 as createDomRuntime,
27
+ installDomRuntime2 as installDomRuntime,
28
+ isRuntimeTarget2 as isRuntimeTarget,
29
+ performDomAction2 as performDomAction
30
+ };
@@ -0,0 +1,44 @@
1
+ import type { UiClock, UiDriver } from '../interpret/driver.js';
2
+ import type { UiTarget } from '../script/types.js';
3
+ import { type ElementStateProbe } from '../target/dom.js';
4
+ /** The capability ids a DOM driver supports by default. */
5
+ export declare const DOM_DRIVER_CAPABILITIES: readonly string[];
6
+ /** Navigation for a DOM driver: the host decides what loading a page means. */
7
+ export interface DomDriverNavigation {
8
+ navigate(url: string, options: {
9
+ waitUntil: string;
10
+ timeoutMs: number;
11
+ }): Promise<void> | void;
12
+ goBack(options: {
13
+ timeoutMs: number;
14
+ }): Promise<void> | void;
15
+ reload(options: {
16
+ timeoutMs: number;
17
+ }): Promise<void> | void;
18
+ closeTab(): Promise<void> | void;
19
+ currentUrl(): string;
20
+ }
21
+ export interface CreateDomDriverOptions extends ElementStateProbe {
22
+ document: Document;
23
+ /** Absent means `DOM_DRIVER_CAPABILITIES`, plus `action:screenshot` when `screenshot` is given. */
24
+ capabilities?: readonly string[];
25
+ clock?: UiClock;
26
+ /** Absent means the document cannot navigate: navigation steps fail with `NAVIGATION_FAILED`. */
27
+ navigation?: DomDriverNavigation;
28
+ screenshot?: (options: {
29
+ target?: UiTarget;
30
+ fullPage?: boolean;
31
+ }) => Promise<string | null> | string | null;
32
+ /** The page never changes between calls (a stored snapshot). */
33
+ staticPage?: boolean;
34
+ /** A snapshot replay: only targets are checked. */
35
+ replay?: boolean;
36
+ /** Resolve targets but never change the page (actions succeed once their target resolves). */
37
+ dryRun?: boolean;
38
+ }
39
+ /** Text a person reads on the page, without hidden or sensitive content, scripts or field values. */
40
+ export declare function safePageText(root: Element | null, probe?: ElementStateProbe): string;
41
+ /** The page's HTML without scripts, event handlers, field values or the content of sensitive elements. */
42
+ export declare function safePageHtml(root: Element | null): string;
43
+ /** Create a desk driver over a document. */
44
+ export declare function createDomDriver(options: CreateDomDriverOptions): UiDriver;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * `@burdenoff/ui-engine/drivers`: desk drivers over a DOM (plan P1-02). The
3
+ * DOM driver runs the P1-01 runtime in the interpreter's own world; the
4
+ * snapshot driver replays a script on a stored tree snapshot (P1-05).
5
+ */
6
+ export { type CreateDomDriverOptions, DOM_DRIVER_CAPABILITIES, type DomDriverNavigation, createDomDriver, safePageHtml, safePageText, } from './dom-driver.js';
7
+ export { type CreateSnapshotDriverOptions, type ReplayUiScriptOnSnapshotOptions, SNAPSHOT_DRIVER_CAPABILITIES, type UiReplayStepVerdict, type UiSnapshotReplayResult, createSnapshotDriver, replayUiScriptOnSnapshot, } from './snapshot-driver.js';
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Snapshot replay (spec 14 "Test a sequence without a robot", plan P1-02 and
3
+ * P1-05): runs a script against a stored tree snapshot, with no browser, to
4
+ * check that every target still resolves, and to exactly one element.
5
+ *
6
+ * The snapshot is rebuilt into an empty, inert document (`hydrateTreeSnapshot`)
7
+ * and the interpreter runs on a DOM driver over it that never changes the page
8
+ * (a dry run), uses a virtual clock (waits cost nothing) and makes one attempt
9
+ * per target (the page cannot change). Verification, paging and waits that are
10
+ * not for a target to appear are skipped, because a single snapshot cannot show
11
+ * what happens after an action.
12
+ *
13
+ * Which steps a snapshot checks:
14
+ * - a snapshot taken at one step of a run (`stepPath`) checks only that step;
15
+ * - otherwise (an element version's snapshot) the steps that use the given
16
+ * element keys (`elementKeys`), or, with neither, every step with a target.
17
+ * Steps that are not checked still run their flow, and report `unchecked`.
18
+ */
19
+ import { type UiDriver, type UiStepContext } from '../interpret/driver.js';
20
+ import { type UiErrorCode } from '../interpret/errors.js';
21
+ import { type RunUiScriptOptions } from '../interpret/run.js';
22
+ import { type UiTreeSnapshot } from '../target/snapshot.js';
23
+ /** A snapshot driver supports every web capability: it only resolves targets. */
24
+ export declare const SNAPSHOT_DRIVER_CAPABILITIES: readonly string[];
25
+ export interface CreateSnapshotDriverOptions {
26
+ /** An empty, inert document to rebuild the snapshot into (a happy-dom or `DOMParser` document). */
27
+ document: Document;
28
+ snapshot: UiTreeSnapshot;
29
+ /** Whether a call of a step resolves its target for real; absent means every step is checked. */
30
+ check?: (context: UiStepContext) => boolean;
31
+ }
32
+ /** A driver over a stored snapshot, and the step paths whose targets it checked. */
33
+ export declare function createSnapshotDriver(options: CreateSnapshotDriverOptions): UiDriver & {
34
+ checkedPaths: Set<string>;
35
+ };
36
+ /** One step's verdict in a replay (contract `UiSnapshotReplay.steps`). */
37
+ export interface UiReplayStepVerdict {
38
+ stepPath: string;
39
+ verdict: 'passed' | 'failed' | 'skipped' | 'unchecked';
40
+ resolvedBy?: string;
41
+ errorCode?: UiErrorCode;
42
+ }
43
+ /** The replay of a script on one snapshot (contract `UiSnapshotReplay`, without the snapshot id). */
44
+ export interface UiSnapshotReplayResult {
45
+ passed: boolean;
46
+ failedStepPath?: string;
47
+ errorCode?: UiErrorCode;
48
+ steps: UiReplayStepVerdict[];
49
+ }
50
+ export interface ReplayUiScriptOnSnapshotOptions extends Pick<RunUiScriptOptions, 'inputs' | 'startAt' | 'stopAfter'> {
51
+ document: Document;
52
+ snapshot: UiTreeSnapshot;
53
+ /** The run step the snapshot was taken at: only that step is checked. */
54
+ stepPath?: string;
55
+ /** Check only the steps whose targets use these element keys. */
56
+ elementKeys?: readonly string[];
57
+ }
58
+ /** Replay a resolved script (compiled, every element with its target) on one snapshot. */
59
+ export declare function replayUiScriptOnSnapshot(script: unknown, options: ReplayUiScriptOnSnapshotOptions): Promise<UiSnapshotReplayResult>;
@@ -0,0 +1,2 @@
1
+ /** `@burdenoff/ui-engine/drivers`: the DOM driver and the snapshot driver with snapshot replay. */
2
+ export * from './drivers/index.js';