@skrillex1224/playwright-toolkit 2.1.29 → 2.1.30
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/index.cjs +6 -42
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +6 -42
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -657,56 +657,19 @@ var Humanize = {
|
|
|
657
657
|
async humanScroll(page, target, options = {}) {
|
|
658
658
|
const { maxSteps = 25, minStep = 80, maxStep = 220 } = options;
|
|
659
659
|
const targetDesc = typeof target === "string" ? target : "ElementHandle";
|
|
660
|
-
logger4.debug(
|
|
660
|
+
logger4.debug(`humanScroll| target=${targetDesc}`);
|
|
661
661
|
let element;
|
|
662
662
|
if (typeof target === "string") {
|
|
663
663
|
element = await page.$(target);
|
|
664
664
|
if (!element) {
|
|
665
|
-
logger4.warn(
|
|
665
|
+
logger4.warn(`humanScroll| Element not found: ${target}`);
|
|
666
666
|
return { element: null, didScroll: false, restore: async () => {
|
|
667
667
|
} };
|
|
668
668
|
}
|
|
669
669
|
} else {
|
|
670
670
|
element = target;
|
|
671
671
|
}
|
|
672
|
-
|
|
673
|
-
const isScrollable = (node) => {
|
|
674
|
-
if (!node || node === document.body) return false;
|
|
675
|
-
const style = window.getComputedStyle(node);
|
|
676
|
-
const overflowY = style.overflowY || style.overflow;
|
|
677
|
-
return (overflowY === "auto" || overflowY === "scroll" || overflowY === "overlay") && node.scrollHeight > node.clientHeight + 1;
|
|
678
|
-
};
|
|
679
|
-
const rect = el.getBoundingClientRect();
|
|
680
|
-
if (!rect || rect.width === 0 || rect.height === 0) return true;
|
|
681
|
-
const inViewport = rect.top >= 0 && rect.bottom <= window.innerHeight;
|
|
682
|
-
if (!inViewport) return true;
|
|
683
|
-
let current = el.parentElement;
|
|
684
|
-
while (current) {
|
|
685
|
-
if (isScrollable(current)) {
|
|
686
|
-
const crect = current.getBoundingClientRect();
|
|
687
|
-
if (rect.top < crect.top + 2 || rect.bottom > crect.bottom - 2) {
|
|
688
|
-
return true;
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
current = current.parentElement;
|
|
692
|
-
}
|
|
693
|
-
const cx = rect.left + rect.width / 2;
|
|
694
|
-
const cy = rect.top + rect.height / 2;
|
|
695
|
-
if (cx < 0 || cx > window.innerWidth || cy < 0 || cy > window.innerHeight) return true;
|
|
696
|
-
const pointElement = document.elementFromPoint(cx, cy);
|
|
697
|
-
if (pointElement) {
|
|
698
|
-
if (el.contains(pointElement) || pointElement.contains(el)) {
|
|
699
|
-
return false;
|
|
700
|
-
}
|
|
701
|
-
return true;
|
|
702
|
-
}
|
|
703
|
-
return false;
|
|
704
|
-
});
|
|
705
|
-
if (!needsScroll) {
|
|
706
|
-
logger4.debug("humanScroll", "Element already in view (and unobstructed)");
|
|
707
|
-
return { element, didScroll: false, restore: async () => {
|
|
708
|
-
} };
|
|
709
|
-
}
|
|
672
|
+
let didScroll = false;
|
|
710
673
|
const scrollStateHandle = await element.evaluateHandle((el) => {
|
|
711
674
|
const isScrollable = (node) => {
|
|
712
675
|
if (!node || node === document.body) return false;
|
|
@@ -803,9 +766,10 @@ var Humanize = {
|
|
|
803
766
|
target2.container.scrollTop = next;
|
|
804
767
|
return { moved: true, inView: false };
|
|
805
768
|
}, step);
|
|
769
|
+
if (result.moved) didScroll = true;
|
|
806
770
|
if (result.inView) break;
|
|
807
771
|
if (!result.moved && !result.inView) {
|
|
808
|
-
logger4.warn("humanScroll
|
|
772
|
+
logger4.warn("humanScroll| Stuck: cannot scroll further but element still obstructed/hidden");
|
|
809
773
|
break;
|
|
810
774
|
}
|
|
811
775
|
await delay2(this.jitterMs(120, 0.4));
|
|
@@ -839,7 +803,7 @@ var Humanize = {
|
|
|
839
803
|
}
|
|
840
804
|
};
|
|
841
805
|
logger4.success("humanScroll", "Scroll completed");
|
|
842
|
-
return { element, didScroll
|
|
806
|
+
return { element, didScroll, restore };
|
|
843
807
|
},
|
|
844
808
|
/**
|
|
845
809
|
* 人类化点击 - 使用 ghost-cursor 模拟人类鼠标移动轨迹并点击
|