@skrillex1224/playwright-toolkit 2.1.248 → 2.1.250

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
@@ -262,6 +262,7 @@ var ActorInfo = {
262
262
  key: "baidu",
263
263
  name: "\u767E\u5EA6AI\u641C",
264
264
  domain: "www.baidu.com",
265
+ device: Device.Mobile,
265
266
  path: "/s",
266
267
  share: {
267
268
  mode: "response",
@@ -3431,13 +3432,6 @@ var jitterMs = (base, jitterPercent = 0.3) => {
3431
3432
  const jitter = Number(base || 0) * Number(jitterPercent || 0) * (Math.random() * 2 - 1);
3432
3433
  return Math.max(10, Math.round(Number(base || 0) + jitter));
3433
3434
  };
3434
- var randomPointInBox = (box, paddingRatio = 0.24) => {
3435
- const safePaddingX = Math.max(2, Math.min(box.width * paddingRatio, box.width / 2));
3436
- const safePaddingY = Math.max(2, Math.min(box.height * paddingRatio, box.height / 2));
3437
- const x = box.x + safePaddingX + Math.random() * Math.max(1, box.width - safePaddingX * 2);
3438
- const y = box.y + safePaddingY + Math.random() * Math.max(1, box.height - safePaddingY * 2);
3439
- return { x, y };
3440
- };
3441
3435
  var resolveElement = async (page, target, { throwOnMissing = true } = {}) => {
3442
3436
  if (target == null) return null;
3443
3437
  let element = target;
@@ -3482,6 +3476,10 @@ var clipBoxToViewport = (box, viewport) => {
3482
3476
  }
3483
3477
  return box;
3484
3478
  };
3479
+ var centerPointInBox = (box) => ({
3480
+ x: box.x + box.width / 2,
3481
+ y: box.y + box.height / 2
3482
+ });
3485
3483
  var withTimeout = async (operation, timeoutMs, label) => {
3486
3484
  const safeTimeoutMs = Math.max(50, Number(timeoutMs || 0));
3487
3485
  let timeoutId = null;
@@ -3633,97 +3631,6 @@ var checkElementVisibility = async (element) => {
3633
3631
  return { code: "VISIBLE", isFixed, positioning };
3634
3632
  });
3635
3633
  };
3636
- var resolveSafeTapPoint = async (element) => {
3637
- return element.evaluate((el) => {
3638
- const rect = el.getBoundingClientRect();
3639
- if (!rect || rect.width <= 0 || rect.height <= 0) {
3640
- return null;
3641
- }
3642
- const viewW = window.innerWidth;
3643
- const viewH = window.innerHeight;
3644
- let clipLeft = 0;
3645
- let clipRight = viewW;
3646
- let clipTop = 0;
3647
- let clipBottom = viewH;
3648
- for (let node = el.parentElement; node && node !== document.body; node = node.parentElement) {
3649
- const style = window.getComputedStyle(node);
3650
- if (!style) continue;
3651
- const clipsX = ["auto", "scroll", "overlay", "hidden", "clip"].includes(style.overflowX);
3652
- const clipsY = ["auto", "scroll", "overlay", "hidden", "clip"].includes(style.overflowY);
3653
- if (!clipsX && !clipsY) continue;
3654
- const nodeRect = node.getBoundingClientRect();
3655
- if (!nodeRect || nodeRect.width <= 0 || nodeRect.height <= 0) continue;
3656
- if (clipsX) {
3657
- clipLeft = Math.max(clipLeft, nodeRect.left);
3658
- clipRight = Math.min(clipRight, nodeRect.right);
3659
- }
3660
- if (clipsY) {
3661
- clipTop = Math.max(clipTop, nodeRect.top);
3662
- clipBottom = Math.min(clipBottom, nodeRect.bottom);
3663
- }
3664
- }
3665
- const visibleLeft = Math.max(clipLeft, Math.min(clipRight, rect.left));
3666
- const visibleRight = Math.max(clipLeft, Math.min(clipRight, rect.right));
3667
- const visibleTop = Math.max(clipTop, Math.min(clipBottom, rect.top));
3668
- const visibleBottom = Math.max(clipTop, Math.min(clipBottom, rect.bottom));
3669
- const visibleWidth = visibleRight - visibleLeft;
3670
- const visibleHeight = visibleBottom - visibleTop;
3671
- if (visibleWidth <= 1 || visibleHeight <= 1) {
3672
- return null;
3673
- }
3674
- const isRootNode = (node) => !node || node === document || node === document.body || node === document.documentElement;
3675
- const commonAncestor = (a, b) => {
3676
- for (let current = a; current && !isRootNode(current); current = current.parentElement) {
3677
- if (current.contains(b)) return current;
3678
- }
3679
- return null;
3680
- };
3681
- const sameTapTarget = (pointElement) => {
3682
- if (!pointElement) return false;
3683
- if (pointElement === el || el.contains(pointElement) || pointElement.contains(el)) {
3684
- return true;
3685
- }
3686
- const common = commonAncestor(el, pointElement);
3687
- if (!common) return false;
3688
- const commonRect = common.getBoundingClientRect?.();
3689
- if (!commonRect || commonRect.width <= 0 || commonRect.height <= 0) return false;
3690
- const commonArea = commonRect.width * commonRect.height;
3691
- const targetArea = Math.max(1, rect.width * rect.height);
3692
- const maxSharedRegionArea = Math.max(targetArea * 12, 4096);
3693
- if (commonArea > maxSharedRegionArea) return false;
3694
- if (commonRect.width > Math.max(rect.width * 8, 120) || commonRect.height > Math.max(rect.height * 8, 120)) {
3695
- return false;
3696
- }
3697
- return common.contains(el) && common.contains(pointElement);
3698
- };
3699
- const cx = visibleLeft + visibleWidth / 2;
3700
- const cy = visibleTop + visibleHeight / 2;
3701
- const smallX = Math.min(12, Math.max(2, visibleWidth * 0.18));
3702
- const smallY = Math.min(12, Math.max(2, visibleHeight * 0.18));
3703
- const points = [
3704
- { x: cx, y: cy },
3705
- { x: visibleLeft + smallX, y: visibleTop + smallY },
3706
- { x: visibleRight - smallX, y: visibleTop + smallY },
3707
- { x: visibleLeft + smallX, y: visibleBottom - smallY },
3708
- { x: visibleRight - smallX, y: visibleBottom - smallY },
3709
- { x: cx, y: visibleTop + Math.min(10, Math.max(2, visibleHeight * 0.2)) },
3710
- { x: cx, y: visibleBottom - Math.min(10, Math.max(2, visibleHeight * 0.2)) },
3711
- { x: visibleLeft + Math.min(10, Math.max(2, visibleWidth * 0.2)), y: cy },
3712
- { x: visibleRight - Math.min(10, Math.max(2, visibleWidth * 0.2)), y: cy }
3713
- ];
3714
- const safePoints = points.filter((point) => {
3715
- const pointElement = document.elementFromPoint(point.x, point.y);
3716
- return sameTapTarget(pointElement);
3717
- });
3718
- const candidates = safePoints.length ? safePoints : points;
3719
- const chosen = candidates[Math.floor(Math.random() * candidates.length)];
3720
- if (!chosen) return null;
3721
- return {
3722
- x: chosen.x,
3723
- y: chosen.y
3724
- };
3725
- });
3726
- };
3727
3634
  var activateElementFallback = async (element, point = null, options = {}) => {
3728
3635
  return element.evaluate((el, { innerOptions }) => {
3729
3636
  const isEditable = (node) => {
@@ -4308,8 +4215,8 @@ var MobileHumanize = {
4308
4215
  return false;
4309
4216
  }
4310
4217
  await waitJitter(reactionDelay, 0.45);
4311
- const safePoint = await resolveSafeTapPoint(element).catch(() => null);
4312
- const tapTarget = safePoint || randomPointInBox(clipBoxToViewport(box, resolveViewport(page)), 0.2);
4218
+ const visibleBox = clipBoxToViewport(box, resolveViewport(page));
4219
+ const tapTarget = centerPointInBox(visibleBox);
4313
4220
  try {
4314
4221
  await tapPoint(page, tapTarget, {
4315
4222
  timeoutMs: tapTimeoutMs,