@page-agent/page-controller 1.7.1 → 1.8.0-beta.0
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/dist/lib/{SimulatorMask-CU7szDjy.js → SimulatorMask-BfJiQVCo.js} +76 -98
- package/dist/lib/SimulatorMask-BfJiQVCo.js.map +1 -0
- package/dist/lib/page-controller.js +32 -85
- package/dist/lib/page-controller.js.map +1 -1
- package/package.json +5 -5
- package/dist/lib/SimulatorMask-CU7szDjy.js.map +0 -1
|
@@ -1,40 +1,30 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
function isHTMLElement(el) {
|
|
4
2
|
return !!el && el.nodeType === 1;
|
|
5
3
|
}
|
|
6
|
-
__name(isHTMLElement, "isHTMLElement");
|
|
7
4
|
function isInputElement(el) {
|
|
8
5
|
return el?.nodeType === 1 && el.tagName === "INPUT";
|
|
9
6
|
}
|
|
10
|
-
__name(isInputElement, "isInputElement");
|
|
11
7
|
function isTextAreaElement(el) {
|
|
12
8
|
return el?.nodeType === 1 && el.tagName === "TEXTAREA";
|
|
13
9
|
}
|
|
14
|
-
__name(isTextAreaElement, "isTextAreaElement");
|
|
15
10
|
function isSelectElement(el) {
|
|
16
11
|
return el?.nodeType === 1 && el.tagName === "SELECT";
|
|
17
12
|
}
|
|
18
|
-
__name(isSelectElement, "isSelectElement");
|
|
19
13
|
function isAnchorElement(el) {
|
|
20
14
|
return el?.nodeType === 1 && el.tagName === "A";
|
|
21
15
|
}
|
|
22
|
-
__name(isAnchorElement, "isAnchorElement");
|
|
23
16
|
function getIframeOffset(element) {
|
|
24
17
|
const frame = element.ownerDocument.defaultView?.frameElement;
|
|
25
18
|
if (!frame) return { x: 0, y: 0 };
|
|
26
19
|
const rect = frame.getBoundingClientRect();
|
|
27
20
|
return { x: rect.left, y: rect.top };
|
|
28
21
|
}
|
|
29
|
-
__name(getIframeOffset, "getIframeOffset");
|
|
30
22
|
function getNativeValueSetter(element) {
|
|
31
23
|
return Object.getOwnPropertyDescriptor(Object.getPrototypeOf(element), "value").set;
|
|
32
24
|
}
|
|
33
|
-
__name(getNativeValueSetter, "getNativeValueSetter");
|
|
34
25
|
async function waitFor(seconds) {
|
|
35
26
|
await new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
|
|
36
27
|
}
|
|
37
|
-
__name(waitFor, "waitFor");
|
|
38
28
|
async function movePointerToElement(element, x, y) {
|
|
39
29
|
const offset = getIframeOffset(element);
|
|
40
30
|
window.dispatchEvent(
|
|
@@ -44,19 +34,15 @@ async function movePointerToElement(element, x, y) {
|
|
|
44
34
|
);
|
|
45
35
|
await waitFor(0.3);
|
|
46
36
|
}
|
|
47
|
-
__name(movePointerToElement, "movePointerToElement");
|
|
48
37
|
async function clickPointer() {
|
|
49
38
|
window.dispatchEvent(new CustomEvent("PageAgent::ClickPointer"));
|
|
50
39
|
}
|
|
51
|
-
__name(clickPointer, "clickPointer");
|
|
52
40
|
async function enablePassThrough() {
|
|
53
41
|
window.dispatchEvent(new CustomEvent("PageAgent::EnablePassThrough"));
|
|
54
42
|
}
|
|
55
|
-
__name(enablePassThrough, "enablePassThrough");
|
|
56
43
|
async function disablePassThrough() {
|
|
57
44
|
window.dispatchEvent(new CustomEvent("PageAgent::DisablePassThrough"));
|
|
58
45
|
}
|
|
59
|
-
__name(disablePassThrough, "disablePassThrough");
|
|
60
46
|
function getElementByIndex(selectorMap, index) {
|
|
61
47
|
const interactiveNode = selectorMap.get(index);
|
|
62
48
|
if (!interactiveNode) {
|
|
@@ -71,7 +57,6 @@ function getElementByIndex(selectorMap, index) {
|
|
|
71
57
|
}
|
|
72
58
|
return element;
|
|
73
59
|
}
|
|
74
|
-
__name(getElementByIndex, "getElementByIndex");
|
|
75
60
|
let lastClickedElement = null;
|
|
76
61
|
function blurLastClickedElement() {
|
|
77
62
|
if (lastClickedElement) {
|
|
@@ -83,7 +68,6 @@ function blurLastClickedElement() {
|
|
|
83
68
|
lastClickedElement = null;
|
|
84
69
|
}
|
|
85
70
|
}
|
|
86
|
-
__name(blurLastClickedElement, "blurLastClickedElement");
|
|
87
71
|
async function clickElement(element) {
|
|
88
72
|
blurLastClickedElement();
|
|
89
73
|
lastClickedElement = element;
|
|
@@ -121,7 +105,6 @@ async function clickElement(element) {
|
|
|
121
105
|
target.click();
|
|
122
106
|
await waitFor(0.2);
|
|
123
107
|
}
|
|
124
|
-
__name(clickElement, "clickElement");
|
|
125
108
|
async function inputTextElement(element, text) {
|
|
126
109
|
const isContentEditable = element.isContentEditable;
|
|
127
110
|
if (!isInputElement(element) && !isTextAreaElement(element) && !isContentEditable) {
|
|
@@ -184,7 +167,6 @@ async function inputTextElement(element, text) {
|
|
|
184
167
|
await waitFor(0.1);
|
|
185
168
|
blurLastClickedElement();
|
|
186
169
|
}
|
|
187
|
-
__name(inputTextElement, "inputTextElement");
|
|
188
170
|
async function selectOptionElement(selectElement, optionText) {
|
|
189
171
|
if (!isSelectElement(selectElement)) {
|
|
190
172
|
throw new Error("Element is not a select element");
|
|
@@ -198,7 +180,6 @@ async function selectOptionElement(selectElement, optionText) {
|
|
|
198
180
|
selectElement.dispatchEvent(new Event("change", { bubbles: true }));
|
|
199
181
|
await waitFor(0.1);
|
|
200
182
|
}
|
|
201
|
-
__name(selectOptionElement, "selectOptionElement");
|
|
202
183
|
async function scrollIntoViewIfNeeded(element) {
|
|
203
184
|
const el = element;
|
|
204
185
|
if (typeof el.scrollIntoViewIfNeeded === "function") {
|
|
@@ -207,7 +188,6 @@ async function scrollIntoViewIfNeeded(element) {
|
|
|
207
188
|
element.scrollIntoView({ behavior: "auto", block: "center", inline: "nearest" });
|
|
208
189
|
}
|
|
209
190
|
}
|
|
210
|
-
__name(scrollIntoViewIfNeeded, "scrollIntoViewIfNeeded");
|
|
211
191
|
async function scrollVertically(scroll_amount, element) {
|
|
212
192
|
if (element) {
|
|
213
193
|
const targetElement = element;
|
|
@@ -253,8 +233,8 @@ async function scrollVertically(scroll_amount, element) {
|
|
|
253
233
|
}
|
|
254
234
|
}
|
|
255
235
|
const dy = scroll_amount;
|
|
256
|
-
const bigEnough =
|
|
257
|
-
const canScroll =
|
|
236
|
+
const bigEnough = (el2) => el2.clientHeight >= window.innerHeight * 0.5;
|
|
237
|
+
const canScroll = (el2) => el2 && /(auto|scroll|overlay)/.test(getComputedStyle(el2).overflowY) && el2.scrollHeight > el2.clientHeight && bigEnough(el2);
|
|
258
238
|
let el = document.activeElement;
|
|
259
239
|
while (el && !canScroll(el) && el !== document.body) el = el.parentElement;
|
|
260
240
|
el = canScroll(el) ? el : Array.from(document.querySelectorAll("*")).find(canScroll) || document.scrollingElement || document.documentElement;
|
|
@@ -293,7 +273,6 @@ async function scrollVertically(scroll_amount, element) {
|
|
|
293
273
|
return `✅ ${warningMsg} Scrolled container (${el.tagName}) by ${scrolled}px.`;
|
|
294
274
|
}
|
|
295
275
|
}
|
|
296
|
-
__name(scrollVertically, "scrollVertically");
|
|
297
276
|
async function scrollHorizontally(scroll_amount, element) {
|
|
298
277
|
if (element) {
|
|
299
278
|
const targetElement = element;
|
|
@@ -339,8 +318,8 @@ async function scrollHorizontally(scroll_amount, element) {
|
|
|
339
318
|
}
|
|
340
319
|
}
|
|
341
320
|
const dx = scroll_amount;
|
|
342
|
-
const bigEnough =
|
|
343
|
-
const canScroll =
|
|
321
|
+
const bigEnough = (el2) => el2.clientWidth >= window.innerWidth * 0.5;
|
|
322
|
+
const canScroll = (el2) => el2 && /(auto|scroll|overlay)/.test(getComputedStyle(el2).overflowX) && el2.scrollWidth > el2.clientWidth && bigEnough(el2);
|
|
344
323
|
let el = document.activeElement;
|
|
345
324
|
while (el && !canScroll(el) && el !== document.body) el = el.parentElement;
|
|
346
325
|
el = canScroll(el) ? el : Array.from(document.querySelectorAll("*")).find(canScroll) || document.scrollingElement || document.documentElement;
|
|
@@ -380,8 +359,7 @@ async function scrollHorizontally(scroll_amount, element) {
|
|
|
380
359
|
return `✅ ${warningMsg} Scrolled container (${el.tagName}) horizontally by ${scrolled}px.`;
|
|
381
360
|
}
|
|
382
361
|
}
|
|
383
|
-
|
|
384
|
-
const domTree = /* @__PURE__ */ __name((args = {
|
|
362
|
+
const domTree = (args = {
|
|
385
363
|
doHighlightElements: true,
|
|
386
364
|
focusHighlightIndex: -1,
|
|
387
365
|
viewportExpansion: 0,
|
|
@@ -404,16 +382,15 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
404
382
|
if (!element || element.nodeType !== Node.ELEMENT_NODE) return;
|
|
405
383
|
extraData.set(element, { ...extraData.get(element), ...data });
|
|
406
384
|
}
|
|
407
|
-
__name(addExtraData, "addExtraData");
|
|
408
385
|
const DOM_CACHE = {
|
|
409
386
|
boundingRects: /* @__PURE__ */ new WeakMap(),
|
|
410
387
|
clientRects: /* @__PURE__ */ new WeakMap(),
|
|
411
388
|
computedStyles: /* @__PURE__ */ new WeakMap(),
|
|
412
|
-
clearCache:
|
|
389
|
+
clearCache: () => {
|
|
413
390
|
DOM_CACHE.boundingRects = /* @__PURE__ */ new WeakMap();
|
|
414
391
|
DOM_CACHE.clientRects = /* @__PURE__ */ new WeakMap();
|
|
415
392
|
DOM_CACHE.computedStyles = /* @__PURE__ */ new WeakMap();
|
|
416
|
-
}
|
|
393
|
+
}
|
|
417
394
|
};
|
|
418
395
|
function getCachedBoundingRect(element) {
|
|
419
396
|
if (!element) return null;
|
|
@@ -426,7 +403,6 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
426
403
|
}
|
|
427
404
|
return rect;
|
|
428
405
|
}
|
|
429
|
-
__name(getCachedBoundingRect, "getCachedBoundingRect");
|
|
430
406
|
function getCachedComputedStyle(element) {
|
|
431
407
|
if (!element) return null;
|
|
432
408
|
if (DOM_CACHE.computedStyles.has(element)) {
|
|
@@ -438,7 +414,6 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
438
414
|
}
|
|
439
415
|
return style;
|
|
440
416
|
}
|
|
441
|
-
__name(getCachedComputedStyle, "getCachedComputedStyle");
|
|
442
417
|
function getCachedClientRects(element) {
|
|
443
418
|
if (!element) return null;
|
|
444
419
|
if (DOM_CACHE.clientRects.has(element)) {
|
|
@@ -450,7 +425,6 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
450
425
|
}
|
|
451
426
|
return rects;
|
|
452
427
|
}
|
|
453
|
-
__name(getCachedClientRects, "getCachedClientRects");
|
|
454
428
|
const DOM_HASH_MAP = {};
|
|
455
429
|
const ID = { current: 0 };
|
|
456
430
|
const HIGHLIGHT_CONTAINER_ID = "playwright-highlight-container";
|
|
@@ -546,7 +520,7 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
546
520
|
label.style.top = `${labelTop}px`;
|
|
547
521
|
label.style.left = `${labelLeft}px`;
|
|
548
522
|
fragment.appendChild(label);
|
|
549
|
-
const updatePositions =
|
|
523
|
+
const updatePositions = () => {
|
|
550
524
|
const newRects = element.getClientRects();
|
|
551
525
|
let newIframeOffset = { x: 0, y: 0 };
|
|
552
526
|
if (parentIframe) {
|
|
@@ -592,8 +566,8 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
592
566
|
} else if (label) {
|
|
593
567
|
label.style.display = "none";
|
|
594
568
|
}
|
|
595
|
-
}
|
|
596
|
-
const throttleFunction =
|
|
569
|
+
};
|
|
570
|
+
const throttleFunction = (func, delay) => {
|
|
597
571
|
let lastCall = 0;
|
|
598
572
|
return (...args2) => {
|
|
599
573
|
const now = performance.now();
|
|
@@ -601,16 +575,16 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
601
575
|
lastCall = now;
|
|
602
576
|
return func(...args2);
|
|
603
577
|
};
|
|
604
|
-
}
|
|
578
|
+
};
|
|
605
579
|
const throttledUpdatePositions = throttleFunction(updatePositions, 16);
|
|
606
580
|
window.addEventListener("scroll", throttledUpdatePositions, true);
|
|
607
581
|
window.addEventListener("resize", throttledUpdatePositions);
|
|
608
|
-
cleanupFn =
|
|
582
|
+
cleanupFn = () => {
|
|
609
583
|
window.removeEventListener("scroll", throttledUpdatePositions, true);
|
|
610
584
|
window.removeEventListener("resize", throttledUpdatePositions);
|
|
611
585
|
overlays.forEach((overlay) => overlay.element.remove());
|
|
612
586
|
if (label) label.remove();
|
|
613
|
-
}
|
|
587
|
+
};
|
|
614
588
|
container.appendChild(fragment);
|
|
615
589
|
return index + 1;
|
|
616
590
|
} finally {
|
|
@@ -621,7 +595,6 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
621
595
|
}
|
|
622
596
|
}
|
|
623
597
|
}
|
|
624
|
-
__name(highlightElement, "highlightElement");
|
|
625
598
|
function isScrollableElement(element) {
|
|
626
599
|
if (!element || element.nodeType !== Node.ELEMENT_NODE) {
|
|
627
600
|
return null;
|
|
@@ -669,7 +642,6 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
669
642
|
console.log("scrollData!!!", scrollData);
|
|
670
643
|
return scrollData;
|
|
671
644
|
}
|
|
672
|
-
__name(isScrollableElement, "isScrollableElement");
|
|
673
645
|
function isTextNodeVisible(textNode) {
|
|
674
646
|
try {
|
|
675
647
|
if (viewportExpansion === -1) {
|
|
@@ -721,7 +693,6 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
721
693
|
return false;
|
|
722
694
|
}
|
|
723
695
|
}
|
|
724
|
-
__name(isTextNodeVisible, "isTextNodeVisible");
|
|
725
696
|
function isElementAccepted(element) {
|
|
726
697
|
if (!element || !element.tagName) return false;
|
|
727
698
|
const alwaysAccept = /* @__PURE__ */ new Set([
|
|
@@ -747,12 +718,10 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
747
718
|
]);
|
|
748
719
|
return !leafElementDenyList.has(tagName);
|
|
749
720
|
}
|
|
750
|
-
__name(isElementAccepted, "isElementAccepted");
|
|
751
721
|
function isElementVisible(element) {
|
|
752
722
|
const style = getCachedComputedStyle(element);
|
|
753
723
|
return element.offsetWidth > 0 && element.offsetHeight > 0 && style?.visibility !== "hidden" && style?.display !== "none";
|
|
754
724
|
}
|
|
755
|
-
__name(isElementVisible, "isElementVisible");
|
|
756
725
|
function isInteractiveElement(element) {
|
|
757
726
|
if (!element || element.nodeType !== Node.ELEMENT_NODE) {
|
|
758
727
|
return false;
|
|
@@ -848,7 +817,6 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
848
817
|
if (style?.cursor && interactiveCursors.has(style.cursor)) return true;
|
|
849
818
|
return false;
|
|
850
819
|
}
|
|
851
|
-
__name(doesElementHaveInteractivePointer, "doesElementHaveInteractivePointer");
|
|
852
820
|
let isInteractiveCursor = doesElementHaveInteractivePointer(element);
|
|
853
821
|
if (isInteractiveCursor) {
|
|
854
822
|
return true;
|
|
@@ -1008,7 +976,6 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
1008
976
|
}
|
|
1009
977
|
return false;
|
|
1010
978
|
}
|
|
1011
|
-
__name(isInteractiveElement, "isInteractiveElement");
|
|
1012
979
|
function isTopElement(element) {
|
|
1013
980
|
if (viewportExpansion === -1) {
|
|
1014
981
|
return true;
|
|
@@ -1079,7 +1046,6 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
1079
1046
|
}
|
|
1080
1047
|
});
|
|
1081
1048
|
}
|
|
1082
|
-
__name(isTopElement, "isTopElement");
|
|
1083
1049
|
function isInExpandedViewport(element, viewportExpansion2) {
|
|
1084
1050
|
if (viewportExpansion2 === -1) {
|
|
1085
1051
|
return true;
|
|
@@ -1100,7 +1066,6 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
1100
1066
|
}
|
|
1101
1067
|
return false;
|
|
1102
1068
|
}
|
|
1103
|
-
__name(isInExpandedViewport, "isInExpandedViewport");
|
|
1104
1069
|
const INTERACTIVE_ARIA_ATTRS = [
|
|
1105
1070
|
"aria-expanded",
|
|
1106
1071
|
"aria-checked",
|
|
@@ -1122,7 +1087,6 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
1122
1087
|
}
|
|
1123
1088
|
return false;
|
|
1124
1089
|
}
|
|
1125
|
-
__name(hasInteractiveAria, "hasInteractiveAria");
|
|
1126
1090
|
function isInteractiveCandidate(element) {
|
|
1127
1091
|
if (!element || element.nodeType !== Node.ELEMENT_NODE) return false;
|
|
1128
1092
|
const tagName = element.tagName.toLowerCase();
|
|
@@ -1140,7 +1104,6 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
1140
1104
|
const hasQuickInteractiveAttr = element.hasAttribute("onclick") || element.hasAttribute("role") || element.hasAttribute("tabindex") || hasInteractiveAria(element) || element.hasAttribute("data-action") || element.getAttribute("contenteditable") === "true";
|
|
1141
1105
|
return hasQuickInteractiveAttr;
|
|
1142
1106
|
}
|
|
1143
|
-
__name(isInteractiveCandidate, "isInteractiveCandidate");
|
|
1144
1107
|
const DISTINCT_INTERACTIVE_TAGS = /* @__PURE__ */ new Set([
|
|
1145
1108
|
"a",
|
|
1146
1109
|
"button",
|
|
@@ -1189,7 +1152,6 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
1189
1152
|
const isParentBody = element.parentElement && element.parentElement.isSameNode(document.body);
|
|
1190
1153
|
return (isInteractiveElement(element) || hasInteractiveAttributes || hasInteractiveClass) && hasVisibleChildren && isInKnownContainer && !isParentBody;
|
|
1191
1154
|
}
|
|
1192
|
-
__name(isHeuristicallyInteractive, "isHeuristicallyInteractive");
|
|
1193
1155
|
function isElementDistinctInteraction(element) {
|
|
1194
1156
|
if (!element || element.nodeType !== Node.ELEMENT_NODE) {
|
|
1195
1157
|
return false;
|
|
@@ -1265,7 +1227,6 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
1265
1227
|
}
|
|
1266
1228
|
return false;
|
|
1267
1229
|
}
|
|
1268
|
-
__name(isElementDistinctInteraction, "isElementDistinctInteraction");
|
|
1269
1230
|
function handleHighlighting(nodeData, node, parentIframe, isParentHighlighted) {
|
|
1270
1231
|
if (!nodeData.isInteractive) return false;
|
|
1271
1232
|
let shouldHighlight = false;
|
|
@@ -1296,7 +1257,6 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
1296
1257
|
}
|
|
1297
1258
|
return false;
|
|
1298
1259
|
}
|
|
1299
|
-
__name(handleHighlighting, "handleHighlighting");
|
|
1300
1260
|
function buildDomTree(node, parentIframe = null, isParentHighlighted = false) {
|
|
1301
1261
|
if (!node || node.id === HIGHLIGHT_CONTAINER_ID || node.nodeType !== Node.ELEMENT_NODE && node.nodeType !== Node.TEXT_NODE) {
|
|
1302
1262
|
return null;
|
|
@@ -1443,16 +1403,14 @@ const domTree = /* @__PURE__ */ __name((args = {
|
|
|
1443
1403
|
DOM_HASH_MAP[id] = nodeData;
|
|
1444
1404
|
return id;
|
|
1445
1405
|
}
|
|
1446
|
-
__name(buildDomTree, "buildDomTree");
|
|
1447
1406
|
const rootId = buildDomTree(document.body);
|
|
1448
1407
|
DOM_CACHE.clearCache();
|
|
1449
1408
|
return { rootId, map: DOM_HASH_MAP };
|
|
1450
|
-
}
|
|
1409
|
+
};
|
|
1451
1410
|
const DEFAULT_VIEWPORT_EXPANSION = -1;
|
|
1452
1411
|
function resolveViewportExpansion(viewportExpansion) {
|
|
1453
1412
|
return viewportExpansion ?? DEFAULT_VIEWPORT_EXPANSION;
|
|
1454
1413
|
}
|
|
1455
|
-
__name(resolveViewportExpansion, "resolveViewportExpansion");
|
|
1456
1414
|
const SEMANTIC_TAGS = /* @__PURE__ */ new Set([
|
|
1457
1415
|
"nav",
|
|
1458
1416
|
"menu",
|
|
@@ -1506,7 +1464,6 @@ function getFlatTree(config) {
|
|
|
1506
1464
|
}
|
|
1507
1465
|
return elements;
|
|
1508
1466
|
}
|
|
1509
|
-
__name(getFlatTree, "getFlatTree");
|
|
1510
1467
|
const globRegexCache = /* @__PURE__ */ new Map();
|
|
1511
1468
|
function globToRegex(pattern) {
|
|
1512
1469
|
let regex = globRegexCache.get(pattern);
|
|
@@ -1517,7 +1474,6 @@ function globToRegex(pattern) {
|
|
|
1517
1474
|
}
|
|
1518
1475
|
return regex;
|
|
1519
1476
|
}
|
|
1520
|
-
__name(globToRegex, "globToRegex");
|
|
1521
1477
|
function matchAttributes(attrs, patterns) {
|
|
1522
1478
|
const result2 = {};
|
|
1523
1479
|
for (const pattern of patterns) {
|
|
@@ -1537,7 +1493,6 @@ function matchAttributes(attrs, patterns) {
|
|
|
1537
1493
|
}
|
|
1538
1494
|
return result2;
|
|
1539
1495
|
}
|
|
1540
|
-
__name(matchAttributes, "matchAttributes");
|
|
1541
1496
|
function flatTreeToString(flatTree, includeAttributes = [], keepSemanticTags = false) {
|
|
1542
1497
|
const DEFAULT_INCLUDE_ATTRIBUTES = [
|
|
1543
1498
|
"title",
|
|
@@ -1566,13 +1521,13 @@ function flatTreeToString(flatTree, includeAttributes = [], keepSemanticTags = f
|
|
|
1566
1521
|
"contenteditable"
|
|
1567
1522
|
];
|
|
1568
1523
|
const includeAttrs = [...includeAttributes, ...DEFAULT_INCLUDE_ATTRIBUTES];
|
|
1569
|
-
const capTextLength =
|
|
1524
|
+
const capTextLength = (text, maxLength) => {
|
|
1570
1525
|
if (text.length > maxLength) {
|
|
1571
1526
|
return text.substring(0, maxLength) + "...";
|
|
1572
1527
|
}
|
|
1573
1528
|
return text;
|
|
1574
|
-
}
|
|
1575
|
-
const buildTreeNode =
|
|
1529
|
+
};
|
|
1530
|
+
const buildTreeNode = (nodeId) => {
|
|
1576
1531
|
const node = flatTree.map[nodeId];
|
|
1577
1532
|
if (!node) return null;
|
|
1578
1533
|
if (node.type === "TEXT_NODE") {
|
|
@@ -1610,17 +1565,17 @@ function flatTreeToString(flatTree, includeAttributes = [], keepSemanticTags = f
|
|
|
1610
1565
|
extra: elementNode.extra ?? {}
|
|
1611
1566
|
};
|
|
1612
1567
|
}
|
|
1613
|
-
}
|
|
1614
|
-
const setParentReferences =
|
|
1568
|
+
};
|
|
1569
|
+
const setParentReferences = (node, parent = null) => {
|
|
1615
1570
|
node.parent = parent;
|
|
1616
1571
|
for (const child of node.children) {
|
|
1617
1572
|
setParentReferences(child, node);
|
|
1618
1573
|
}
|
|
1619
|
-
}
|
|
1574
|
+
};
|
|
1620
1575
|
const rootNode = buildTreeNode(flatTree.rootId);
|
|
1621
1576
|
if (!rootNode) return "";
|
|
1622
1577
|
setParentReferences(rootNode);
|
|
1623
|
-
const hasParentWithHighlightIndex =
|
|
1578
|
+
const hasParentWithHighlightIndex = (node) => {
|
|
1624
1579
|
let current = node.parent;
|
|
1625
1580
|
while (current) {
|
|
1626
1581
|
if (current.type === "element" && current.highlightIndex !== void 0) {
|
|
@@ -1629,8 +1584,8 @@ function flatTreeToString(flatTree, includeAttributes = [], keepSemanticTags = f
|
|
|
1629
1584
|
current = current.parent;
|
|
1630
1585
|
}
|
|
1631
1586
|
return false;
|
|
1632
|
-
}
|
|
1633
|
-
const processNode =
|
|
1587
|
+
};
|
|
1588
|
+
const processNode = (node, depth, result22) => {
|
|
1634
1589
|
let nextDepth = depth;
|
|
1635
1590
|
const depthStr = " ".repeat(depth);
|
|
1636
1591
|
if (node.type === "element") {
|
|
@@ -1726,15 +1681,14 @@ function flatTreeToString(flatTree, includeAttributes = [], keepSemanticTags = f
|
|
|
1726
1681
|
result22.push(`${depthStr}${node.text ?? ""}`);
|
|
1727
1682
|
}
|
|
1728
1683
|
}
|
|
1729
|
-
}
|
|
1684
|
+
};
|
|
1730
1685
|
const result2 = [];
|
|
1731
1686
|
processNode(rootNode, 0, result2);
|
|
1732
1687
|
return result2.join("\n");
|
|
1733
1688
|
}
|
|
1734
|
-
|
|
1735
|
-
const getAllTextTillNextClickableElement = /* @__PURE__ */ __name((node, maxDepth = -1) => {
|
|
1689
|
+
const getAllTextTillNextClickableElement = (node, maxDepth = -1) => {
|
|
1736
1690
|
const textParts = [];
|
|
1737
|
-
const collectText =
|
|
1691
|
+
const collectText = (currentNode, currentDepth) => {
|
|
1738
1692
|
if (maxDepth !== -1 && currentDepth > maxDepth) {
|
|
1739
1693
|
return;
|
|
1740
1694
|
}
|
|
@@ -1748,10 +1702,10 @@ const getAllTextTillNextClickableElement = /* @__PURE__ */ __name((node, maxDept
|
|
|
1748
1702
|
collectText(child, currentDepth + 1);
|
|
1749
1703
|
}
|
|
1750
1704
|
}
|
|
1751
|
-
}
|
|
1705
|
+
};
|
|
1752
1706
|
collectText(node, 0);
|
|
1753
1707
|
return textParts.join("\n").trim();
|
|
1754
|
-
}
|
|
1708
|
+
};
|
|
1755
1709
|
function getSelectorMap(flatTree) {
|
|
1756
1710
|
const selectorMap = /* @__PURE__ */ new Map();
|
|
1757
1711
|
const keys = Object.keys(flatTree.map);
|
|
@@ -1763,7 +1717,6 @@ function getSelectorMap(flatTree) {
|
|
|
1763
1717
|
}
|
|
1764
1718
|
return selectorMap;
|
|
1765
1719
|
}
|
|
1766
|
-
__name(getSelectorMap, "getSelectorMap");
|
|
1767
1720
|
function getElementTextMap(simplifiedHTML) {
|
|
1768
1721
|
const lines = simplifiedHTML.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
|
|
1769
1722
|
const elementTextMap = /* @__PURE__ */ new Map();
|
|
@@ -1777,7 +1730,6 @@ function getElementTextMap(simplifiedHTML) {
|
|
|
1777
1730
|
}
|
|
1778
1731
|
return elementTextMap;
|
|
1779
1732
|
}
|
|
1780
|
-
__name(getElementTextMap, "getElementTextMap");
|
|
1781
1733
|
function cleanUpHighlights() {
|
|
1782
1734
|
const cleanupFunctions = window._highlightCleanupFunctions || [];
|
|
1783
1735
|
for (const cleanup of cleanupFunctions) {
|
|
@@ -1787,7 +1739,6 @@ function cleanUpHighlights() {
|
|
|
1787
1739
|
}
|
|
1788
1740
|
window._highlightCleanupFunctions = [];
|
|
1789
1741
|
}
|
|
1790
|
-
__name(cleanUpHighlights, "cleanUpHighlights");
|
|
1791
1742
|
window.addEventListener("popstate", () => {
|
|
1792
1743
|
cleanUpHighlights();
|
|
1793
1744
|
});
|
|
@@ -1843,7 +1794,6 @@ function getPageInfo() {
|
|
|
1843
1794
|
pixels_right
|
|
1844
1795
|
};
|
|
1845
1796
|
}
|
|
1846
|
-
__name(getPageInfo, "getPageInfo");
|
|
1847
1797
|
function patchReact(pageController) {
|
|
1848
1798
|
const reactRootElements = document.querySelectorAll(
|
|
1849
1799
|
'[data-reactroot], [data-reactid], [data-react-checksum], #root, #app, [id^="root-"], [id^="app-"], #adex-wrapper, #adex-root'
|
|
@@ -1852,8 +1802,7 @@ function patchReact(pageController) {
|
|
|
1852
1802
|
element.setAttribute("data-page-agent-not-interactive", "true");
|
|
1853
1803
|
}
|
|
1854
1804
|
}
|
|
1855
|
-
|
|
1856
|
-
const _PageController = class _PageController extends EventTarget {
|
|
1805
|
+
class PageController extends EventTarget {
|
|
1857
1806
|
config;
|
|
1858
1807
|
/** Corresponds to eval_page in browser-use */
|
|
1859
1808
|
flatTree = null;
|
|
@@ -1888,7 +1837,7 @@ const _PageController = class _PageController extends EventTarget {
|
|
|
1888
1837
|
initMask() {
|
|
1889
1838
|
if (this.maskReady !== null) return;
|
|
1890
1839
|
this.maskReady = (async () => {
|
|
1891
|
-
const { SimulatorMask } = await import("./SimulatorMask-
|
|
1840
|
+
const { SimulatorMask } = await import("./SimulatorMask-BfJiQVCo.js");
|
|
1892
1841
|
this.mask = new SimulatorMask();
|
|
1893
1842
|
})();
|
|
1894
1843
|
}
|
|
@@ -1946,7 +1895,7 @@ ${scrollHintAbove}`;
|
|
|
1946
1895
|
cleanUpHighlights();
|
|
1947
1896
|
const blacklist = [
|
|
1948
1897
|
...this.config.interactiveBlacklist || [],
|
|
1949
|
-
...document.querySelectorAll("[data-page-agent-not-interactive]")
|
|
1898
|
+
...Array.from(document.querySelectorAll("[data-page-agent-not-interactive]"))
|
|
1950
1899
|
];
|
|
1951
1900
|
this.flatTree = getFlatTree({
|
|
1952
1901
|
...this.config,
|
|
@@ -2141,9 +2090,7 @@ ${scrollHintAbove}`;
|
|
|
2141
2090
|
this.mask?.dispose();
|
|
2142
2091
|
this.mask = null;
|
|
2143
2092
|
}
|
|
2144
|
-
}
|
|
2145
|
-
__name(_PageController, "PageController");
|
|
2146
|
-
let PageController = _PageController;
|
|
2093
|
+
}
|
|
2147
2094
|
export {
|
|
2148
2095
|
PageController,
|
|
2149
2096
|
clickElement,
|