@burdenoff/ui-engine 2026.1127.2 → 2026.1127.3
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 +33 -3
- package/dist/capture.js +3 -2
- package/dist/dom-runtime/actions.d.ts +65 -0
- package/dist/dom-runtime/iife.d.ts +1 -0
- package/dist/dom-runtime/index.d.ts +7 -0
- package/dist/dom-runtime/runtime.d.ts +79 -0
- package/dist/dom-runtime.d.ts +2 -0
- package/dist/dom-runtime.iife.js +1 -0
- package/dist/dom-runtime.js +535 -0
- package/dist/{index-n5amgh31.js → index-2kgsgn1c.js} +1 -1
- package/dist/{index-phd8yhyg.js → index-bnvmt4wf.js} +7 -5
- package/dist/{index-c6pmt2rg.js → index-cs6acyjn.js} +6 -59
- package/dist/index-mgztm37r.js +57 -0
- package/dist/index-q1b0j9yr.js +1349 -0
- package/dist/{index-tqffkt91.js → index-zwrxw3zp.js} +5 -3
- package/dist/index.js +8 -6
- package/dist/recording.js +1 -1
- package/dist/replay.js +2 -2
- package/dist/script.js +2 -2
- package/dist/target/aria.d.ts +31 -0
- package/dist/target/dom.d.ts +35 -0
- package/dist/target/index.d.ts +13 -0
- package/dist/target/markers.d.ts +18 -0
- package/dist/target/methods.d.ts +52 -0
- package/dist/target/resolve.d.ts +46 -0
- package/dist/target/snapshot.d.ts +57 -0
- package/dist/target/text.d.ts +23 -0
- package/dist/target/types.d.ts +88 -0
- package/dist/target.d.ts +2 -0
- package/dist/target.js +92 -0
- package/dist/testing/fixtures/ambiguous.d.ts +7 -0
- package/dist/testing/fixtures/iframe.d.ts +6 -0
- package/dist/testing/fixtures/index.d.ts +26 -0
- package/dist/testing/fixtures/invoices-v2.d.ts +8 -0
- package/dist/testing/fixtures/invoices-v3.d.ts +7 -0
- package/dist/testing/fixtures/invoices.d.ts +6 -0
- package/dist/testing/fixtures/login.d.ts +6 -0
- package/dist/testing/fixtures/shadow.d.ts +7 -0
- package/dist/testing/index.d.ts +6 -0
- package/dist/testing/mount.d.ts +18 -0
- package/dist/testing.d.ts +2 -0
- package/dist/testing.js +324 -0
- package/package.json +21 -5
|
@@ -0,0 +1,1349 @@
|
|
|
1
|
+
import {
|
|
2
|
+
REDACTED2,
|
|
3
|
+
redactCredentials2,
|
|
4
|
+
containsCredential,
|
|
5
|
+
decodeUriText,
|
|
6
|
+
containsCredentialInUrl
|
|
7
|
+
} from "./index-mgztm37r.js";
|
|
8
|
+
|
|
9
|
+
// src/target/types.ts
|
|
10
|
+
var WEB_TARGET_ERROR_CODES2 = ["ELEMENT_NOT_FOUND", "ELEMENT_AMBIGUOUS", "ELEMENT_NOT_INTERACTABLE"];
|
|
11
|
+
var MAX_CANDIDATES2 = 5;
|
|
12
|
+
var MAX_CANDIDATE_NAME2 = 200;
|
|
13
|
+
|
|
14
|
+
// src/target/markers.ts
|
|
15
|
+
var SENSITIVE_MARKERS2 = ["data-fg-sensitive", "data-sensitive", "data-private"];
|
|
16
|
+
function hasSensitiveMarker2(element) {
|
|
17
|
+
return SENSITIVE_MARKERS2.some((marker) => element.hasAttribute(marker));
|
|
18
|
+
}
|
|
19
|
+
function assignedSlotOf(element) {
|
|
20
|
+
const native = element.assignedSlot;
|
|
21
|
+
if (native !== undefined)
|
|
22
|
+
return native;
|
|
23
|
+
const shadow = element.parentElement?.shadowRoot;
|
|
24
|
+
if (!shadow)
|
|
25
|
+
return null;
|
|
26
|
+
for (const slot of Array.from(shadow.querySelectorAll("slot"))) {
|
|
27
|
+
const assigned = typeof slot.assignedNodes === "function" ? slot.assignedNodes() : [];
|
|
28
|
+
if (assigned.includes(element))
|
|
29
|
+
return slot;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
function containerOf(element) {
|
|
34
|
+
const slot = assignedSlotOf(element);
|
|
35
|
+
if (slot)
|
|
36
|
+
return slot;
|
|
37
|
+
if (element.parentElement)
|
|
38
|
+
return element.parentElement;
|
|
39
|
+
const root = element.getRootNode();
|
|
40
|
+
if (root && "host" in root)
|
|
41
|
+
return root.host;
|
|
42
|
+
try {
|
|
43
|
+
return element.ownerDocument.defaultView?.frameElement ?? null;
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function isMarkedSensitive(element) {
|
|
49
|
+
for (let current = element;current; current = containerOf(current)) {
|
|
50
|
+
if (hasSensitiveMarker2(current))
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/target/text.ts
|
|
57
|
+
var MAX_COMPARED_TEXT2 = 256;
|
|
58
|
+
function normaliseText2(value) {
|
|
59
|
+
return (value ?? "").normalize("NFKC").replace(/\s+/g, " ").trim().toLowerCase();
|
|
60
|
+
}
|
|
61
|
+
function sameText2(a, b) {
|
|
62
|
+
return normaliseText2(a) === normaliseText2(b);
|
|
63
|
+
}
|
|
64
|
+
function containsText2(haystack, needle) {
|
|
65
|
+
const wanted = normaliseText2(needle);
|
|
66
|
+
return wanted.length > 0 && normaliseText2(haystack).includes(wanted);
|
|
67
|
+
}
|
|
68
|
+
function editDistance2(a, b) {
|
|
69
|
+
if (a === b)
|
|
70
|
+
return 0;
|
|
71
|
+
if (a.length === 0)
|
|
72
|
+
return b.length;
|
|
73
|
+
if (b.length === 0)
|
|
74
|
+
return a.length;
|
|
75
|
+
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
76
|
+
for (let i = 1;i <= a.length; i += 1) {
|
|
77
|
+
const current = [i];
|
|
78
|
+
for (let j = 1;j <= b.length; j += 1) {
|
|
79
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
80
|
+
current[j] = Math.min((previous[j] ?? 0) + 1, (current[j - 1] ?? 0) + 1, (previous[j - 1] ?? 0) + cost);
|
|
81
|
+
}
|
|
82
|
+
previous = current;
|
|
83
|
+
}
|
|
84
|
+
return previous[b.length] ?? 0;
|
|
85
|
+
}
|
|
86
|
+
function textSimilarity2(a, b) {
|
|
87
|
+
const left = normaliseText2(a).slice(0, MAX_COMPARED_TEXT2);
|
|
88
|
+
const right = normaliseText2(b).slice(0, MAX_COMPARED_TEXT2);
|
|
89
|
+
const longest = Math.max(left.length, right.length);
|
|
90
|
+
if (longest === 0)
|
|
91
|
+
return 0;
|
|
92
|
+
return 1 - editDistance2(left, right) / longest;
|
|
93
|
+
}
|
|
94
|
+
function clip2(value, max) {
|
|
95
|
+
return value.length <= max ? value : `${value.slice(0, Math.max(0, max - 1))}…`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/target/aria.ts
|
|
99
|
+
var MAX_NAME_LENGTH3 = 512;
|
|
100
|
+
var MAX_VISIBLE_TEXT2 = 65536;
|
|
101
|
+
var INPUT_ROLES = {
|
|
102
|
+
button: "button",
|
|
103
|
+
submit: "button",
|
|
104
|
+
reset: "button",
|
|
105
|
+
image: "button",
|
|
106
|
+
checkbox: "checkbox",
|
|
107
|
+
radio: "radio",
|
|
108
|
+
range: "slider",
|
|
109
|
+
number: "spinbutton",
|
|
110
|
+
search: "searchbox",
|
|
111
|
+
email: "textbox",
|
|
112
|
+
tel: "textbox",
|
|
113
|
+
text: "textbox",
|
|
114
|
+
url: "textbox",
|
|
115
|
+
password: "textbox",
|
|
116
|
+
date: "textbox",
|
|
117
|
+
"datetime-local": "textbox",
|
|
118
|
+
month: "textbox",
|
|
119
|
+
time: "textbox",
|
|
120
|
+
week: "textbox",
|
|
121
|
+
color: "textbox",
|
|
122
|
+
file: "button"
|
|
123
|
+
};
|
|
124
|
+
var TAG_ROLES = {
|
|
125
|
+
article: "article",
|
|
126
|
+
aside: "complementary",
|
|
127
|
+
button: "button",
|
|
128
|
+
datalist: "listbox",
|
|
129
|
+
dd: "definition",
|
|
130
|
+
details: "group",
|
|
131
|
+
dialog: "dialog",
|
|
132
|
+
dt: "term",
|
|
133
|
+
fieldset: "group",
|
|
134
|
+
figure: "figure",
|
|
135
|
+
h1: "heading",
|
|
136
|
+
h2: "heading",
|
|
137
|
+
h3: "heading",
|
|
138
|
+
h4: "heading",
|
|
139
|
+
h5: "heading",
|
|
140
|
+
h6: "heading",
|
|
141
|
+
hr: "separator",
|
|
142
|
+
li: "listitem",
|
|
143
|
+
main: "main",
|
|
144
|
+
menu: "list",
|
|
145
|
+
meter: "meter",
|
|
146
|
+
nav: "navigation",
|
|
147
|
+
ol: "list",
|
|
148
|
+
optgroup: "group",
|
|
149
|
+
option: "option",
|
|
150
|
+
output: "status",
|
|
151
|
+
p: "paragraph",
|
|
152
|
+
progress: "progressbar",
|
|
153
|
+
summary: "button",
|
|
154
|
+
table: "table",
|
|
155
|
+
tbody: "rowgroup",
|
|
156
|
+
td: "cell",
|
|
157
|
+
textarea: "textbox",
|
|
158
|
+
tfoot: "rowgroup",
|
|
159
|
+
thead: "rowgroup",
|
|
160
|
+
tr: "row",
|
|
161
|
+
ul: "list"
|
|
162
|
+
};
|
|
163
|
+
var NAME_FROM_CONTENT = new Set([
|
|
164
|
+
"button",
|
|
165
|
+
"cell",
|
|
166
|
+
"checkbox",
|
|
167
|
+
"columnheader",
|
|
168
|
+
"gridcell",
|
|
169
|
+
"heading",
|
|
170
|
+
"link",
|
|
171
|
+
"menuitem",
|
|
172
|
+
"menuitemcheckbox",
|
|
173
|
+
"menuitemradio",
|
|
174
|
+
"option",
|
|
175
|
+
"radio",
|
|
176
|
+
"row",
|
|
177
|
+
"rowheader",
|
|
178
|
+
"switch",
|
|
179
|
+
"tab",
|
|
180
|
+
"tooltip",
|
|
181
|
+
"treeitem"
|
|
182
|
+
]);
|
|
183
|
+
var LABELABLE = new Set(["button", "input", "meter", "output", "progress", "select", "textarea"]);
|
|
184
|
+
var SKIPPED_CONTENT = new Set(["script", "style", "noscript", "template", "head", "title", "meta", "link"]);
|
|
185
|
+
function tagOf(element) {
|
|
186
|
+
return element.localName.toLowerCase();
|
|
187
|
+
}
|
|
188
|
+
function hasSectioningAncestor(element) {
|
|
189
|
+
return element.parentElement?.closest("article, aside, main, nav, section") != null;
|
|
190
|
+
}
|
|
191
|
+
function implicitRole(element) {
|
|
192
|
+
const tag = tagOf(element);
|
|
193
|
+
switch (tag) {
|
|
194
|
+
case "a":
|
|
195
|
+
case "area":
|
|
196
|
+
return element.hasAttribute("href") ? "link" : "";
|
|
197
|
+
case "input": {
|
|
198
|
+
const type = (element.getAttribute("type") ?? "text").toLowerCase();
|
|
199
|
+
if (type === "hidden")
|
|
200
|
+
return "";
|
|
201
|
+
if (element.hasAttribute("list") && ["text", "search", "email", "tel", "url"].includes(type))
|
|
202
|
+
return "combobox";
|
|
203
|
+
return INPUT_ROLES[type] ?? "textbox";
|
|
204
|
+
}
|
|
205
|
+
case "select": {
|
|
206
|
+
const size = Number(element.getAttribute("size") ?? "0");
|
|
207
|
+
return element.hasAttribute("multiple") || size > 1 ? "listbox" : "combobox";
|
|
208
|
+
}
|
|
209
|
+
case "img": {
|
|
210
|
+
const alt = element.getAttribute("alt");
|
|
211
|
+
return alt === "" ? "presentation" : "img";
|
|
212
|
+
}
|
|
213
|
+
case "th":
|
|
214
|
+
return element.getAttribute("scope") === "row" ? "rowheader" : "columnheader";
|
|
215
|
+
case "header":
|
|
216
|
+
return hasSectioningAncestor(element) ? "" : "banner";
|
|
217
|
+
case "footer":
|
|
218
|
+
return hasSectioningAncestor(element) ? "" : "contentinfo";
|
|
219
|
+
case "section":
|
|
220
|
+
case "form":
|
|
221
|
+
return element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby") ? tag === "form" ? "form" : "region" : "";
|
|
222
|
+
default:
|
|
223
|
+
return TAG_ROLES[tag] ?? "";
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function roleOf2(element) {
|
|
227
|
+
const explicit = element.getAttribute("role")?.trim().split(/\s+/)[0];
|
|
228
|
+
return explicit ? explicit.toLowerCase() : implicitRole(element);
|
|
229
|
+
}
|
|
230
|
+
function byId(element, id) {
|
|
231
|
+
const root = element.getRootNode();
|
|
232
|
+
return typeof root.getElementById === "function" ? root.getElementById(id) : null;
|
|
233
|
+
}
|
|
234
|
+
function isHiddenForName(element) {
|
|
235
|
+
return element.hasAttribute("hidden") || element.getAttribute("aria-hidden") === "true";
|
|
236
|
+
}
|
|
237
|
+
function cssHiding(element) {
|
|
238
|
+
const view = element.ownerDocument.defaultView;
|
|
239
|
+
if (!view)
|
|
240
|
+
return "none";
|
|
241
|
+
const style = view.getComputedStyle(element);
|
|
242
|
+
if (style.display === "none")
|
|
243
|
+
return "subtree";
|
|
244
|
+
return style.visibility === "hidden" || style.visibility === "collapse" ? "self" : "none";
|
|
245
|
+
}
|
|
246
|
+
function isEditingHost(element) {
|
|
247
|
+
const value = element.getAttribute("contenteditable");
|
|
248
|
+
if (value === null)
|
|
249
|
+
return false;
|
|
250
|
+
const normalised = value.trim().toLowerCase();
|
|
251
|
+
return normalised === "" || normalised === "true" || normalised === "plaintext-only";
|
|
252
|
+
}
|
|
253
|
+
function renderedChildren(element) {
|
|
254
|
+
if (element.shadowRoot)
|
|
255
|
+
return Array.from(element.shadowRoot.childNodes);
|
|
256
|
+
if (tagOf(element) === "slot") {
|
|
257
|
+
const slot = element;
|
|
258
|
+
const assigned = typeof slot.assignedNodes === "function" ? slot.assignedNodes({ flatten: true }) : [];
|
|
259
|
+
if (assigned.length > 0)
|
|
260
|
+
return assigned;
|
|
261
|
+
}
|
|
262
|
+
return Array.from(element.childNodes);
|
|
263
|
+
}
|
|
264
|
+
var BLOCK_TAGS = /^(div|p|li|tr|td|th|br|h[1-6]|section|article|header|footer)$/;
|
|
265
|
+
function push(sink, text) {
|
|
266
|
+
if (sink.remaining <= 0 || text.length === 0)
|
|
267
|
+
return;
|
|
268
|
+
const kept = text.slice(0, sink.remaining);
|
|
269
|
+
sink.parts.push(kept);
|
|
270
|
+
sink.remaining -= kept.length;
|
|
271
|
+
}
|
|
272
|
+
function collectText(node, depth, sink, probe, includeHidden, textHidden = false) {
|
|
273
|
+
if (depth > 32 || sink.remaining <= 0)
|
|
274
|
+
return;
|
|
275
|
+
if (node.nodeType === 3) {
|
|
276
|
+
if (!textHidden)
|
|
277
|
+
push(sink, node.textContent ?? "");
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (node.nodeType !== 1)
|
|
281
|
+
return;
|
|
282
|
+
const element = node;
|
|
283
|
+
const tag = tagOf(element);
|
|
284
|
+
if (SKIPPED_CONTENT.has(tag) || hasSensitiveMarker2(element))
|
|
285
|
+
return;
|
|
286
|
+
if (!includeHidden && isHiddenForName(element))
|
|
287
|
+
return;
|
|
288
|
+
let hidden = false;
|
|
289
|
+
if (depth > 0 && !includeHidden) {
|
|
290
|
+
const visible = probe?.isVisible?.(element);
|
|
291
|
+
if (visible === false)
|
|
292
|
+
hidden = true;
|
|
293
|
+
else if (visible === undefined) {
|
|
294
|
+
const hiding = cssHiding(element);
|
|
295
|
+
if (hiding === "subtree")
|
|
296
|
+
return;
|
|
297
|
+
hidden = hiding === "self";
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const label = element.getAttribute("aria-label")?.trim();
|
|
301
|
+
if (label && depth > 0 && !hidden) {
|
|
302
|
+
push(sink, ` ${label} `);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (tag === "img" || tag === "input" && element.getAttribute("type") === "image") {
|
|
306
|
+
if (!hidden)
|
|
307
|
+
push(sink, ` ${element.getAttribute("alt") ?? ""} `);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (tag === "input" || tag === "textarea" || tag === "select")
|
|
311
|
+
return;
|
|
312
|
+
if (depth > 0 && isEditingHost(element))
|
|
313
|
+
return;
|
|
314
|
+
const block = depth > 0 && BLOCK_TAGS.test(tag);
|
|
315
|
+
if (block)
|
|
316
|
+
push(sink, " ");
|
|
317
|
+
for (const child of renderedChildren(element))
|
|
318
|
+
collectText(child, depth + 1, sink, probe, includeHidden, hidden);
|
|
319
|
+
if (block)
|
|
320
|
+
push(sink, " ");
|
|
321
|
+
}
|
|
322
|
+
function isTypedContent2(element) {
|
|
323
|
+
const tag = tagOf(element);
|
|
324
|
+
if (tag === "textarea" || isEditingHost(element))
|
|
325
|
+
return true;
|
|
326
|
+
for (let current = containerOf(element);current; current = containerOf(current)) {
|
|
327
|
+
if (tagOf(current) === "textarea" || isEditingHost(current))
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
function isInsideFieldValue(element) {
|
|
333
|
+
for (let current = containerOf(element);current; current = containerOf(current)) {
|
|
334
|
+
const tag = tagOf(current);
|
|
335
|
+
if (tag === "textarea" || tag === "select" || isEditingHost(current))
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
function referencedText(label, probe, includeHidden = false) {
|
|
341
|
+
const tag = tagOf(label);
|
|
342
|
+
const isFieldValue = tag === "textarea" || tag === "select" || isEditingHost(label) || isInsideFieldValue(label);
|
|
343
|
+
if (isFieldValue || isMarkedSensitive(label))
|
|
344
|
+
return "";
|
|
345
|
+
const ownLabel = collapse(label.getAttribute("aria-label") ?? "");
|
|
346
|
+
return ownLabel || contentText(label, probe, MAX_NAME_LENGTH3, includeHidden);
|
|
347
|
+
}
|
|
348
|
+
function contentText(node, probe, max = MAX_NAME_LENGTH3, includeHidden = false) {
|
|
349
|
+
if (node.nodeType === 1 && isMarkedSensitive(node))
|
|
350
|
+
return "";
|
|
351
|
+
const sink = { parts: [], remaining: max * 2 + 64 };
|
|
352
|
+
collectText(node, 0, sink, probe, includeHidden);
|
|
353
|
+
return collapse(sink.parts.join(""), max);
|
|
354
|
+
}
|
|
355
|
+
function collapse(text, max = MAX_NAME_LENGTH3) {
|
|
356
|
+
return text.replace(/\s+/g, " ").trim().slice(0, max);
|
|
357
|
+
}
|
|
358
|
+
function labelsOf(element, probe) {
|
|
359
|
+
const parts = [];
|
|
360
|
+
const id = element.getAttribute("id");
|
|
361
|
+
if (id) {
|
|
362
|
+
const root = element.getRootNode();
|
|
363
|
+
for (const label of Array.from(root.querySelectorAll("label"))) {
|
|
364
|
+
if (label.getAttribute("for") === id)
|
|
365
|
+
parts.push(referencedText(label, probe, true));
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const wrapping = element.closest("label");
|
|
369
|
+
if (wrapping && !wrapping.hasAttribute("for"))
|
|
370
|
+
parts.push(referencedText(wrapping, probe, true));
|
|
371
|
+
return collapse(parts.join(" "));
|
|
372
|
+
}
|
|
373
|
+
function firstChildText(element, tag, probe) {
|
|
374
|
+
const child = Array.from(element.children).find((candidate) => tagOf(candidate) === tag);
|
|
375
|
+
return child ? referencedText(child, probe) : "";
|
|
376
|
+
}
|
|
377
|
+
function accessibleName2(element, probe) {
|
|
378
|
+
return computeName(element, probe, true);
|
|
379
|
+
}
|
|
380
|
+
function labelName2(element, probe) {
|
|
381
|
+
return computeName(element, probe, false);
|
|
382
|
+
}
|
|
383
|
+
function svgTitle(svg, probe) {
|
|
384
|
+
const title = Array.from(svg.children).find((child) => tagOf(child) === "title");
|
|
385
|
+
if (!title || isMarkedSensitive(title) || isInsideFieldValue(title))
|
|
386
|
+
return "";
|
|
387
|
+
return collapse(Array.from(title.childNodes).map((child) => contentText(child, probe)).join(" "));
|
|
388
|
+
}
|
|
389
|
+
function computeName(element, probe, fromContent) {
|
|
390
|
+
const labelledBy = element.getAttribute("aria-labelledby");
|
|
391
|
+
if (labelledBy) {
|
|
392
|
+
const text = labelledBy.split(/\s+/).filter(Boolean).map((id) => byId(element, id)).filter((label) => label !== null).map((label) => referencedText(label, probe, true)).join(" ");
|
|
393
|
+
if (collapse(text))
|
|
394
|
+
return collapse(text);
|
|
395
|
+
}
|
|
396
|
+
const ariaLabel = element.getAttribute("aria-label");
|
|
397
|
+
if (ariaLabel && collapse(ariaLabel))
|
|
398
|
+
return collapse(ariaLabel);
|
|
399
|
+
const tag = tagOf(element);
|
|
400
|
+
if (LABELABLE.has(tag)) {
|
|
401
|
+
const labels = labelsOf(element, probe);
|
|
402
|
+
if (labels)
|
|
403
|
+
return labels;
|
|
404
|
+
}
|
|
405
|
+
if (tag === "input") {
|
|
406
|
+
const type = (element.getAttribute("type") ?? "text").toLowerCase();
|
|
407
|
+
if (type === "button" || type === "submit" || type === "reset") {
|
|
408
|
+
const value = element.getAttribute("value");
|
|
409
|
+
if (value !== null)
|
|
410
|
+
return collapse(value);
|
|
411
|
+
return type === "submit" ? "Submit" : type === "reset" ? "Reset" : "";
|
|
412
|
+
}
|
|
413
|
+
if (type === "image")
|
|
414
|
+
return collapse(element.getAttribute("alt") ?? "");
|
|
415
|
+
}
|
|
416
|
+
if (tag === "img" || tag === "area") {
|
|
417
|
+
const alt = element.getAttribute("alt");
|
|
418
|
+
if (alt)
|
|
419
|
+
return collapse(alt);
|
|
420
|
+
}
|
|
421
|
+
if (tag === "svg") {
|
|
422
|
+
const title = svgTitle(element, probe);
|
|
423
|
+
if (title)
|
|
424
|
+
return title;
|
|
425
|
+
}
|
|
426
|
+
if (tag === "fieldset") {
|
|
427
|
+
const legend = firstChildText(element, "legend", probe);
|
|
428
|
+
if (legend)
|
|
429
|
+
return legend;
|
|
430
|
+
}
|
|
431
|
+
if (tag === "table") {
|
|
432
|
+
const caption = firstChildText(element, "caption", probe);
|
|
433
|
+
if (caption)
|
|
434
|
+
return caption;
|
|
435
|
+
}
|
|
436
|
+
if (tag === "option") {
|
|
437
|
+
const label = collapse(element.getAttribute("label") ?? "");
|
|
438
|
+
if (label)
|
|
439
|
+
return label;
|
|
440
|
+
}
|
|
441
|
+
if (tag === "figure") {
|
|
442
|
+
const caption = firstChildText(element, "figcaption", probe);
|
|
443
|
+
if (caption)
|
|
444
|
+
return caption;
|
|
445
|
+
}
|
|
446
|
+
if (fromContent && NAME_FROM_CONTENT.has(roleOf2(element))) {
|
|
447
|
+
const text = contentText(element, probe);
|
|
448
|
+
if (text)
|
|
449
|
+
return text;
|
|
450
|
+
}
|
|
451
|
+
const title = element.getAttribute("title");
|
|
452
|
+
if (title && collapse(title))
|
|
453
|
+
return collapse(title);
|
|
454
|
+
const placeholder = element.getAttribute("placeholder");
|
|
455
|
+
if (placeholder && collapse(placeholder))
|
|
456
|
+
return collapse(placeholder);
|
|
457
|
+
return "";
|
|
458
|
+
}
|
|
459
|
+
function visibleText2(element, probe) {
|
|
460
|
+
const tag = tagOf(element);
|
|
461
|
+
if (tag === "input") {
|
|
462
|
+
const type = (element.getAttribute("type") ?? "text").toLowerCase();
|
|
463
|
+
return type === "button" || type === "submit" || type === "reset" ? accessibleName2(element, probe) : "";
|
|
464
|
+
}
|
|
465
|
+
return contentText(element, probe, MAX_VISIBLE_TEXT2);
|
|
466
|
+
}
|
|
467
|
+
function matchesRoleAndName2(element, role, name, probe) {
|
|
468
|
+
return roleOf2(element) === role.trim().toLowerCase() && normaliseText2(accessibleName2(element, probe)) === normaliseText2(name);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// src/target/dom.ts
|
|
472
|
+
function viewOf(element) {
|
|
473
|
+
return element.ownerDocument.defaultView;
|
|
474
|
+
}
|
|
475
|
+
function parentAcrossShadow2(element) {
|
|
476
|
+
const slot = assignedSlotOf(element);
|
|
477
|
+
if (slot)
|
|
478
|
+
return slot;
|
|
479
|
+
if (element.parentElement)
|
|
480
|
+
return element.parentElement;
|
|
481
|
+
const root = element.getRootNode();
|
|
482
|
+
return root && "host" in root ? root.host : null;
|
|
483
|
+
}
|
|
484
|
+
function isElementVisible2(element, probe) {
|
|
485
|
+
const override = probe?.isVisible?.(element);
|
|
486
|
+
if (override !== undefined)
|
|
487
|
+
return override;
|
|
488
|
+
if (!element.isConnected)
|
|
489
|
+
return false;
|
|
490
|
+
const view = viewOf(element);
|
|
491
|
+
let current = element;
|
|
492
|
+
while (current) {
|
|
493
|
+
if (current.hasAttribute("hidden"))
|
|
494
|
+
return false;
|
|
495
|
+
if (current.localName === "input" && current.getAttribute("type")?.toLowerCase() === "hidden")
|
|
496
|
+
return false;
|
|
497
|
+
if (view && view.getComputedStyle(current).display === "none")
|
|
498
|
+
return false;
|
|
499
|
+
current = parentAcrossShadow2(current);
|
|
500
|
+
}
|
|
501
|
+
if (view) {
|
|
502
|
+
const style = view.getComputedStyle(element);
|
|
503
|
+
if (style.visibility === "hidden" || style.visibility === "collapse")
|
|
504
|
+
return false;
|
|
505
|
+
if (style.display === "contents")
|
|
506
|
+
return true;
|
|
507
|
+
}
|
|
508
|
+
const check = element.checkVisibility;
|
|
509
|
+
return typeof check === "function" ? check.call(element) : true;
|
|
510
|
+
}
|
|
511
|
+
function isElementEnabled2(element) {
|
|
512
|
+
for (let current = element;current; current = containerOf(current)) {
|
|
513
|
+
if (current.getAttribute("aria-disabled") === "true" || current.hasAttribute("inert"))
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
if (!FORM_CONTROLS.has(element.localName)) {
|
|
517
|
+
const control = element.parentElement?.closest("button, select, option, optgroup, textarea");
|
|
518
|
+
return control ? isElementEnabled2(control) : true;
|
|
519
|
+
}
|
|
520
|
+
if (element.hasAttribute("disabled"))
|
|
521
|
+
return false;
|
|
522
|
+
const fieldset = element.parentElement?.closest("fieldset[disabled]");
|
|
523
|
+
if (fieldset) {
|
|
524
|
+
const legend = Array.from(fieldset.children).find((child) => child.localName === "legend");
|
|
525
|
+
if (!legend?.contains(element))
|
|
526
|
+
return false;
|
|
527
|
+
}
|
|
528
|
+
try {
|
|
529
|
+
return !element.matches(":disabled");
|
|
530
|
+
} catch {
|
|
531
|
+
return true;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
var FORM_CONTROLS = new Set(["button", "input", "select", "textarea", "optgroup", "option", "fieldset"]);
|
|
535
|
+
function elementRect2(element, probe, offset) {
|
|
536
|
+
const given = probe?.rectOf?.(element);
|
|
537
|
+
const box = given ?? element.getBoundingClientRect();
|
|
538
|
+
return {
|
|
539
|
+
x: Math.round(box.x + (offset?.x ?? 0)),
|
|
540
|
+
y: Math.round(box.y + (offset?.y ?? 0)),
|
|
541
|
+
width: Math.round(box.width),
|
|
542
|
+
height: Math.round(box.height)
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
function elementsUnder2(root) {
|
|
546
|
+
const all = Array.from(root.querySelectorAll("*"));
|
|
547
|
+
return root.nodeType === 1 ? [root, ...all] : all;
|
|
548
|
+
}
|
|
549
|
+
var SECRET_FIELD = /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;
|
|
550
|
+
var SECRET_AUTOCOMPLETE = /password|one-time-code|^cc-/i;
|
|
551
|
+
function isSecretFieldName2(name) {
|
|
552
|
+
return SECRET_FIELD.test(name);
|
|
553
|
+
}
|
|
554
|
+
function isSensitiveElement2(element) {
|
|
555
|
+
if (isMarkedSensitive(element))
|
|
556
|
+
return true;
|
|
557
|
+
if (isSensitiveField(element))
|
|
558
|
+
return true;
|
|
559
|
+
for (let current = containerOf(element);current; current = containerOf(current)) {
|
|
560
|
+
if (isSensitiveField(current))
|
|
561
|
+
return true;
|
|
562
|
+
}
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
function isSensitiveField(element) {
|
|
566
|
+
const tag = element.localName;
|
|
567
|
+
const editable = element.getAttribute("contenteditable");
|
|
568
|
+
const isEditingHost = editable !== null && editable.trim().toLowerCase() !== "false";
|
|
569
|
+
if (tag !== "input" && tag !== "textarea" && tag !== "select" && !isEditingHost)
|
|
570
|
+
return false;
|
|
571
|
+
if (element.getAttribute("type")?.toLowerCase() === "password")
|
|
572
|
+
return true;
|
|
573
|
+
const tokens = (element.getAttribute("autocomplete") ?? "").trim().split(/\s+/).filter(Boolean);
|
|
574
|
+
if (tokens.some((token) => SECRET_AUTOCOMPLETE.test(token)))
|
|
575
|
+
return true;
|
|
576
|
+
return fieldHints(element).some((hint) => hint.length > 0 && isSecretFieldName2(hint.replace(/[-_]/g, " ")));
|
|
577
|
+
}
|
|
578
|
+
function fieldHints(element) {
|
|
579
|
+
const raw = (value) => (value ?? "").slice(0, 512);
|
|
580
|
+
const hints = [
|
|
581
|
+
accessibleName2(element),
|
|
582
|
+
raw(element.getAttribute("aria-label")),
|
|
583
|
+
raw(element.getAttribute("placeholder")),
|
|
584
|
+
raw(element.getAttribute("title")),
|
|
585
|
+
raw(element.getAttribute("name")),
|
|
586
|
+
raw(element.getAttribute("id"))
|
|
587
|
+
];
|
|
588
|
+
const root = element.getRootNode();
|
|
589
|
+
const byId = (id) => typeof root.getElementById === "function" ? root.getElementById(id) : null;
|
|
590
|
+
for (const id of (element.getAttribute("aria-labelledby") ?? "").split(/\s+/).filter(Boolean)) {
|
|
591
|
+
const target = byId(id);
|
|
592
|
+
if (target)
|
|
593
|
+
hints.push(raw(target.getAttribute("aria-label")), raw(target.textContent));
|
|
594
|
+
}
|
|
595
|
+
const id = element.getAttribute("id");
|
|
596
|
+
const labels = Array.from(root.querySelectorAll("label")).filter((label) => id !== null && label.getAttribute("for") === id || !label.hasAttribute("for") && label.contains(element));
|
|
597
|
+
for (const label of labels)
|
|
598
|
+
hints.push(raw(label.getAttribute("aria-label")), raw(label.textContent));
|
|
599
|
+
return hints;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// src/target/methods.ts
|
|
603
|
+
var DEFAULT_FUZZY_THRESHOLD2 = 0.8;
|
|
604
|
+
var FUZZY_MARGIN2 = 0.05;
|
|
605
|
+
var ANCHOR_MARGIN_PX2 = 4;
|
|
606
|
+
var MAX_XPATH_RESULTS2 = 1000;
|
|
607
|
+
var EDGE_SLACK_PX = 2;
|
|
608
|
+
var INTERACTIVE_ROLES2 = new Set([
|
|
609
|
+
"button",
|
|
610
|
+
"checkbox",
|
|
611
|
+
"combobox",
|
|
612
|
+
"link",
|
|
613
|
+
"listbox",
|
|
614
|
+
"menuitem",
|
|
615
|
+
"menuitemcheckbox",
|
|
616
|
+
"menuitemradio",
|
|
617
|
+
"option",
|
|
618
|
+
"radio",
|
|
619
|
+
"searchbox",
|
|
620
|
+
"slider",
|
|
621
|
+
"spinbutton",
|
|
622
|
+
"switch",
|
|
623
|
+
"tab",
|
|
624
|
+
"textbox",
|
|
625
|
+
"treeitem"
|
|
626
|
+
]);
|
|
627
|
+
var ATTRIBUTE_NAME = /^[A-Za-z_][\w:.-]{0,127}$/;
|
|
628
|
+
function documentOf(root) {
|
|
629
|
+
return root.nodeType === 9 ? root : root.ownerDocument;
|
|
630
|
+
}
|
|
631
|
+
function matchRole(method, context) {
|
|
632
|
+
const elements = elementsUnder2(context.root).filter((element) => matchesRoleAndName2(element, method.role, method.name, context.probe));
|
|
633
|
+
return { kind: "list", elements, ...method.nth !== undefined ? { nth: method.nth } : {} };
|
|
634
|
+
}
|
|
635
|
+
function matchCss(selector, context) {
|
|
636
|
+
try {
|
|
637
|
+
return { kind: "list", elements: Array.from(context.root.querySelectorAll(selector)) };
|
|
638
|
+
} catch {
|
|
639
|
+
return { kind: "invalid" };
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
function matchTestId(method, context) {
|
|
643
|
+
const attribute = method.attribute ?? "data-testid";
|
|
644
|
+
if (!ATTRIBUTE_NAME.test(attribute))
|
|
645
|
+
return { kind: "invalid" };
|
|
646
|
+
const elements = elementsUnder2(context.root).filter((element) => element.getAttribute(attribute) === method.value);
|
|
647
|
+
return { kind: "list", elements };
|
|
648
|
+
}
|
|
649
|
+
function isUnder(root, node) {
|
|
650
|
+
if (root.nodeType === 9)
|
|
651
|
+
return node.ownerDocument === root && node.getRootNode() === root;
|
|
652
|
+
return root === node || root.contains(node);
|
|
653
|
+
}
|
|
654
|
+
function matchXPath(method, context) {
|
|
655
|
+
const document = documentOf(context.root);
|
|
656
|
+
if (typeof document.evaluate !== "function")
|
|
657
|
+
return { kind: "unsupported" };
|
|
658
|
+
let result;
|
|
659
|
+
try {
|
|
660
|
+
result = document.evaluate(method.xpath, context.root, null, 7, null);
|
|
661
|
+
} catch {
|
|
662
|
+
return { kind: "invalid" };
|
|
663
|
+
}
|
|
664
|
+
const elements = [];
|
|
665
|
+
const length = Math.min(result.snapshotLength, MAX_XPATH_RESULTS2);
|
|
666
|
+
for (let index = 0;index < length; index += 1) {
|
|
667
|
+
const node = result.snapshotItem(index);
|
|
668
|
+
if (node && node.nodeType === 1 && isUnder(context.root, node))
|
|
669
|
+
elements.push(node);
|
|
670
|
+
}
|
|
671
|
+
return { kind: "list", elements, ...result.snapshotLength > MAX_XPATH_RESULTS2 ? { overflow: true } : {} };
|
|
672
|
+
}
|
|
673
|
+
function lengthAllows(name, wantedLength, threshold) {
|
|
674
|
+
const length = Math.min(normaliseText2(name).length, MAX_COMPARED_TEXT2);
|
|
675
|
+
const longest = Math.max(length, wantedLength);
|
|
676
|
+
return longest > 0 && Math.abs(length - wantedLength) <= (1 - threshold) * longest;
|
|
677
|
+
}
|
|
678
|
+
function matchFuzzy(method, context) {
|
|
679
|
+
const threshold = Math.min(1, Math.max(0.5, method.threshold ?? DEFAULT_FUZZY_THRESHOLD2));
|
|
680
|
+
const wantedRole = method.role?.trim().toLowerCase();
|
|
681
|
+
const wantedLength = Math.min(normaliseText2(method.name).length, MAX_COMPARED_TEXT2);
|
|
682
|
+
const scored = [];
|
|
683
|
+
for (const element of elementsUnder2(context.root)) {
|
|
684
|
+
const role = roleOf2(element);
|
|
685
|
+
if (wantedRole ? role !== wantedRole : role === "")
|
|
686
|
+
continue;
|
|
687
|
+
const name = accessibleName2(element, context.probe);
|
|
688
|
+
if (!lengthAllows(name, wantedLength, threshold))
|
|
689
|
+
continue;
|
|
690
|
+
const score = textSimilarity2(name, method.name);
|
|
691
|
+
if (score >= threshold)
|
|
692
|
+
scored.push({ element, score });
|
|
693
|
+
}
|
|
694
|
+
return { kind: "ranked", scored, margin: FUZZY_MARGIN2 };
|
|
695
|
+
}
|
|
696
|
+
function innermostByText(context, matches) {
|
|
697
|
+
const hits = elementsUnder2(context.root).filter((element) => matches(visibleText2(element, context.probe)));
|
|
698
|
+
const keep = context.keep ?? (() => true);
|
|
699
|
+
const innerHits = hits.filter(keep);
|
|
700
|
+
return hits.filter((element) => !innerHits.some((inner) => inner !== element && element.contains(inner)));
|
|
701
|
+
}
|
|
702
|
+
function matchText(method, context) {
|
|
703
|
+
const test = method.exact ? (text) => sameText2(text, method.text) : (text) => containsText2(text, method.text);
|
|
704
|
+
if (normaliseText2(method.text).length === 0)
|
|
705
|
+
return { kind: "list", elements: [] };
|
|
706
|
+
return {
|
|
707
|
+
kind: "list",
|
|
708
|
+
elements: innermostByText(context, test),
|
|
709
|
+
...method.nth !== undefined ? { nth: method.nth } : {}
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
function labelText(text) {
|
|
713
|
+
return normaliseText2(text).replace(/[\s:*]+$/u, "");
|
|
714
|
+
}
|
|
715
|
+
function anchorElements(anchor, context) {
|
|
716
|
+
const found = anchor.kind === "role" ? elementsUnder2(context.root).filter((element) => matchesRoleAndName2(element, anchor.role, anchor.name, context.probe)) : innermostByText(context, (text) => labelText(text) === labelText(anchor.text) && labelText(text) !== "");
|
|
717
|
+
return found.filter((element) => isElementVisible2(element, context.probe));
|
|
718
|
+
}
|
|
719
|
+
function candidateElements(method, context, anchors) {
|
|
720
|
+
const wantedRole = method.role?.trim().toLowerCase();
|
|
721
|
+
return elementsUnder2(context.root).filter((element) => {
|
|
722
|
+
const role = roleOf2(element);
|
|
723
|
+
if (wantedRole ? role !== wantedRole : !INTERACTIVE_ROLES2.has(role))
|
|
724
|
+
return false;
|
|
725
|
+
return !anchors.some((anchor) => anchor === element || element.contains(anchor));
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
var HEADING_TAGS = new Set(["h1", "h2", "h3", "h4", "h5", "h6", "legend", "caption", "figcaption", "summary", "dt"]);
|
|
729
|
+
function isHeadingLike(element) {
|
|
730
|
+
return HEADING_TAGS.has(element.localName) || roleOf2(element) === "heading";
|
|
731
|
+
}
|
|
732
|
+
function headingOf(anchor) {
|
|
733
|
+
for (let current = anchor;current; current = current.parentElement) {
|
|
734
|
+
if (isHeadingLike(current))
|
|
735
|
+
return current;
|
|
736
|
+
}
|
|
737
|
+
return null;
|
|
738
|
+
}
|
|
739
|
+
function matchInside(method, context, anchors) {
|
|
740
|
+
const candidates = candidateElements(method, context, anchors);
|
|
741
|
+
const inside = new Set;
|
|
742
|
+
for (const anchor of anchors) {
|
|
743
|
+
const heading = headingOf(anchor);
|
|
744
|
+
const container = heading?.parentElement ?? anchor;
|
|
745
|
+
for (const candidate of candidates)
|
|
746
|
+
if (container.contains(candidate))
|
|
747
|
+
inside.add(candidate);
|
|
748
|
+
}
|
|
749
|
+
return { kind: "list", elements: candidates.filter((candidate) => inside.has(candidate)) };
|
|
750
|
+
}
|
|
751
|
+
function overlaps(aStart, aEnd, bStart, bEnd) {
|
|
752
|
+
return aStart < bEnd && bStart < aEnd;
|
|
753
|
+
}
|
|
754
|
+
function relationDistance2(relation, anchor, element) {
|
|
755
|
+
const aRight = anchor.x + anchor.width;
|
|
756
|
+
const aBottom = anchor.y + anchor.height;
|
|
757
|
+
const eRight = element.x + element.width;
|
|
758
|
+
const eBottom = element.y + element.height;
|
|
759
|
+
const sameRow = overlaps(anchor.y, aBottom, element.y, eBottom);
|
|
760
|
+
const sameColumn = overlaps(anchor.x, aRight, element.x, eRight);
|
|
761
|
+
switch (relation) {
|
|
762
|
+
case "rightOf":
|
|
763
|
+
return sameRow && element.x >= aRight - EDGE_SLACK_PX ? Math.max(0, element.x - aRight) : null;
|
|
764
|
+
case "leftOf":
|
|
765
|
+
return sameRow && eRight <= anchor.x + EDGE_SLACK_PX ? Math.max(0, anchor.x - eRight) : null;
|
|
766
|
+
case "below":
|
|
767
|
+
return sameColumn && element.y >= aBottom - EDGE_SLACK_PX ? Math.max(0, element.y - aBottom) : null;
|
|
768
|
+
case "above":
|
|
769
|
+
return sameColumn && eBottom <= anchor.y + EDGE_SLACK_PX ? Math.max(0, anchor.y - eBottom) : null;
|
|
770
|
+
case "sameRow":
|
|
771
|
+
return sameRow ? Math.abs(element.x + element.width / 2 - (anchor.x + anchor.width / 2)) : null;
|
|
772
|
+
default:
|
|
773
|
+
return null;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
function hasArea(rect) {
|
|
777
|
+
return rect.width > 0 && rect.height > 0;
|
|
778
|
+
}
|
|
779
|
+
function matchAnchor(method, context) {
|
|
780
|
+
const anchors = anchorElements(method.anchor, context);
|
|
781
|
+
if (anchors.length === 0)
|
|
782
|
+
return { kind: "list", elements: [] };
|
|
783
|
+
if (method.relation === "inside")
|
|
784
|
+
return matchInside(method, context, anchors);
|
|
785
|
+
const anchorRects = anchors.map((anchor) => elementRect2(anchor, context.probe)).filter(hasArea);
|
|
786
|
+
if (anchorRects.length === 0)
|
|
787
|
+
return { kind: "unsupported" };
|
|
788
|
+
const scored = [];
|
|
789
|
+
for (const element of candidateElements(method, context, anchors)) {
|
|
790
|
+
const rect = elementRect2(element, context.probe);
|
|
791
|
+
if (!hasArea(rect))
|
|
792
|
+
continue;
|
|
793
|
+
let best = null;
|
|
794
|
+
for (const anchorRect of anchorRects) {
|
|
795
|
+
const distance = relationDistance2(method.relation, anchorRect, rect);
|
|
796
|
+
if (distance !== null && (best === null || distance < best))
|
|
797
|
+
best = distance;
|
|
798
|
+
}
|
|
799
|
+
if (best !== null)
|
|
800
|
+
scored.push({ element, score: -best });
|
|
801
|
+
}
|
|
802
|
+
return { kind: "ranked", scored, margin: ANCHOR_MARGIN_PX2 };
|
|
803
|
+
}
|
|
804
|
+
function matchMethod2(method, context) {
|
|
805
|
+
switch (method.kind) {
|
|
806
|
+
case "role":
|
|
807
|
+
return matchRole(method, context);
|
|
808
|
+
case "css":
|
|
809
|
+
return matchCss(method.selector, context);
|
|
810
|
+
case "testId":
|
|
811
|
+
return matchTestId(method, context);
|
|
812
|
+
case "xpath":
|
|
813
|
+
return matchXPath(method, context);
|
|
814
|
+
case "fuzzy":
|
|
815
|
+
return matchFuzzy(method, context);
|
|
816
|
+
case "anchor":
|
|
817
|
+
return matchAnchor(method, context);
|
|
818
|
+
case "text":
|
|
819
|
+
return matchText(method, context);
|
|
820
|
+
default:
|
|
821
|
+
return { kind: "unsupported" };
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// src/target/resolve.ts
|
|
826
|
+
var ZERO = { x: 0, y: 0, width: 0, height: 0 };
|
|
827
|
+
function enterFrames2(root, chain, probe) {
|
|
828
|
+
let entry = { root, offset: ZERO, hidden: false, disabled: false };
|
|
829
|
+
for (const [index, selector] of (chain ?? []).entries()) {
|
|
830
|
+
let found;
|
|
831
|
+
try {
|
|
832
|
+
found = Array.from(entry.root.querySelectorAll(selector));
|
|
833
|
+
} catch {
|
|
834
|
+
return { index, reason: "invalid" };
|
|
835
|
+
}
|
|
836
|
+
if (found.length === 0)
|
|
837
|
+
return { index, reason: "notFound" };
|
|
838
|
+
if (found.length > 1)
|
|
839
|
+
return { index, reason: "ambiguous" };
|
|
840
|
+
const host = found[0];
|
|
841
|
+
const tag = host.localName;
|
|
842
|
+
if (tag === "iframe" || tag === "frame") {
|
|
843
|
+
const frame = host;
|
|
844
|
+
let inner = null;
|
|
845
|
+
try {
|
|
846
|
+
inner = frame.contentDocument;
|
|
847
|
+
} catch {
|
|
848
|
+
inner = null;
|
|
849
|
+
}
|
|
850
|
+
if (!inner)
|
|
851
|
+
return { index, reason: "inaccessible" };
|
|
852
|
+
const box = elementRect2(host, probe, entry.offset);
|
|
853
|
+
entry = {
|
|
854
|
+
root: inner,
|
|
855
|
+
offset: { x: box.x + frame.clientLeft, y: box.y + frame.clientTop, width: 0, height: 0 },
|
|
856
|
+
hidden: entry.hidden || !isElementVisible2(host, probe),
|
|
857
|
+
disabled: entry.disabled || !isElementEnabled2(host)
|
|
858
|
+
};
|
|
859
|
+
} else if (host.shadowRoot) {
|
|
860
|
+
entry = { root: host.shadowRoot, offset: entry.offset, hidden: entry.hidden, disabled: entry.disabled };
|
|
861
|
+
} else {
|
|
862
|
+
return { index, reason: "notAFrame" };
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
return entry;
|
|
866
|
+
}
|
|
867
|
+
function inState(element, state, entry, probe) {
|
|
868
|
+
if (state === "attached")
|
|
869
|
+
return true;
|
|
870
|
+
if (entry.hidden || !isElementVisible2(element, probe))
|
|
871
|
+
return false;
|
|
872
|
+
return state === "visible" || !entry.disabled && isElementEnabled2(element);
|
|
873
|
+
}
|
|
874
|
+
function describeCandidate2(element, method, methodIndex, offset, probe) {
|
|
875
|
+
return {
|
|
876
|
+
role: roleOf2(element),
|
|
877
|
+
name: isSensitiveElement2(element) ? "" : clip2(isTypedContent2(element) ? labelName2(element, probe) : accessibleName2(element, probe), MAX_CANDIDATE_NAME2),
|
|
878
|
+
bounds: elementRect2(element, probe, offset),
|
|
879
|
+
method: method.kind,
|
|
880
|
+
methodIndex
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
function pickFromList(all, kept, nth, overflow = false) {
|
|
884
|
+
if (kept.length === 0) {
|
|
885
|
+
return all.length > 0 ? { outcome: "notInteractable", elements: all, matches: 0 } : { outcome: "none", elements: [], matches: 0 };
|
|
886
|
+
}
|
|
887
|
+
if (overflow)
|
|
888
|
+
return { outcome: "ambiguous", elements: kept, matches: kept.length };
|
|
889
|
+
if (nth !== undefined) {
|
|
890
|
+
const element = kept[nth];
|
|
891
|
+
return element ? { outcome: "found", element, matches: kept.length } : { outcome: "none", elements: [], matches: kept.length };
|
|
892
|
+
}
|
|
893
|
+
return kept.length === 1 ? { outcome: "found", element: kept[0], matches: 1 } : { outcome: "ambiguous", elements: kept, matches: kept.length };
|
|
894
|
+
}
|
|
895
|
+
function pickRanked(all, kept, margin) {
|
|
896
|
+
if (kept.length === 0) {
|
|
897
|
+
return all.length > 0 ? { outcome: "notInteractable", elements: all.map((item) => item.element), matches: 0 } : { outcome: "none", elements: [], matches: 0 };
|
|
898
|
+
}
|
|
899
|
+
const sorted = [...kept].sort((a, b) => b.score - a.score);
|
|
900
|
+
const best = sorted[0];
|
|
901
|
+
const runnerUp = sorted[1];
|
|
902
|
+
if (!runnerUp || best.score - runnerUp.score >= margin) {
|
|
903
|
+
return { outcome: "found", element: best.element, matches: kept.length };
|
|
904
|
+
}
|
|
905
|
+
const tied = sorted.filter((item) => best.score - item.score < margin).map((item) => item.element);
|
|
906
|
+
return { outcome: "ambiguous", elements: tied, matches: tied.length };
|
|
907
|
+
}
|
|
908
|
+
function pick(match, keep) {
|
|
909
|
+
switch (match.kind) {
|
|
910
|
+
case "invalid":
|
|
911
|
+
case "unsupported":
|
|
912
|
+
return match.kind;
|
|
913
|
+
case "list":
|
|
914
|
+
return pickFromList(match.elements, match.elements.filter(keep), match.nth, match.overflow);
|
|
915
|
+
case "ranked":
|
|
916
|
+
return pickRanked(match.scored, match.scored.filter((item) => keep(item.element)), match.margin);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
function failure(code, attempts, candidates = [], candidateCount = 0, frame) {
|
|
920
|
+
return { status: "failed", code, candidates, candidateCount, attempts, ...frame ? { frame } : {} };
|
|
921
|
+
}
|
|
922
|
+
function resolveWebTarget2(root, target, options = {}) {
|
|
923
|
+
const state = options.state ?? "interactable";
|
|
924
|
+
const entered = enterFrames2(root, target.frame, options);
|
|
925
|
+
if (!("root" in entered)) {
|
|
926
|
+
const attempts = target.methods.map((method, index) => ({
|
|
927
|
+
index,
|
|
928
|
+
method: method.kind,
|
|
929
|
+
outcome: "notTried",
|
|
930
|
+
matches: 0
|
|
931
|
+
}));
|
|
932
|
+
return failure("ELEMENT_NOT_FOUND", attempts, [], 0, entered);
|
|
933
|
+
}
|
|
934
|
+
const attempts = [];
|
|
935
|
+
const firstEnabled = target.methods.findIndex((method) => method.enabled !== false);
|
|
936
|
+
let ambiguous;
|
|
937
|
+
let blocked;
|
|
938
|
+
let found;
|
|
939
|
+
for (const [index, method] of target.methods.entries()) {
|
|
940
|
+
if (found) {
|
|
941
|
+
attempts.push({ index, method: method.kind, outcome: "notTried", matches: 0 });
|
|
942
|
+
continue;
|
|
943
|
+
}
|
|
944
|
+
if (method.enabled === false) {
|
|
945
|
+
attempts.push({ index, method: method.kind, outcome: "disabled", matches: 0 });
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
const keep = (element) => inState(element, state, entered, options);
|
|
949
|
+
const result = pick(matchMethod2(method, { root: entered.root, probe: options, keep }), keep);
|
|
950
|
+
if (result === "invalid" || result === "unsupported") {
|
|
951
|
+
attempts.push({ index, method: method.kind, outcome: result, matches: 0 });
|
|
952
|
+
continue;
|
|
953
|
+
}
|
|
954
|
+
attempts.push({ index, method: method.kind, outcome: result.outcome, matches: result.matches });
|
|
955
|
+
if (result.outcome === "found")
|
|
956
|
+
found = { element: result.element, method, index };
|
|
957
|
+
else if (result.outcome === "ambiguous" && !ambiguous) {
|
|
958
|
+
ambiguous = { elements: result.elements, method, index, count: result.matches };
|
|
959
|
+
} else if (result.outcome === "notInteractable" && !blocked)
|
|
960
|
+
blocked = { elements: result.elements, method, index };
|
|
961
|
+
}
|
|
962
|
+
if (found) {
|
|
963
|
+
return {
|
|
964
|
+
status: "found",
|
|
965
|
+
element: found.element,
|
|
966
|
+
method: found.method.kind,
|
|
967
|
+
methodIndex: found.index,
|
|
968
|
+
fallback: found.index !== firstEnabled,
|
|
969
|
+
candidate: describeCandidate2(found.element, found.method, found.index, entered.offset, options),
|
|
970
|
+
attempts
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
const listed = (report) => report.elements.slice(0, MAX_CANDIDATES2).map((element) => describeCandidate2(element, report.method, report.index, entered.offset, options));
|
|
974
|
+
if (ambiguous)
|
|
975
|
+
return failure("ELEMENT_AMBIGUOUS", attempts, listed(ambiguous), ambiguous.count);
|
|
976
|
+
if (blocked)
|
|
977
|
+
return failure("ELEMENT_NOT_INTERACTABLE", attempts, listed(blocked), blocked.elements.length);
|
|
978
|
+
return failure("ELEMENT_NOT_FOUND", attempts);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
// src/target/snapshot.ts
|
|
982
|
+
var UI_TREE_SNAPSHOT_VERSION2 = 1;
|
|
983
|
+
var DEFAULT_SNAPSHOT_MAX_NODES2 = 5000;
|
|
984
|
+
var MAX_SNAPSHOT_DEPTH2 = 64;
|
|
985
|
+
var MAX_SNAPSHOT_TEXT2 = 500;
|
|
986
|
+
var SKIPPED = new Set(["script", "style", "noscript", "template", "link", "meta", "base", "head", "object", "embed"]);
|
|
987
|
+
var VALUE_CONTENT = new Set(["textarea"]);
|
|
988
|
+
var KEPT_ATTRIBUTES = new Set([
|
|
989
|
+
"id",
|
|
990
|
+
"class",
|
|
991
|
+
"role",
|
|
992
|
+
"name",
|
|
993
|
+
"type",
|
|
994
|
+
"for",
|
|
995
|
+
"title",
|
|
996
|
+
"alt",
|
|
997
|
+
"placeholder",
|
|
998
|
+
"label",
|
|
999
|
+
"autocomplete",
|
|
1000
|
+
"tabindex",
|
|
1001
|
+
"disabled",
|
|
1002
|
+
"readonly",
|
|
1003
|
+
"hidden",
|
|
1004
|
+
"inert",
|
|
1005
|
+
"contenteditable",
|
|
1006
|
+
"list",
|
|
1007
|
+
"multiple",
|
|
1008
|
+
"size",
|
|
1009
|
+
"scope",
|
|
1010
|
+
"slot",
|
|
1011
|
+
"part",
|
|
1012
|
+
"lang",
|
|
1013
|
+
"dir",
|
|
1014
|
+
"data-testid",
|
|
1015
|
+
"data-test",
|
|
1016
|
+
"data-test-id",
|
|
1017
|
+
"data-qa",
|
|
1018
|
+
"data-cy",
|
|
1019
|
+
"data-automation-id",
|
|
1020
|
+
...SENSITIVE_MARKERS2
|
|
1021
|
+
]);
|
|
1022
|
+
var DROPPED_ARIA = new Set(["aria-valuenow", "aria-valuetext", "aria-checked", "aria-selected", "aria-pressed"]);
|
|
1023
|
+
var BUTTON_INPUTS = new Set(["button", "submit", "reset"]);
|
|
1024
|
+
var RESET_SEGMENT = /reset|recover|verify|verification|magic|confirm|activate|invite|unsubscribe/i;
|
|
1025
|
+
var TAG_NAME = /^[a-z][a-z0-9-]{0,63}$/;
|
|
1026
|
+
var EMPTY_FRAME_DOCUMENT = "<!doctype html><html><head></head><body></body></html>";
|
|
1027
|
+
var ATTRIBUTE_NAME2 = /^[a-z][a-z0-9_:.-]{0,127}$/;
|
|
1028
|
+
function isEditingHost2(element) {
|
|
1029
|
+
const value = element.getAttribute("contenteditable");
|
|
1030
|
+
return value !== null && value.trim().toLowerCase() !== "false";
|
|
1031
|
+
}
|
|
1032
|
+
function hasFieldValueAncestor(element) {
|
|
1033
|
+
for (let current = containerOf(element);current; current = containerOf(current)) {
|
|
1034
|
+
if (current.localName === "textarea" || isEditingHost2(current))
|
|
1035
|
+
return true;
|
|
1036
|
+
}
|
|
1037
|
+
return false;
|
|
1038
|
+
}
|
|
1039
|
+
function slottedTextHidden(text) {
|
|
1040
|
+
if (!text.parentElement?.shadowRoot)
|
|
1041
|
+
return false;
|
|
1042
|
+
const slot = assignedSlotOf(text);
|
|
1043
|
+
return slot !== null && (isSensitiveElement2(slot) || hasFieldValueAncestor(slot));
|
|
1044
|
+
}
|
|
1045
|
+
function cleanText(value) {
|
|
1046
|
+
return clip2(redactCredentials2(value), MAX_SNAPSHOT_TEXT2);
|
|
1047
|
+
}
|
|
1048
|
+
function decodeSegment(segment) {
|
|
1049
|
+
let current = segment;
|
|
1050
|
+
for (let round = 0;round < 3; round += 1) {
|
|
1051
|
+
const next = decodeUriText(current);
|
|
1052
|
+
if (next === current)
|
|
1053
|
+
break;
|
|
1054
|
+
current = next;
|
|
1055
|
+
}
|
|
1056
|
+
return current;
|
|
1057
|
+
}
|
|
1058
|
+
function resetPrefix(decoded) {
|
|
1059
|
+
const parts = decoded.split(/[/?#;]/);
|
|
1060
|
+
const index = parts.findIndex((part) => RESET_SEGMENT.test(part));
|
|
1061
|
+
const kept = parts.slice(0, index + 1).map((part) => containsCredential(part) ? REDACTED2 : part);
|
|
1062
|
+
return kept.join("/");
|
|
1063
|
+
}
|
|
1064
|
+
function snapshotUrl2(raw) {
|
|
1065
|
+
const value = raw.trim();
|
|
1066
|
+
if (value === "")
|
|
1067
|
+
return null;
|
|
1068
|
+
const absolute = /^[a-z][a-z0-9+.-]*:/i.test(value) || value.startsWith("//");
|
|
1069
|
+
let origin = "";
|
|
1070
|
+
let path;
|
|
1071
|
+
if (absolute) {
|
|
1072
|
+
let url;
|
|
1073
|
+
try {
|
|
1074
|
+
url = new URL(value.startsWith("//") ? `https:${value}` : value);
|
|
1075
|
+
} catch {
|
|
1076
|
+
return null;
|
|
1077
|
+
}
|
|
1078
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
1079
|
+
return null;
|
|
1080
|
+
origin = value.startsWith("//") ? `//${url.host}` : url.origin;
|
|
1081
|
+
path = url.pathname;
|
|
1082
|
+
} else {
|
|
1083
|
+
path = value.split(/[?#]/)[0] ?? "";
|
|
1084
|
+
}
|
|
1085
|
+
const segments = path.split("/");
|
|
1086
|
+
const decoded = segments.map(decodeSegment);
|
|
1087
|
+
const reset = decoded.findIndex((segment) => RESET_SEGMENT.test(segment));
|
|
1088
|
+
const kept = reset >= 0 ? segments.slice(0, reset + 1) : segments;
|
|
1089
|
+
const cleaned = kept.map((segment, index) => {
|
|
1090
|
+
const plain = decoded[index] ?? segment;
|
|
1091
|
+
if (index === reset)
|
|
1092
|
+
return resetPrefix(plain);
|
|
1093
|
+
return containsCredential(plain) || containsCredentialInUrl(segment) ? REDACTED2 : segment;
|
|
1094
|
+
}).join("/");
|
|
1095
|
+
return clip2(`${origin}${cleaned}`, MAX_SNAPSHOT_TEXT2);
|
|
1096
|
+
}
|
|
1097
|
+
var DESCRIPTIVE_ATTRIBUTES = new Set([
|
|
1098
|
+
"alt",
|
|
1099
|
+
"label",
|
|
1100
|
+
"title",
|
|
1101
|
+
"placeholder",
|
|
1102
|
+
"value",
|
|
1103
|
+
"aria-label",
|
|
1104
|
+
"aria-description",
|
|
1105
|
+
"aria-roledescription",
|
|
1106
|
+
"aria-placeholder"
|
|
1107
|
+
]);
|
|
1108
|
+
var STRUCTURAL_ARIA = new Set([
|
|
1109
|
+
"aria-hidden",
|
|
1110
|
+
"aria-disabled",
|
|
1111
|
+
"aria-expanded",
|
|
1112
|
+
"aria-haspopup",
|
|
1113
|
+
"aria-controls",
|
|
1114
|
+
"aria-owns",
|
|
1115
|
+
"aria-labelledby",
|
|
1116
|
+
"aria-describedby",
|
|
1117
|
+
"aria-level",
|
|
1118
|
+
"aria-current",
|
|
1119
|
+
"aria-modal",
|
|
1120
|
+
"aria-multiline",
|
|
1121
|
+
"aria-multiselectable",
|
|
1122
|
+
"aria-orientation",
|
|
1123
|
+
"aria-readonly",
|
|
1124
|
+
"aria-required",
|
|
1125
|
+
"aria-invalid",
|
|
1126
|
+
"aria-busy",
|
|
1127
|
+
"aria-live",
|
|
1128
|
+
"aria-atomic",
|
|
1129
|
+
"aria-posinset",
|
|
1130
|
+
"aria-setsize",
|
|
1131
|
+
"aria-colcount",
|
|
1132
|
+
"aria-colindex",
|
|
1133
|
+
"aria-colspan",
|
|
1134
|
+
"aria-rowcount",
|
|
1135
|
+
"aria-rowindex",
|
|
1136
|
+
"aria-rowspan",
|
|
1137
|
+
"aria-sort"
|
|
1138
|
+
]);
|
|
1139
|
+
function keptAttributes(element, marked) {
|
|
1140
|
+
const kept = {};
|
|
1141
|
+
const tag = element.localName;
|
|
1142
|
+
for (const attribute of Array.from(element.attributes)) {
|
|
1143
|
+
const name = attribute.name.toLowerCase();
|
|
1144
|
+
if (name.startsWith("on") || !ATTRIBUTE_NAME2.test(name))
|
|
1145
|
+
continue;
|
|
1146
|
+
if (marked && (DESCRIPTIVE_ATTRIBUTES.has(name) || name === "href" || name.startsWith("aria-") && !STRUCTURAL_ARIA.has(name))) {
|
|
1147
|
+
continue;
|
|
1148
|
+
}
|
|
1149
|
+
if (KEPT_ATTRIBUTES.has(name) || name.startsWith("aria-") && !DROPPED_ARIA.has(name)) {
|
|
1150
|
+
kept[name] = cleanText(attribute.value);
|
|
1151
|
+
} else if (name === "href" && (tag === "a" || tag === "area")) {
|
|
1152
|
+
const url = snapshotUrl2(attribute.value);
|
|
1153
|
+
if (url !== null)
|
|
1154
|
+
kept[name] = url;
|
|
1155
|
+
} else if (name === "value" && tag === "input" && BUTTON_INPUTS.has((element.getAttribute("type") ?? "").toLowerCase())) {
|
|
1156
|
+
kept[name] = cleanText(attribute.value);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
return Object.keys(kept).length > 0 ? kept : undefined;
|
|
1160
|
+
}
|
|
1161
|
+
function rectTuple(element, probe) {
|
|
1162
|
+
const box = probe?.rectOf?.(element) ?? element.getBoundingClientRect();
|
|
1163
|
+
const tuple = [
|
|
1164
|
+
Math.round(box.x),
|
|
1165
|
+
Math.round(box.y),
|
|
1166
|
+
Math.round(box.width),
|
|
1167
|
+
Math.round(box.height)
|
|
1168
|
+
];
|
|
1169
|
+
return tuple[2] > 0 || tuple[3] > 0 ? tuple : undefined;
|
|
1170
|
+
}
|
|
1171
|
+
function walkChildren(parent, state, depth, textAllowed, marked) {
|
|
1172
|
+
const children = [];
|
|
1173
|
+
for (const child of Array.from(parent.childNodes)) {
|
|
1174
|
+
if (state.count >= state.max) {
|
|
1175
|
+
state.truncated = true;
|
|
1176
|
+
break;
|
|
1177
|
+
}
|
|
1178
|
+
if (child.nodeType === 3) {
|
|
1179
|
+
if (!textAllowed || slottedTextHidden(child))
|
|
1180
|
+
continue;
|
|
1181
|
+
const raw = child.textContent ?? "";
|
|
1182
|
+
if (raw.length === 0)
|
|
1183
|
+
continue;
|
|
1184
|
+
const text = raw.trim() === "" ? " " : cleanText(raw);
|
|
1185
|
+
state.count += 1;
|
|
1186
|
+
children.push(text);
|
|
1187
|
+
} else if (child.nodeType === 1) {
|
|
1188
|
+
const node = walkElement(child, state, depth + 1, textAllowed, marked);
|
|
1189
|
+
if (node)
|
|
1190
|
+
children.push(node);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
return children;
|
|
1194
|
+
}
|
|
1195
|
+
function walkElement(element, state, depth, textAllowed, parentMarked) {
|
|
1196
|
+
const tag = element.localName.toLowerCase();
|
|
1197
|
+
if (SKIPPED.has(tag) || !TAG_NAME.test(tag))
|
|
1198
|
+
return null;
|
|
1199
|
+
if (depth > MAX_SNAPSHOT_DEPTH2) {
|
|
1200
|
+
state.truncated = true;
|
|
1201
|
+
return null;
|
|
1202
|
+
}
|
|
1203
|
+
state.count += 1;
|
|
1204
|
+
const node = { t: tag };
|
|
1205
|
+
const inFieldValue = hasFieldValueAncestor(element);
|
|
1206
|
+
const marked = parentMarked || inFieldValue || isMarkedSensitive(element);
|
|
1207
|
+
const attributes = keptAttributes(element, marked);
|
|
1208
|
+
if (attributes)
|
|
1209
|
+
node.a = attributes;
|
|
1210
|
+
if (isElementVisible2(element, state.probe)) {
|
|
1211
|
+
const rect = rectTuple(element, state.probe);
|
|
1212
|
+
if (rect)
|
|
1213
|
+
node.r = rect;
|
|
1214
|
+
} else {
|
|
1215
|
+
node.h = 1;
|
|
1216
|
+
}
|
|
1217
|
+
const sensitive = isSensitiveElement2(element);
|
|
1218
|
+
const childText = textAllowed && !inFieldValue && !sensitive && !VALUE_CONTENT.has(tag) && !isEditingHost2(element);
|
|
1219
|
+
const childMarked = marked || !childText;
|
|
1220
|
+
if (tag === "svg") {
|
|
1221
|
+
const title = Array.from(element.children).find((child) => child.localName === "title");
|
|
1222
|
+
const titleNode = title ? walkElement(title, state, depth + 1, childText, childMarked) : null;
|
|
1223
|
+
if (titleNode)
|
|
1224
|
+
node.c = [titleNode];
|
|
1225
|
+
return node;
|
|
1226
|
+
}
|
|
1227
|
+
if (tag === "iframe" || tag === "frame") {
|
|
1228
|
+
let inner = null;
|
|
1229
|
+
try {
|
|
1230
|
+
inner = element.contentDocument;
|
|
1231
|
+
} catch {
|
|
1232
|
+
inner = null;
|
|
1233
|
+
}
|
|
1234
|
+
const innerRoot = inner?.documentElement;
|
|
1235
|
+
if (innerRoot) {
|
|
1236
|
+
const frame = walkElement(innerRoot, state, depth + 1, childText, childMarked);
|
|
1237
|
+
if (frame)
|
|
1238
|
+
node.f = frame;
|
|
1239
|
+
}
|
|
1240
|
+
return node;
|
|
1241
|
+
}
|
|
1242
|
+
const children = walkChildren(element, state, depth, childText, childMarked);
|
|
1243
|
+
if (children.length > 0)
|
|
1244
|
+
node.c = children;
|
|
1245
|
+
const shadow = element.shadowRoot;
|
|
1246
|
+
if (shadow) {
|
|
1247
|
+
const shadowChildren = walkChildren(shadow, state, depth, childText, childMarked);
|
|
1248
|
+
if (shadowChildren.length > 0)
|
|
1249
|
+
node.s = shadowChildren;
|
|
1250
|
+
}
|
|
1251
|
+
return node;
|
|
1252
|
+
}
|
|
1253
|
+
function pageTitle(document) {
|
|
1254
|
+
const element = document.querySelector("title");
|
|
1255
|
+
if (element && isMarkedSensitive(element))
|
|
1256
|
+
return "";
|
|
1257
|
+
return cleanText(document.title ?? "");
|
|
1258
|
+
}
|
|
1259
|
+
function serializeTreeSnapshot2(document, options = {}) {
|
|
1260
|
+
const state = {
|
|
1261
|
+
count: 0,
|
|
1262
|
+
max: Math.max(1, options.maxNodes ?? DEFAULT_SNAPSHOT_MAX_NODES2),
|
|
1263
|
+
truncated: false,
|
|
1264
|
+
probe: options
|
|
1265
|
+
};
|
|
1266
|
+
const root = walkElement(document.documentElement, state, 0, true, false) ?? { t: "html" };
|
|
1267
|
+
const view = document.defaultView;
|
|
1268
|
+
return {
|
|
1269
|
+
snapshotVersion: UI_TREE_SNAPSHOT_VERSION2,
|
|
1270
|
+
url: snapshotUrl2(document.URL) ?? "",
|
|
1271
|
+
title: pageTitle(document),
|
|
1272
|
+
viewport: { width: Math.round(view?.innerWidth ?? 0), height: Math.round(view?.innerHeight ?? 0) },
|
|
1273
|
+
root,
|
|
1274
|
+
nodeCount: state.count,
|
|
1275
|
+
truncated: state.truncated
|
|
1276
|
+
};
|
|
1277
|
+
}
|
|
1278
|
+
function appendChildren(document, parent, children, state) {
|
|
1279
|
+
for (const child of children ?? []) {
|
|
1280
|
+
if (typeof child === "string")
|
|
1281
|
+
parent.appendChild(document.createTextNode(child));
|
|
1282
|
+
else {
|
|
1283
|
+
const element = buildElement(document, child, state);
|
|
1284
|
+
if (element)
|
|
1285
|
+
parent.appendChild(element);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
function applyNode(document, element, node, state) {
|
|
1290
|
+
for (const [name, value] of Object.entries(node.a ?? {})) {
|
|
1291
|
+
if (!ATTRIBUTE_NAME2.test(name) || name.startsWith("on"))
|
|
1292
|
+
continue;
|
|
1293
|
+
if (name === "href" && snapshotUrl2(value) === null)
|
|
1294
|
+
continue;
|
|
1295
|
+
element.setAttribute(name, value);
|
|
1296
|
+
}
|
|
1297
|
+
if (node.r)
|
|
1298
|
+
state.rects.set(element, { x: node.r[0], y: node.r[1], width: node.r[2], height: node.r[3] });
|
|
1299
|
+
if (node.h)
|
|
1300
|
+
state.hidden.add(element);
|
|
1301
|
+
if (node.f && (node.t === "iframe" || node.t === "frame")) {
|
|
1302
|
+
element.setAttribute("srcdoc", EMPTY_FRAME_DOCUMENT);
|
|
1303
|
+
state.frames.push({ element, root: node.f });
|
|
1304
|
+
}
|
|
1305
|
+
appendChildren(document, element, node.c, state);
|
|
1306
|
+
}
|
|
1307
|
+
function buildElement(document, node, state) {
|
|
1308
|
+
if (!TAG_NAME.test(node.t) || SKIPPED.has(node.t))
|
|
1309
|
+
return null;
|
|
1310
|
+
const element = document.createElement(node.t);
|
|
1311
|
+
applyNode(document, element, node, state);
|
|
1312
|
+
if (node.s && node.s.length > 0) {
|
|
1313
|
+
let shadow = null;
|
|
1314
|
+
try {
|
|
1315
|
+
shadow = element.attachShadow({ mode: "open" });
|
|
1316
|
+
} catch {
|
|
1317
|
+
shadow = null;
|
|
1318
|
+
}
|
|
1319
|
+
appendChildren(document, shadow ?? element, node.s, state);
|
|
1320
|
+
}
|
|
1321
|
+
return element;
|
|
1322
|
+
}
|
|
1323
|
+
function hydrateInto(document, root, state) {
|
|
1324
|
+
const html = document.documentElement;
|
|
1325
|
+
while (html.firstChild)
|
|
1326
|
+
html.removeChild(html.firstChild);
|
|
1327
|
+
for (const attribute of Array.from(html.attributes))
|
|
1328
|
+
html.removeAttribute(attribute.name);
|
|
1329
|
+
applyNode(document, html, root, state);
|
|
1330
|
+
const frames = state.frames.splice(0);
|
|
1331
|
+
for (const frame of frames) {
|
|
1332
|
+
const inner = frame.element.contentDocument;
|
|
1333
|
+
if (inner?.documentElement)
|
|
1334
|
+
hydrateInto(inner, frame.root, state);
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
function hydrateTreeSnapshot2(document, snapshot) {
|
|
1338
|
+
const state = { rects: new WeakMap, hidden: new WeakSet, frames: [] };
|
|
1339
|
+
hydrateInto(document, snapshot.root, state);
|
|
1340
|
+
const zero = { x: 0, y: 0, width: 0, height: 0 };
|
|
1341
|
+
return {
|
|
1342
|
+
probe: {
|
|
1343
|
+
rectOf: (element) => state.rects.get(element) ?? zero,
|
|
1344
|
+
isVisible: (element) => !state.hidden.has(element) && element.isConnected
|
|
1345
|
+
}
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
export { WEB_TARGET_ERROR_CODES2, MAX_CANDIDATES2, MAX_CANDIDATE_NAME2, SENSITIVE_MARKERS2, hasSensitiveMarker2, MAX_COMPARED_TEXT2, normaliseText2, sameText2, containsText2, editDistance2, textSimilarity2, clip2, MAX_NAME_LENGTH3, MAX_VISIBLE_TEXT2, roleOf2, isTypedContent2, accessibleName2, labelName2, visibleText2, matchesRoleAndName2, parentAcrossShadow2, isElementVisible2, isElementEnabled2, elementRect2, elementsUnder2, isSecretFieldName2, isSensitiveElement2, DEFAULT_FUZZY_THRESHOLD2, FUZZY_MARGIN2, ANCHOR_MARGIN_PX2, MAX_XPATH_RESULTS2, INTERACTIVE_ROLES2, relationDistance2, matchMethod2, enterFrames2, describeCandidate2, resolveWebTarget2, UI_TREE_SNAPSHOT_VERSION2, DEFAULT_SNAPSHOT_MAX_NODES2, MAX_SNAPSHOT_DEPTH2, MAX_SNAPSHOT_TEXT2, snapshotUrl2, serializeTreeSnapshot2, hydrateTreeSnapshot2 };
|