@skrillex1224/playwright-toolkit 2.1.233 → 2.1.235

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
@@ -236,8 +236,9 @@ var ActorInfo = {
236
236
  erine: createActorInfo({
237
237
  key: "erine",
238
238
  name: "\u6587\u5FC3\u4E00\u8A00",
239
- domain: "yiyan.baidu.com",
239
+ domain: "wenxin.baidu.com",
240
240
  path: "/",
241
+ device: Device.Mobile,
241
242
  share: {
242
243
  mode: "response",
243
244
  prefix: "https://yiyan.baidu.com/share/",
@@ -283,6 +284,7 @@ var ActorInfo = {
283
284
  name: "\u5143\u5B9D",
284
285
  domain: "yuanbao.tencent.com",
285
286
  path: "/chat/",
287
+ device: Device.Mobile,
286
288
  share: {
287
289
  mode: "response",
288
290
  prefix: "https://yb.tencent.com/s/",
@@ -312,6 +314,7 @@ var ActorInfo = {
312
314
  name: "\u901A\u4E49\u5343\u95EE",
313
315
  domain: "www.qianwen.com",
314
316
  path: "/chat",
317
+ device: Device.Mobile,
315
318
  share: {
316
319
  mode: "response",
317
320
  prefix: "https://www.qianwen.com/share/chat/",
@@ -469,6 +472,9 @@ function createInternalLogger(moduleName, explicitLogger) {
469
472
  // src/internals/screenshot.js
470
473
  var import_delay = __toESM(require("delay"), 1);
471
474
 
475
+ // src/internals/constants.js
476
+ var PageRuntimeStateKey = "__playwright_toolkit_runtime_state__";
477
+
472
478
  // src/internals/viewport.js
473
479
  var toPositiveInt = (value) => {
474
480
  const number = Math.round(Number(value) || 0);
@@ -505,6 +511,7 @@ var SUPPORTED_TYPES = /* @__PURE__ */ new Set(["png", "jpeg", "webp"]);
505
511
  var EXPANDED_SCROLLABLE_CLASS = "__pk_expanded__";
506
512
  var DEFAULT_MAX_HEIGHT = 8e3;
507
513
  var DEFAULT_SETTLE_MS = 1e3;
514
+ var DEFAULT_MOBILE_SETTLE_MS = 50;
508
515
  var toPositiveNumber = (value, fallback = 0) => {
509
516
  const n = Number(value);
510
517
  if (!Number.isFinite(n) || n <= 0) return fallback;
@@ -527,6 +534,7 @@ var normalizeQuality = (value, type) => {
527
534
  if (rounded < 0 || rounded > 100) return void 0;
528
535
  return rounded;
529
536
  };
537
+ var resolvePageDevice = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
530
538
  var buildFullPageClip = (metrics, viewport, maxClipHeight) => {
531
539
  const contentSize = metrics && typeof metrics === "object" ? metrics.contentSize || null : null;
532
540
  const width = Math.max(1, Math.ceil(viewport.width || contentSize?.width || 1));
@@ -543,7 +551,7 @@ var buildFullPageClip = (metrics, viewport, maxClipHeight) => {
543
551
  };
544
552
  };
545
553
  var expandScrollableContent = async (page, options = {}) => {
546
- return await page.evaluate(({ className, forceScrollableHeight, visibleOnly }) => {
554
+ return await page.evaluate(({ className, forceScrollableHeight, visibleOnly, expandDocumentElements }) => {
547
555
  const body = document.body;
548
556
  const root = document.documentElement;
549
557
  const scrollingElement = document.scrollingElement;
@@ -568,8 +576,8 @@ var expandScrollableContent = async (page, options = {}) => {
568
576
  if (Number(style.opacity) === 0) return false;
569
577
  return rect.width > 0 && rect.height > 0;
570
578
  };
571
- const rememberOriginalBoxStyles = (el) => {
572
- if (!el || isDocumentElement(el) || el.classList.contains(className)) {
579
+ const rememberOriginalBoxStyles = (el, { includeDocumentElement = false } = {}) => {
580
+ if (!el || !includeDocumentElement && isDocumentElement(el) || el.classList.contains(className)) {
573
581
  return;
574
582
  }
575
583
  el.dataset.pkOrigOverflow = el.style.overflow;
@@ -582,6 +590,19 @@ var expandScrollableContent = async (page, options = {}) => {
582
590
  el.dataset.pkOrigMaxHeightPriority = el.style.getPropertyPriority("max-height") || "";
583
591
  el.classList.add(className);
584
592
  };
593
+ const expandDocumentElementsToHeight = (height) => {
594
+ if (!expandDocumentElements) return;
595
+ const targetHeight = Math.ceil(Number(height) || 0);
596
+ if (targetHeight <= 0) return;
597
+ [root, body, scrollingElement].forEach((el) => {
598
+ if (!el) return;
599
+ rememberOriginalBoxStyles(el, { includeDocumentElement: true });
600
+ el.style.setProperty("overflow", "visible", "important");
601
+ el.style.setProperty("height", `${targetHeight}px`, "important");
602
+ el.style.setProperty("min-height", `${targetHeight}px`, "important");
603
+ el.style.setProperty("max-height", "none", "important");
604
+ });
605
+ };
585
606
  const isScrollableY = (el, style, rect) => {
586
607
  if (!el || el.scrollHeight <= el.clientHeight + 1) {
587
608
  return false;
@@ -717,38 +738,61 @@ var expandScrollableContent = async (page, options = {}) => {
717
738
  }
718
739
  });
719
740
  maxHeight = Math.max(maxHeight, measureDocumentScrollHeight(), measureExpandedRenderedBottom());
741
+ if (expandDocumentElements) {
742
+ for (let pass = 0; pass < 2; pass += 1) {
743
+ expandDocumentElementsToHeight(maxHeight);
744
+ maxHeight = Math.max(maxHeight, measureDocumentScrollHeight(), measureExpandedRenderedBottom());
745
+ }
746
+ }
720
747
  return Math.ceil(maxHeight);
721
748
  }, {
722
749
  className: EXPANDED_SCROLLABLE_CLASS,
723
750
  forceScrollableHeight: options.forceScrollableHeight !== false,
724
- visibleOnly: options.visibleOnly !== false
751
+ visibleOnly: options.visibleOnly !== false,
752
+ expandDocumentElements: options.expandDocumentElements === true
725
753
  });
726
754
  };
727
755
  var prepareExpandedFullPageScreenshot = async (page, options = {}) => {
728
756
  const originalViewport = await resolveCurrentViewportSize(page);
729
757
  const maxHeight = toPositiveInteger(options.maxHeight, DEFAULT_MAX_HEIGHT);
730
- const settleMs = Math.max(0, Number(options.settleMs ?? DEFAULT_SETTLE_MS) || 0);
758
+ const preserveViewport = options.preserveViewport ?? resolvePageDevice(page) === Device.Mobile;
759
+ const defaultSettleMs = preserveViewport ? DEFAULT_MOBILE_SETTLE_MS : DEFAULT_SETTLE_MS;
760
+ const requestedSettleMs = Math.max(0, Number(options.settleMs ?? defaultSettleMs) || 0);
761
+ const settleMs = preserveViewport ? Math.min(requestedSettleMs, DEFAULT_MOBILE_SETTLE_MS) : requestedSettleMs;
731
762
  const maxScrollHeight = await expandScrollableContent(page, {
732
763
  forceScrollableHeight: options.forceScrollableHeight,
733
- visibleOnly: options.visibleOnly !== false
764
+ visibleOnly: options.visibleOnly !== false,
765
+ expandDocumentElements: preserveViewport
734
766
  });
735
767
  const targetHeight = Math.min(maxScrollHeight, maxHeight);
736
- await page.setViewportSize({
737
- width: originalViewport.width,
738
- height: targetHeight
739
- });
768
+ let viewportResized = false;
769
+ if (!preserveViewport) {
770
+ await page.setViewportSize({
771
+ width: originalViewport.width,
772
+ height: targetHeight
773
+ });
774
+ viewportResized = true;
775
+ }
740
776
  if (settleMs > 0) {
741
777
  await (0, import_delay.default)(settleMs);
742
778
  }
743
779
  return {
744
780
  originalViewport,
745
781
  maxScrollHeight,
746
- targetHeight
782
+ targetHeight,
783
+ preserveViewport,
784
+ viewportResized
747
785
  };
748
786
  };
749
787
  var restoreExpandedFullPageScreenshot = async (page, state = {}) => {
750
788
  await page.evaluate((className) => {
751
- document.querySelectorAll(`.${className}`).forEach((el) => {
789
+ const targets = new Set([
790
+ ...document.querySelectorAll(`.${className}`),
791
+ document.documentElement,
792
+ document.body,
793
+ document.scrollingElement
794
+ ].filter((el) => el?.classList?.contains(className)));
795
+ targets.forEach((el) => {
752
796
  el.style.setProperty("overflow", el.dataset.pkOrigOverflow || "", el.dataset.pkOrigOverflowPriority || "");
753
797
  el.style.setProperty("height", el.dataset.pkOrigHeight || "", el.dataset.pkOrigHeightPriority || "");
754
798
  el.style.setProperty("min-height", el.dataset.pkOrigMinHeight || "", el.dataset.pkOrigMinHeightPriority || "");
@@ -764,7 +808,7 @@ var restoreExpandedFullPageScreenshot = async (page, state = {}) => {
764
808
  el.classList.remove(className);
765
809
  });
766
810
  }, EXPANDED_SCROLLABLE_CLASS);
767
- if (state?.originalViewport) {
811
+ if (state?.originalViewport && state?.viewportResized) {
768
812
  await page.setViewportSize(state.originalViewport);
769
813
  }
770
814
  };
@@ -1262,9 +1306,6 @@ var ProxyMeterRuntime = {
1262
1306
  getProxyMeterSnapshot
1263
1307
  };
1264
1308
 
1265
- // src/internals/constants.js
1266
- var PageRuntimeStateKey = "__playwright_toolkit_runtime_state__";
1267
-
1268
1309
  // src/runtime-env.js
1269
1310
  var BROWSER_PROFILE_SCHEMA_VERSION = 1;
1270
1311
  var rememberedRuntimeState = null;
@@ -2814,14 +2855,14 @@ var Humanize = {
2814
2855
  * @param {import('playwright').Page} page
2815
2856
  * @param {string|import('playwright').ElementHandle} target - CSS 选择器或元素句柄
2816
2857
  * @param {Object} [options]
2817
- * @param {number} [options.maxSteps=14] - 最大滚动步数
2858
+ * @param {number} [options.maxSteps=20] - 最大滚动步数
2818
2859
  * @param {number} [options.minStep=260] - 单次滚动最小步长
2819
2860
  * @param {number} [options.maxStep=800] - 单次滚动最大步长
2820
2861
  * @param {number} [options.maxDurationMs] - 最长耗时上限 (默认随 maxSteps 估算)
2821
2862
  */
2822
2863
  async humanScroll(page, target, options = {}) {
2823
2864
  const {
2824
- maxSteps = 14,
2865
+ maxSteps = 20,
2825
2866
  minStep = 260,
2826
2867
  maxStep = 800,
2827
2868
  maxDurationMs = maxSteps * 220 + 800
@@ -3742,7 +3783,7 @@ var MobileHumanize = {
3742
3783
  },
3743
3784
  async humanScroll(page, target, options = {}) {
3744
3785
  const {
3745
- maxSteps = 12,
3786
+ maxSteps = 20,
3746
3787
  minStep = 180,
3747
3788
  maxStep = 520,
3748
3789
  maxDurationMs = maxSteps * 280 + 1200,
@@ -7379,11 +7420,11 @@ var resolveScreenshotWatermarkifyMeta = async (page, options = {}) => {
7379
7420
  watermark: options.watermark,
7380
7421
  strip: options.strip,
7381
7422
  stripLogoSrc,
7382
- device: resolvePageDevice(page)
7423
+ device: resolvePageDevice2(page)
7383
7424
  };
7384
7425
  };
7385
7426
  var buildFontFamily = () => 'MiSans, "SF Pro Display", "PingFang SC", "Helvetica Neue", Arial, sans-serif';
7386
- var resolvePageDevice = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
7427
+ var resolvePageDevice2 = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
7387
7428
  var findStripSegment = (segments, kind) => {
7388
7429
  const found = Array.isArray(segments) ? segments.find((segment) => segment?.kind === kind) : null;
7389
7430
  return found && typeof found === "object" ? found : {};