@burdenoff/ui-engine 2026.1127.3 → 2026.1127.5
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.
- package/README.md +71 -5
- package/dist/analyze/analyze.d.ts +19 -0
- package/dist/analyze/context.d.ts +40 -0
- package/dist/analyze/index.d.ts +10 -0
- package/dist/analyze/messages.d.ts +39 -0
- package/dist/analyze/rules/fixed-wait.d.ts +6 -0
- package/dist/analyze/rules/hardware-input.d.ts +2 -0
- package/dist/analyze/rules/index.d.ts +3 -0
- package/dist/analyze/rules/inline-target.d.ts +2 -0
- package/dist/analyze/rules/masked-value.d.ts +8 -0
- package/dist/analyze/rules/no-cleanup.d.ts +2 -0
- package/dist/analyze/rules/plain-text-secret.d.ts +2 -0
- package/dist/analyze/rules/rule.d.ts +15 -0
- package/dist/analyze/rules/secret-origin.d.ts +7 -0
- package/dist/analyze/rules/sensitive-screenshot.d.ts +2 -0
- package/dist/analyze/rules/single-method-target.d.ts +2 -0
- package/dist/analyze/rules/unknown-variable.d.ts +2 -0
- package/dist/analyze/rules/unused-value.d.ts +2 -0
- package/dist/analyze/sensitive.d.ts +14 -0
- package/dist/analyze/types.d.ts +66 -0
- package/dist/analyze.d.ts +2 -0
- package/dist/analyze.js +26 -0
- package/dist/dom-runtime.iife.js +1 -1
- package/dist/dom-runtime.js +27 -532
- package/dist/drivers/dom-driver.d.ts +44 -0
- package/dist/drivers/index.d.ts +7 -0
- package/dist/drivers/snapshot-driver.d.ts +59 -0
- package/dist/drivers.d.ts +2 -0
- package/dist/drivers.js +172 -0
- package/dist/index-21hvbvx1.js +340 -0
- package/dist/{index-q1b0j9yr.js → index-5k26keah.js} +58 -592
- package/dist/index-77pcz6n3.js +303 -0
- package/dist/index-8w0f6rsz.js +402 -0
- package/dist/index-9s5nphx0.js +99 -0
- package/dist/index-c88tvyj1.js +743 -0
- package/dist/index-ct2xctrq.js +229 -0
- package/dist/index-g7724awk.js +224 -0
- package/dist/index-gvavb597.js +195 -0
- package/dist/index-r2a9rftv.js +1740 -0
- package/dist/index-s7qdecev.js +489 -0
- package/dist/index-vg8r40y7.js +220 -0
- package/dist/index-xner4tgb.js +810 -0
- package/dist/index-ycs2bz1a.js +589 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +163 -49
- package/dist/interpret/compile.d.ts +58 -0
- package/dist/interpret/driver.d.ts +171 -0
- package/dist/interpret/errors.d.ts +194 -0
- package/dist/interpret/events.d.ts +73 -0
- package/dist/interpret/expr.d.ts +35 -0
- package/dist/interpret/index.d.ts +13 -0
- package/dist/interpret/run.d.ts +77 -0
- package/dist/interpret.d.ts +2 -0
- package/dist/interpret.js +84 -0
- package/dist/script/adapters/browser-action-contract.d.ts +5 -2
- package/dist/script/limits.d.ts +2 -0
- package/dist/script.js +60 -50
- package/dist/target/index.d.ts +1 -1
- package/dist/target/resolve.d.ts +18 -1
- package/dist/target.js +23 -19
- package/dist/testing/fake-web-driver.d.ts +28 -0
- package/dist/testing/index.d.ts +3 -2
- package/dist/testing.js +55 -0
- package/package.json +15 -3
- package/dist/index-zwrxw3zp.js +0 -1988
package/dist/dom-runtime.js
CHANGED
|
@@ -1,535 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "./index-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return element.ownerDocument.defaultView;
|
|
18
|
-
}
|
|
19
|
-
var BUTTONS = { left: 0, middle: 1, right: 2 };
|
|
20
|
-
var PRESSED = { left: 1, middle: 4, right: 2 };
|
|
21
|
-
function pointerInit(element, view, button) {
|
|
22
|
-
const rect = element.getBoundingClientRect();
|
|
23
|
-
return {
|
|
24
|
-
bubbles: true,
|
|
25
|
-
cancelable: true,
|
|
26
|
-
composed: true,
|
|
27
|
-
view,
|
|
28
|
-
button: BUTTONS[button],
|
|
29
|
-
buttons: 0,
|
|
30
|
-
clientX: rect.x + rect.width / 2,
|
|
31
|
-
clientY: rect.y + rect.height / 2,
|
|
32
|
-
pointerId: 1,
|
|
33
|
-
pointerType: "mouse",
|
|
34
|
-
isPrimary: true
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function pointerArrives(element, view, init) {
|
|
38
|
-
const PointerCtor = typeof view.PointerEvent === "function" ? view.PointerEvent : view.MouseEvent;
|
|
39
|
-
const entered = [];
|
|
40
|
-
for (let current = element;current; current = parentAcrossShadow2(current))
|
|
41
|
-
entered.unshift(current);
|
|
42
|
-
const enter = { ...init, bubbles: false };
|
|
43
|
-
element.dispatchEvent(new PointerCtor("pointerover", init));
|
|
44
|
-
for (const target of entered)
|
|
45
|
-
target.dispatchEvent(new PointerCtor("pointerenter", enter));
|
|
46
|
-
element.dispatchEvent(new view.MouseEvent("mouseover", init));
|
|
47
|
-
for (const target of entered)
|
|
48
|
-
target.dispatchEvent(new view.MouseEvent("mouseenter", enter));
|
|
49
|
-
}
|
|
50
|
-
var FOCUSABLE = 'a[href], area[href], button, input, select, textarea, iframe, summary, [tabindex], [contenteditable]:not([contenteditable="false"])';
|
|
51
|
-
function focusOnPress(element, view) {
|
|
52
|
-
for (let current = element;current; current = parentAcrossShadow2(current)) {
|
|
53
|
-
if (current.matches(FOCUSABLE) && isElementEnabled2(current) && current instanceof view.HTMLElement) {
|
|
54
|
-
current.focus();
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const active = element.ownerDocument.activeElement;
|
|
59
|
-
if (active instanceof view.HTMLElement && active !== element.ownerDocument.body)
|
|
60
|
-
active.blur();
|
|
61
|
-
}
|
|
62
|
-
function pointerSequence(element, view, init, button, count) {
|
|
63
|
-
const PointerCtor = typeof view.PointerEvent === "function" ? view.PointerEvent : view.MouseEvent;
|
|
64
|
-
const pressed = { ...init, buttons: PRESSED[button], detail: count };
|
|
65
|
-
const released = { ...init, detail: count };
|
|
66
|
-
pointerArrives(element, view, init);
|
|
67
|
-
const pointerProceeds = element.dispatchEvent(new PointerCtor("pointerdown", pressed));
|
|
68
|
-
const mouseProceeds = pointerProceeds && element.dispatchEvent(new view.MouseEvent("mousedown", pressed));
|
|
69
|
-
if (mouseProceeds)
|
|
70
|
-
focusOnPress(element, view);
|
|
71
|
-
element.dispatchEvent(new PointerCtor("pointerup", released));
|
|
72
|
-
if (pointerProceeds)
|
|
73
|
-
element.dispatchEvent(new view.MouseEvent("mouseup", released));
|
|
74
|
-
}
|
|
75
|
-
function click(element, view, button, count = 1) {
|
|
76
|
-
const init = pointerInit(element, view, button);
|
|
77
|
-
pointerSequence(element, view, init, button, count);
|
|
78
|
-
const terminal = button === "left" ? "click" : button === "right" ? "contextmenu" : "auxclick";
|
|
79
|
-
element.dispatchEvent(new view.MouseEvent(terminal, { ...init, detail: count }));
|
|
80
|
-
}
|
|
81
|
-
function isTextField(element, view) {
|
|
82
|
-
if (element instanceof view.HTMLTextAreaElement)
|
|
83
|
-
return true;
|
|
84
|
-
if (!(element instanceof view.HTMLInputElement))
|
|
85
|
-
return false;
|
|
86
|
-
return !["button", "submit", "reset", "image", "checkbox", "radio", "file", "range", "color", "hidden"].includes(element.type);
|
|
87
|
-
}
|
|
88
|
-
function setFieldValue(element, view, value) {
|
|
89
|
-
const prototype = element instanceof view.HTMLTextAreaElement ? view.HTMLTextAreaElement.prototype : view.HTMLInputElement.prototype;
|
|
90
|
-
const setter = Object.getOwnPropertyDescriptor(prototype, "value")?.set;
|
|
91
|
-
if (setter)
|
|
92
|
-
setter.call(element, value);
|
|
93
|
-
else
|
|
94
|
-
element.value = value;
|
|
95
|
-
element.dispatchEvent(new view.Event("input", { bubbles: true, composed: true }));
|
|
96
|
-
element.dispatchEvent(new view.Event("change", { bubbles: true }));
|
|
97
|
-
}
|
|
98
|
-
function isEditableRegion(element, view) {
|
|
99
|
-
if (!(element instanceof view.HTMLElement))
|
|
100
|
-
return false;
|
|
101
|
-
if (element.isContentEditable)
|
|
102
|
-
return true;
|
|
103
|
-
const editable = element.closest("[contenteditable]")?.getAttribute("contenteditable")?.toLowerCase();
|
|
104
|
-
return editable === "" || editable === "true" || editable === "plaintext-only";
|
|
105
|
-
}
|
|
106
|
-
function typeInto(element, view, text, append) {
|
|
107
|
-
if (text.length > MAX_TYPED_TEXT)
|
|
108
|
-
return { ok: false, problem: "INVALID_ACTION" };
|
|
109
|
-
if (isTextField(element, view)) {
|
|
110
|
-
if (element.readOnly)
|
|
111
|
-
return { ok: false, problem: "NOT_EDITABLE" };
|
|
112
|
-
element.focus();
|
|
113
|
-
setFieldValue(element, view, append ? `${element.value}${text}` : text);
|
|
114
|
-
return { ok: true };
|
|
115
|
-
}
|
|
116
|
-
if (isEditableRegion(element, view)) {
|
|
117
|
-
element.focus();
|
|
118
|
-
element.textContent = append ? `${element.textContent ?? ""}${text}` : text;
|
|
119
|
-
element.dispatchEvent(new view.Event("input", { bubbles: true, composed: true }));
|
|
120
|
-
return { ok: true };
|
|
121
|
-
}
|
|
122
|
-
return { ok: false, problem: "NOT_EDITABLE" };
|
|
123
|
-
}
|
|
124
|
-
function optionLabel(option) {
|
|
125
|
-
const label = option.getAttribute("label");
|
|
126
|
-
return label !== null && label.trim() !== "" ? label : option.textContent ?? "";
|
|
127
|
-
}
|
|
128
|
-
function selectOption(element, view, action) {
|
|
129
|
-
if (!(element instanceof view.HTMLSelectElement))
|
|
130
|
-
return { ok: false, problem: "NOT_SELECTABLE" };
|
|
131
|
-
const options = Array.from(element.options);
|
|
132
|
-
const option = action.value !== undefined ? options.find((candidate) => candidate.value === action.value) : action.label !== undefined ? options.find((candidate) => sameText2(optionLabel(candidate), action.label)) : action.index !== undefined ? options[action.index] : undefined;
|
|
133
|
-
if (!option || option.disabled || option.closest("optgroup")?.hasAttribute("disabled")) {
|
|
134
|
-
return { ok: false, problem: "OPTION_NOT_FOUND" };
|
|
135
|
-
}
|
|
136
|
-
element.focus();
|
|
137
|
-
option.selected = true;
|
|
138
|
-
element.dispatchEvent(new view.Event("input", { bubbles: true, composed: true }));
|
|
139
|
-
element.dispatchEvent(new view.Event("change", { bubbles: true }));
|
|
140
|
-
return { ok: true };
|
|
141
|
-
}
|
|
142
|
-
function setChecked(element, view, checked) {
|
|
143
|
-
if (element instanceof view.HTMLInputElement && (element.type === "checkbox" || element.type === "radio")) {
|
|
144
|
-
if (element.checked !== checked) {
|
|
145
|
-
if (element.type === "radio" && !checked)
|
|
146
|
-
return { ok: false, problem: "NOT_CHECKABLE" };
|
|
147
|
-
click(element, view, "left");
|
|
148
|
-
}
|
|
149
|
-
return element.checked === checked ? { ok: true } : { ok: false, problem: "STATE_NOT_CHANGED" };
|
|
150
|
-
}
|
|
151
|
-
const role = element.getAttribute("role");
|
|
152
|
-
if (role === "checkbox" || role === "switch" || role === "radio" || role === "menuitemcheckbox") {
|
|
153
|
-
const isChecked = () => element.getAttribute("aria-checked") === "true";
|
|
154
|
-
if (isChecked() !== checked)
|
|
155
|
-
click(element, view, "left");
|
|
156
|
-
return isChecked() === checked ? { ok: true } : { ok: false, problem: "STATE_NOT_CHANGED" };
|
|
157
|
-
}
|
|
158
|
-
return { ok: false, problem: "NOT_CHECKABLE" };
|
|
159
|
-
}
|
|
160
|
-
var KEY = /^(?:[\s\S]|[A-Z][A-Za-z0-9]{1,23})$/u;
|
|
161
|
-
function activatesOnEnter(element, view) {
|
|
162
|
-
if (element instanceof view.HTMLButtonElement)
|
|
163
|
-
return true;
|
|
164
|
-
if (element instanceof view.HTMLInputElement)
|
|
165
|
-
return ["submit", "button", "reset", "image"].includes(element.type);
|
|
166
|
-
const tag = element.localName;
|
|
167
|
-
return tag === "a" && element.hasAttribute("href") || tag === "summary";
|
|
168
|
-
}
|
|
169
|
-
function activatesOnSpace(element, view) {
|
|
170
|
-
if (element instanceof view.HTMLButtonElement)
|
|
171
|
-
return true;
|
|
172
|
-
if (element instanceof view.HTMLInputElement) {
|
|
173
|
-
return ["submit", "button", "reset", "image", "checkbox", "radio"].includes(element.type);
|
|
174
|
-
}
|
|
175
|
-
return element.localName === "summary";
|
|
176
|
-
}
|
|
177
|
-
function keyboardClick(element, view) {
|
|
178
|
-
element.dispatchEvent(new view.MouseEvent("click", { bubbles: true, cancelable: true, composed: true, view, detail: 0 }));
|
|
179
|
-
}
|
|
180
|
-
function pressKey(element, view, key) {
|
|
181
|
-
if (!KEY.test(key))
|
|
182
|
-
return { ok: false, problem: "INVALID_ACTION" };
|
|
183
|
-
const eventKey = key === "Space" ? " " : key;
|
|
184
|
-
if (element instanceof view.HTMLElement)
|
|
185
|
-
element.focus();
|
|
186
|
-
const init = { key: eventKey, bubbles: true, cancelable: true, composed: true };
|
|
187
|
-
const downProceeds = element.dispatchEvent(new view.KeyboardEvent("keydown", init));
|
|
188
|
-
if (eventKey === "Enter" && downProceeds) {
|
|
189
|
-
if (activatesOnEnter(element, view))
|
|
190
|
-
keyboardClick(element, view);
|
|
191
|
-
else if (element instanceof view.HTMLInputElement && isTextField(element, view) && element.form) {
|
|
192
|
-
implicitSubmit(element.form, view);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
const upProceeds = element.dispatchEvent(new view.KeyboardEvent("keyup", init));
|
|
196
|
-
if (eventKey === " " && downProceeds && upProceeds && activatesOnSpace(element, view))
|
|
197
|
-
keyboardClick(element, view);
|
|
198
|
-
return { ok: true };
|
|
199
|
-
}
|
|
200
|
-
var SUBMIT_INPUTS = new Set(["submit", "image"]);
|
|
201
|
-
var BLOCKING_INPUTS = new Set([
|
|
202
|
-
"text",
|
|
203
|
-
"search",
|
|
204
|
-
"url",
|
|
205
|
-
"tel",
|
|
206
|
-
"email",
|
|
207
|
-
"password",
|
|
208
|
-
"date",
|
|
209
|
-
"month",
|
|
210
|
-
"week",
|
|
211
|
-
"time",
|
|
212
|
-
"datetime-local",
|
|
213
|
-
"number"
|
|
214
|
-
]);
|
|
215
|
-
function implicitSubmit(form, view) {
|
|
216
|
-
const controls = Array.from(form.elements);
|
|
217
|
-
const root = form.getRootNode();
|
|
218
|
-
const defaultButton = Array.from(root.querySelectorAll("button, input")).find((control) => (control instanceof view.HTMLButtonElement && control.type === "submit" || control instanceof view.HTMLInputElement && SUBMIT_INPUTS.has(control.type)) && control.form === form);
|
|
219
|
-
if (defaultButton) {
|
|
220
|
-
if (isElementEnabled2(defaultButton))
|
|
221
|
-
keyboardClick(defaultButton, view);
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
const blocking = controls.filter((control) => control instanceof view.HTMLInputElement && BLOCKING_INPUTS.has(control.type));
|
|
225
|
-
if (blocking.length === 1)
|
|
226
|
-
form.requestSubmit();
|
|
227
|
-
}
|
|
228
|
-
function readValue(element, view) {
|
|
229
|
-
if (element instanceof view.HTMLInputElement && (element.type === "checkbox" || element.type === "radio")) {
|
|
230
|
-
return element.checked;
|
|
231
|
-
}
|
|
232
|
-
if (element instanceof view.HTMLInputElement || element instanceof view.HTMLTextAreaElement || element instanceof view.HTMLSelectElement) {
|
|
233
|
-
return element.value.slice(0, MAX_READ_TEXT);
|
|
234
|
-
}
|
|
235
|
-
const checked = element.getAttribute("aria-checked");
|
|
236
|
-
if (checked === "true" || checked === "false")
|
|
237
|
-
return checked === "true";
|
|
238
|
-
return element.getAttribute("aria-valuenow") ?? element.getAttribute("aria-valuetext");
|
|
239
|
-
}
|
|
240
|
-
var ATTRIBUTE_NAME = /^[A-Za-z_][\w:.-]{0,127}$/;
|
|
241
|
-
function performDomAction(element, action) {
|
|
242
|
-
const view = viewOf(element);
|
|
243
|
-
if (!view)
|
|
244
|
-
return { ok: false, problem: "INVALID_ACTION" };
|
|
245
|
-
switch (action.kind) {
|
|
246
|
-
case "click":
|
|
247
|
-
click(element, view, action.button ?? "left");
|
|
248
|
-
return { ok: true };
|
|
249
|
-
case "doubleClick":
|
|
250
|
-
click(element, view, "left", 1);
|
|
251
|
-
click(element, view, "left", 2);
|
|
252
|
-
element.dispatchEvent(new view.MouseEvent("dblclick", { ...pointerInit(element, view, "left"), detail: 2 }));
|
|
253
|
-
return { ok: true };
|
|
254
|
-
case "hover": {
|
|
255
|
-
const init = pointerInit(element, view, "left");
|
|
256
|
-
const PointerCtor = typeof view.PointerEvent === "function" ? view.PointerEvent : view.MouseEvent;
|
|
257
|
-
pointerArrives(element, view, init);
|
|
258
|
-
element.dispatchEvent(new PointerCtor("pointermove", init));
|
|
259
|
-
element.dispatchEvent(new view.MouseEvent("mousemove", init));
|
|
260
|
-
return { ok: true };
|
|
261
|
-
}
|
|
262
|
-
case "focus":
|
|
263
|
-
if (element instanceof view.HTMLElement)
|
|
264
|
-
element.focus();
|
|
265
|
-
return { ok: true };
|
|
266
|
-
case "type":
|
|
267
|
-
return typeof action.text === "string" ? typeInto(element, view, action.text, action.append === true) : { ok: false, problem: "INVALID_ACTION" };
|
|
268
|
-
case "clear":
|
|
269
|
-
return typeInto(element, view, "", false);
|
|
270
|
-
case "select":
|
|
271
|
-
return selectOption(element, view, action);
|
|
272
|
-
case "check":
|
|
273
|
-
return setChecked(element, view, action.checked === true);
|
|
274
|
-
case "pressKey":
|
|
275
|
-
return typeof action.key === "string" ? pressKey(element, view, action.key) : { ok: false, problem: "INVALID_ACTION" };
|
|
276
|
-
case "scroll":
|
|
277
|
-
element.scrollBy?.({ left: Number(action.dx ?? 0) || 0, top: Number(action.dy ?? 0) || 0 });
|
|
278
|
-
return { ok: true };
|
|
279
|
-
case "scrollIntoView":
|
|
280
|
-
element.scrollIntoView?.({ block: "center", inline: "nearest" });
|
|
281
|
-
return { ok: true };
|
|
282
|
-
case "getText":
|
|
283
|
-
if (isSensitiveElement2(element))
|
|
284
|
-
return { ok: false, problem: "SENSITIVE_ELEMENT" };
|
|
285
|
-
return { ok: true, value: visibleText2(element).slice(0, MAX_READ_TEXT) };
|
|
286
|
-
case "getValue":
|
|
287
|
-
if (isSensitiveElement2(element))
|
|
288
|
-
return { ok: false, problem: "SENSITIVE_ELEMENT" };
|
|
289
|
-
return { ok: true, value: readValue(element, view) };
|
|
290
|
-
case "getAttribute": {
|
|
291
|
-
if (typeof action.name !== "string" || !ATTRIBUTE_NAME.test(action.name))
|
|
292
|
-
return { ok: false, problem: "INVALID_ACTION" };
|
|
293
|
-
const name = action.name.toLowerCase();
|
|
294
|
-
if (isSensitiveElement2(element))
|
|
295
|
-
return { ok: false, problem: "SENSITIVE_ELEMENT" };
|
|
296
|
-
return { ok: true, value: element.getAttribute(name)?.slice(0, MAX_READ_TEXT) ?? null };
|
|
297
|
-
}
|
|
298
|
-
case "exists":
|
|
299
|
-
return { ok: true, value: true };
|
|
300
|
-
default:
|
|
301
|
-
return { ok: false, problem: "INVALID_ACTION" };
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// src/dom-runtime/runtime.ts
|
|
306
|
-
var DOM_RUNTIME_VERSION = 1;
|
|
307
|
-
var DOM_RUNTIME_GLOBAL = "__burdenoffUiRuntime";
|
|
308
|
-
var MAX_HIGHLIGHT_MS = 60000;
|
|
309
|
-
var HIGHLIGHT_HOST_TAG = "fg-ui-highlight";
|
|
310
|
-
var METHOD_KINDS = new Set(["role", "css", "testId", "xpath", "fuzzy", "anchor", "text"]);
|
|
311
|
-
function isRuntimeTarget(value) {
|
|
312
|
-
if (!value || typeof value !== "object")
|
|
313
|
-
return false;
|
|
314
|
-
const target = value;
|
|
315
|
-
if (!Array.isArray(target.methods) || target.methods.length === 0 || target.methods.length > 8)
|
|
316
|
-
return false;
|
|
317
|
-
if (target.frame !== undefined && !(Array.isArray(target.frame) && target.frame.every((item) => typeof item === "string"))) {
|
|
318
|
-
return false;
|
|
319
|
-
}
|
|
320
|
-
return target.methods.every((method) => !!method && typeof method === "object" && METHOD_KINDS.has(String(method.kind)));
|
|
321
|
-
}
|
|
322
|
-
function invalidTarget() {
|
|
323
|
-
return { status: "failed", code: "ELEMENT_NOT_FOUND", candidates: [], candidateCount: 0, attempts: [] };
|
|
324
|
-
}
|
|
325
|
-
function withoutElement(found) {
|
|
326
|
-
return {
|
|
327
|
-
status: found.status,
|
|
328
|
-
method: found.method,
|
|
329
|
-
methodIndex: found.methodIndex,
|
|
330
|
-
fallback: found.fallback,
|
|
331
|
-
candidate: found.candidate,
|
|
332
|
-
attempts: found.attempts
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
function frameElementOf(document) {
|
|
336
|
-
try {
|
|
337
|
-
return document.defaultView?.frameElement ?? null;
|
|
338
|
-
} catch {
|
|
339
|
-
return null;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
function coveredAt(current, x, y, labels) {
|
|
343
|
-
const root = current.getRootNode();
|
|
344
|
-
if (typeof root.elementFromPoint !== "function")
|
|
345
|
-
return null;
|
|
346
|
-
const top = root.elementFromPoint(x, y);
|
|
347
|
-
if (!top)
|
|
348
|
-
return "offscreen";
|
|
349
|
-
if (top === current || current.contains(top))
|
|
350
|
-
return null;
|
|
351
|
-
return labels.some((label) => label.contains(top)) ? null : "covered";
|
|
352
|
-
}
|
|
353
|
-
function coverage(element, rect) {
|
|
354
|
-
let x = rect.x + rect.width / 2;
|
|
355
|
-
let y = rect.y + rect.height / 2;
|
|
356
|
-
const labels = Array.from(element.labels ?? []);
|
|
357
|
-
let current = element;
|
|
358
|
-
for (let hop = 0;hop < 32; hop += 1) {
|
|
359
|
-
const blocked = coveredAt(current, x, y, hop === 0 ? labels : []);
|
|
360
|
-
if (blocked)
|
|
361
|
-
return blocked;
|
|
362
|
-
const root = current.getRootNode();
|
|
363
|
-
if (root && "host" in root) {
|
|
364
|
-
current = root.host;
|
|
365
|
-
continue;
|
|
366
|
-
}
|
|
367
|
-
const frame = frameElementOf(current.ownerDocument);
|
|
368
|
-
if (!frame)
|
|
369
|
-
return null;
|
|
370
|
-
const box = frame.getBoundingClientRect();
|
|
371
|
-
x += box.x + frame.clientLeft;
|
|
372
|
-
y += box.y + frame.clientTop;
|
|
373
|
-
current = frame;
|
|
374
|
-
}
|
|
375
|
-
return null;
|
|
376
|
-
}
|
|
377
|
-
function outsideViewport(element, rect) {
|
|
378
|
-
const view = element.ownerDocument.defaultView;
|
|
379
|
-
if (!view)
|
|
380
|
-
return false;
|
|
381
|
-
const x = rect.x + rect.width / 2;
|
|
382
|
-
const y = rect.y + rect.height / 2;
|
|
383
|
-
return x < 0 || y < 0 || x >= view.innerWidth || y >= view.innerHeight;
|
|
384
|
-
}
|
|
385
|
-
function pointerBlock(element) {
|
|
386
|
-
const view = element.ownerDocument.defaultView;
|
|
387
|
-
if (view && view.getComputedStyle(element).pointerEvents === "none")
|
|
388
|
-
return "noPointerEvents";
|
|
389
|
-
let rect = element.getBoundingClientRect();
|
|
390
|
-
if (rect.width <= 0 || rect.height <= 0)
|
|
391
|
-
return null;
|
|
392
|
-
if (outsideViewport(element, rect) && typeof element.scrollIntoView === "function") {
|
|
393
|
-
element.scrollIntoView({ block: "center", inline: "center" });
|
|
394
|
-
rect = element.getBoundingClientRect();
|
|
395
|
-
}
|
|
396
|
-
return coverage(element, rect);
|
|
397
|
-
}
|
|
398
|
-
function createDomRuntime(document, options = {}) {
|
|
399
|
-
const root = options.root ?? document;
|
|
400
|
-
const probe = {
|
|
401
|
-
...options.rectOf ? { rectOf: options.rectOf } : {},
|
|
402
|
-
...options.isVisible ? { isVisible: options.isVisible } : {}
|
|
403
|
-
};
|
|
404
|
-
let overlay = null;
|
|
405
|
-
let clearTimer = null;
|
|
406
|
-
const clearHighlight = () => {
|
|
407
|
-
if (clearTimer !== null) {
|
|
408
|
-
clearTimeout(clearTimer);
|
|
409
|
-
clearTimer = null;
|
|
410
|
-
}
|
|
411
|
-
overlay?.remove();
|
|
412
|
-
overlay = null;
|
|
413
|
-
};
|
|
414
|
-
const resolveRaw = (target, state) => {
|
|
415
|
-
clearHighlight();
|
|
416
|
-
return resolveWebTarget2(root, target, { ...probe, ...state ? { state } : {} });
|
|
417
|
-
};
|
|
418
|
-
const resolve = (target, resolveOptions = {}) => {
|
|
419
|
-
if (!isRuntimeTarget(target))
|
|
420
|
-
return invalidTarget();
|
|
421
|
-
const result = resolveRaw(target, resolveOptions.state);
|
|
422
|
-
return result.status === "found" ? withoutElement(result) : result;
|
|
423
|
-
};
|
|
424
|
-
const act = (target, action, actOptions = {}) => {
|
|
425
|
-
if (!action || typeof action !== "object" || typeof action.kind !== "string") {
|
|
426
|
-
return { ok: false, code: "INVALID_ACTION" };
|
|
427
|
-
}
|
|
428
|
-
if (!isRuntimeTarget(target)) {
|
|
429
|
-
return { ok: false, code: "ELEMENT_NOT_FOUND", resolution: invalidTarget() };
|
|
430
|
-
}
|
|
431
|
-
const state = actOptions.state ?? (READ_ACTIONS.has(action.kind) ? "visible" : "interactable");
|
|
432
|
-
const result = resolveRaw(target, state);
|
|
433
|
-
if (result.status !== "found") {
|
|
434
|
-
if (action.kind === "exists" && result.code === "ELEMENT_NOT_FOUND") {
|
|
435
|
-
return { ok: true, value: false, resolution: result };
|
|
436
|
-
}
|
|
437
|
-
return { ok: false, code: result.code, resolution: result };
|
|
438
|
-
}
|
|
439
|
-
const resolution = withoutElement(result);
|
|
440
|
-
const blocked = POINTER_ACTIONS.has(action.kind) ? pointerBlock(result.element) : null;
|
|
441
|
-
if (blocked) {
|
|
442
|
-
return {
|
|
443
|
-
ok: false,
|
|
444
|
-
code: "ELEMENT_NOT_INTERACTABLE",
|
|
445
|
-
reason: blocked,
|
|
446
|
-
resolution: {
|
|
447
|
-
status: "failed",
|
|
448
|
-
code: "ELEMENT_NOT_INTERACTABLE",
|
|
449
|
-
candidates: [result.candidate],
|
|
450
|
-
candidateCount: 1,
|
|
451
|
-
attempts: result.attempts
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
const outcome = performDomAction(result.element, action);
|
|
456
|
-
if (!outcome.ok)
|
|
457
|
-
return { ok: false, code: outcome.problem, resolution };
|
|
458
|
-
return outcome.value === undefined ? { ok: true, resolution } : { ok: true, resolution, value: outcome.value };
|
|
459
|
-
};
|
|
460
|
-
const drawBoxes = (boxes, label, numbered) => {
|
|
461
|
-
const host = document.createElement(HIGHLIGHT_HOST_TAG);
|
|
462
|
-
host.setAttribute("aria-hidden", "true");
|
|
463
|
-
host.setAttribute("style", "all: initial; position: fixed; inset: 0; pointer-events: none; z-index: 2147483647;");
|
|
464
|
-
const shadow = host.attachShadow({ mode: "closed" });
|
|
465
|
-
boxes.forEach((box, index) => {
|
|
466
|
-
const frame = document.createElement("div");
|
|
467
|
-
frame.setAttribute("style", `position: fixed; left: ${box.bounds.x - 3}px; top: ${box.bounds.y - 3}px; width: ${box.bounds.width + 6}px; height: ${box.bounds.height + 6}px; outline: 3px solid Highlight; border-radius: 4px; box-sizing: border-box;`);
|
|
468
|
-
const caption = numbered ? `${index + 1}${label ? ` ${label}` : ""}` : label;
|
|
469
|
-
if (caption) {
|
|
470
|
-
const tag = document.createElement("span");
|
|
471
|
-
tag.textContent = caption.slice(0, 120);
|
|
472
|
-
tag.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;");
|
|
473
|
-
frame.appendChild(tag);
|
|
474
|
-
}
|
|
475
|
-
shadow.appendChild(frame);
|
|
476
|
-
});
|
|
477
|
-
document.documentElement.appendChild(host);
|
|
478
|
-
overlay = host;
|
|
479
|
-
};
|
|
480
|
-
const highlight = (target, highlightOptions = {}) => {
|
|
481
|
-
if (!isRuntimeTarget(target))
|
|
482
|
-
return invalidTarget();
|
|
483
|
-
const result = resolveRaw(target, highlightOptions.state ?? "visible");
|
|
484
|
-
if (result.status === "found")
|
|
485
|
-
drawBoxes([result.candidate], highlightOptions.label, false);
|
|
486
|
-
else if (result.candidates.length > 0)
|
|
487
|
-
drawBoxes(result.candidates, highlightOptions.label, true);
|
|
488
|
-
const duration = Math.min(MAX_HIGHLIGHT_MS, Math.max(0, Number(highlightOptions.durationMs ?? 0) || 0));
|
|
489
|
-
if (overlay && duration > 0)
|
|
490
|
-
clearTimer = setTimeout(clearHighlight, duration);
|
|
491
|
-
return result.status === "found" ? withoutElement(result) : result;
|
|
492
|
-
};
|
|
493
|
-
return {
|
|
494
|
-
version: DOM_RUNTIME_VERSION,
|
|
495
|
-
resolve,
|
|
496
|
-
act,
|
|
497
|
-
highlight,
|
|
498
|
-
clearHighlight,
|
|
499
|
-
snapshot: (snapshotOptions = {}) => {
|
|
500
|
-
clearHighlight();
|
|
501
|
-
return serializeTreeSnapshot2(document, {
|
|
502
|
-
...probe,
|
|
503
|
-
...snapshotOptions.maxNodes ? { maxNodes: snapshotOptions.maxNodes } : {}
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
function installDomRuntime(scope, document) {
|
|
509
|
-
const existing = Reflect.get(scope, DOM_RUNTIME_GLOBAL);
|
|
510
|
-
if (existing && typeof existing === "object" && typeof existing.version === "number" && existing.version >= DOM_RUNTIME_VERSION) {
|
|
511
|
-
return existing;
|
|
512
|
-
}
|
|
513
|
-
const runtime = Object.freeze(createDomRuntime(document));
|
|
514
|
-
Object.defineProperty(scope, DOM_RUNTIME_GLOBAL, {
|
|
515
|
-
value: runtime,
|
|
516
|
-
configurable: true,
|
|
517
|
-
enumerable: false,
|
|
518
|
-
writable: false
|
|
519
|
-
});
|
|
520
|
-
return runtime;
|
|
521
|
-
}
|
|
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";
|
|
522
17
|
export {
|
|
523
|
-
DOM_RUNTIME_GLOBAL,
|
|
524
|
-
DOM_RUNTIME_VERSION,
|
|
525
|
-
HIGHLIGHT_HOST_TAG,
|
|
526
|
-
MAX_HIGHLIGHT_MS,
|
|
527
|
-
MAX_READ_TEXT,
|
|
528
|
-
MAX_TYPED_TEXT,
|
|
529
|
-
POINTER_ACTIONS,
|
|
530
|
-
READ_ACTIONS,
|
|
531
|
-
createDomRuntime,
|
|
532
|
-
installDomRuntime,
|
|
533
|
-
isRuntimeTarget,
|
|
534
|
-
performDomAction
|
|
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
|
|
535
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>;
|