@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 CHANGED
@@ -686,56 +686,19 @@ var Humanize = {
686
686
  async humanScroll(page, target, options = {}) {
687
687
  const { maxSteps = 25, minStep = 80, maxStep = 220 } = options;
688
688
  const targetDesc = typeof target === "string" ? target : "ElementHandle";
689
- logger4.debug("humanScroll", `target=${targetDesc}`);
689
+ logger4.debug(`humanScroll| target=${targetDesc}`);
690
690
  let element;
691
691
  if (typeof target === "string") {
692
692
  element = await page.$(target);
693
693
  if (!element) {
694
- logger4.warn("humanScroll", `Element not found: ${target}`);
694
+ logger4.warn(`humanScroll| Element not found: ${target}`);
695
695
  return { element: null, didScroll: false, restore: async () => {
696
696
  } };
697
697
  }
698
698
  } else {
699
699
  element = target;
700
700
  }
701
- const needsScroll = await element.evaluate((el) => {
702
- const isScrollable = (node) => {
703
- if (!node || node === document.body) return false;
704
- const style = window.getComputedStyle(node);
705
- const overflowY = style.overflowY || style.overflow;
706
- return (overflowY === "auto" || overflowY === "scroll" || overflowY === "overlay") && node.scrollHeight > node.clientHeight + 1;
707
- };
708
- const rect = el.getBoundingClientRect();
709
- if (!rect || rect.width === 0 || rect.height === 0) return true;
710
- const inViewport = rect.top >= 0 && rect.bottom <= window.innerHeight;
711
- if (!inViewport) return true;
712
- let current = el.parentElement;
713
- while (current) {
714
- if (isScrollable(current)) {
715
- const crect = current.getBoundingClientRect();
716
- if (rect.top < crect.top + 2 || rect.bottom > crect.bottom - 2) {
717
- return true;
718
- }
719
- }
720
- current = current.parentElement;
721
- }
722
- const cx = rect.left + rect.width / 2;
723
- const cy = rect.top + rect.height / 2;
724
- if (cx < 0 || cx > window.innerWidth || cy < 0 || cy > window.innerHeight) return true;
725
- const pointElement = document.elementFromPoint(cx, cy);
726
- if (pointElement) {
727
- if (el.contains(pointElement) || pointElement.contains(el)) {
728
- return false;
729
- }
730
- return true;
731
- }
732
- return false;
733
- });
734
- if (!needsScroll) {
735
- logger4.debug("humanScroll", "Element already in view (and unobstructed)");
736
- return { element, didScroll: false, restore: async () => {
737
- } };
738
- }
701
+ let didScroll = false;
739
702
  const scrollStateHandle = await element.evaluateHandle((el) => {
740
703
  const isScrollable = (node) => {
741
704
  if (!node || node === document.body) return false;
@@ -832,9 +795,10 @@ var Humanize = {
832
795
  target2.container.scrollTop = next;
833
796
  return { moved: true, inView: false };
834
797
  }, step);
798
+ if (result.moved) didScroll = true;
835
799
  if (result.inView) break;
836
800
  if (!result.moved && !result.inView) {
837
- logger4.warn("humanScroll", "Stuck: cannot scroll further but element still obstructed/hidden");
801
+ logger4.warn("humanScroll| Stuck: cannot scroll further but element still obstructed/hidden");
838
802
  break;
839
803
  }
840
804
  await (0, import_delay2.default)(this.jitterMs(120, 0.4));
@@ -868,7 +832,7 @@ var Humanize = {
868
832
  }
869
833
  };
870
834
  logger4.success("humanScroll", "Scroll completed");
871
- return { element, didScroll: true, restore };
835
+ return { element, didScroll, restore };
872
836
  },
873
837
  /**
874
838
  * 人类化点击 - 使用 ghost-cursor 模拟人类鼠标移动轨迹并点击