@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.js CHANGED
@@ -209,8 +209,9 @@ var ActorInfo = {
209
209
  erine: createActorInfo({
210
210
  key: "erine",
211
211
  name: "\u6587\u5FC3\u4E00\u8A00",
212
- domain: "yiyan.baidu.com",
212
+ domain: "wenxin.baidu.com",
213
213
  path: "/",
214
+ device: Device.Mobile,
214
215
  share: {
215
216
  mode: "response",
216
217
  prefix: "https://yiyan.baidu.com/share/",
@@ -256,6 +257,7 @@ var ActorInfo = {
256
257
  name: "\u5143\u5B9D",
257
258
  domain: "yuanbao.tencent.com",
258
259
  path: "/chat/",
260
+ device: Device.Mobile,
259
261
  share: {
260
262
  mode: "response",
261
263
  prefix: "https://yb.tencent.com/s/",
@@ -285,6 +287,7 @@ var ActorInfo = {
285
287
  name: "\u901A\u4E49\u5343\u95EE",
286
288
  domain: "www.qianwen.com",
287
289
  path: "/chat",
290
+ device: Device.Mobile,
288
291
  share: {
289
292
  mode: "response",
290
293
  prefix: "https://www.qianwen.com/share/chat/",
@@ -442,6 +445,9 @@ function createInternalLogger(moduleName, explicitLogger) {
442
445
  // src/internals/screenshot.js
443
446
  import delay from "delay";
444
447
 
448
+ // src/internals/constants.js
449
+ var PageRuntimeStateKey = "__playwright_toolkit_runtime_state__";
450
+
445
451
  // src/internals/viewport.js
446
452
  var toPositiveInt = (value) => {
447
453
  const number = Math.round(Number(value) || 0);
@@ -478,6 +484,7 @@ var SUPPORTED_TYPES = /* @__PURE__ */ new Set(["png", "jpeg", "webp"]);
478
484
  var EXPANDED_SCROLLABLE_CLASS = "__pk_expanded__";
479
485
  var DEFAULT_MAX_HEIGHT = 8e3;
480
486
  var DEFAULT_SETTLE_MS = 1e3;
487
+ var DEFAULT_MOBILE_SETTLE_MS = 50;
481
488
  var toPositiveNumber = (value, fallback = 0) => {
482
489
  const n = Number(value);
483
490
  if (!Number.isFinite(n) || n <= 0) return fallback;
@@ -500,6 +507,7 @@ var normalizeQuality = (value, type) => {
500
507
  if (rounded < 0 || rounded > 100) return void 0;
501
508
  return rounded;
502
509
  };
510
+ var resolvePageDevice = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
503
511
  var buildFullPageClip = (metrics, viewport, maxClipHeight) => {
504
512
  const contentSize = metrics && typeof metrics === "object" ? metrics.contentSize || null : null;
505
513
  const width = Math.max(1, Math.ceil(viewport.width || contentSize?.width || 1));
@@ -516,7 +524,7 @@ var buildFullPageClip = (metrics, viewport, maxClipHeight) => {
516
524
  };
517
525
  };
518
526
  var expandScrollableContent = async (page, options = {}) => {
519
- return await page.evaluate(({ className, forceScrollableHeight, visibleOnly }) => {
527
+ return await page.evaluate(({ className, forceScrollableHeight, visibleOnly, expandDocumentElements }) => {
520
528
  const body = document.body;
521
529
  const root = document.documentElement;
522
530
  const scrollingElement = document.scrollingElement;
@@ -541,8 +549,8 @@ var expandScrollableContent = async (page, options = {}) => {
541
549
  if (Number(style.opacity) === 0) return false;
542
550
  return rect.width > 0 && rect.height > 0;
543
551
  };
544
- const rememberOriginalBoxStyles = (el) => {
545
- if (!el || isDocumentElement(el) || el.classList.contains(className)) {
552
+ const rememberOriginalBoxStyles = (el, { includeDocumentElement = false } = {}) => {
553
+ if (!el || !includeDocumentElement && isDocumentElement(el) || el.classList.contains(className)) {
546
554
  return;
547
555
  }
548
556
  el.dataset.pkOrigOverflow = el.style.overflow;
@@ -555,6 +563,19 @@ var expandScrollableContent = async (page, options = {}) => {
555
563
  el.dataset.pkOrigMaxHeightPriority = el.style.getPropertyPriority("max-height") || "";
556
564
  el.classList.add(className);
557
565
  };
566
+ const expandDocumentElementsToHeight = (height) => {
567
+ if (!expandDocumentElements) return;
568
+ const targetHeight = Math.ceil(Number(height) || 0);
569
+ if (targetHeight <= 0) return;
570
+ [root, body, scrollingElement].forEach((el) => {
571
+ if (!el) return;
572
+ rememberOriginalBoxStyles(el, { includeDocumentElement: true });
573
+ el.style.setProperty("overflow", "visible", "important");
574
+ el.style.setProperty("height", `${targetHeight}px`, "important");
575
+ el.style.setProperty("min-height", `${targetHeight}px`, "important");
576
+ el.style.setProperty("max-height", "none", "important");
577
+ });
578
+ };
558
579
  const isScrollableY = (el, style, rect) => {
559
580
  if (!el || el.scrollHeight <= el.clientHeight + 1) {
560
581
  return false;
@@ -690,38 +711,61 @@ var expandScrollableContent = async (page, options = {}) => {
690
711
  }
691
712
  });
692
713
  maxHeight = Math.max(maxHeight, measureDocumentScrollHeight(), measureExpandedRenderedBottom());
714
+ if (expandDocumentElements) {
715
+ for (let pass = 0; pass < 2; pass += 1) {
716
+ expandDocumentElementsToHeight(maxHeight);
717
+ maxHeight = Math.max(maxHeight, measureDocumentScrollHeight(), measureExpandedRenderedBottom());
718
+ }
719
+ }
693
720
  return Math.ceil(maxHeight);
694
721
  }, {
695
722
  className: EXPANDED_SCROLLABLE_CLASS,
696
723
  forceScrollableHeight: options.forceScrollableHeight !== false,
697
- visibleOnly: options.visibleOnly !== false
724
+ visibleOnly: options.visibleOnly !== false,
725
+ expandDocumentElements: options.expandDocumentElements === true
698
726
  });
699
727
  };
700
728
  var prepareExpandedFullPageScreenshot = async (page, options = {}) => {
701
729
  const originalViewport = await resolveCurrentViewportSize(page);
702
730
  const maxHeight = toPositiveInteger(options.maxHeight, DEFAULT_MAX_HEIGHT);
703
- const settleMs = Math.max(0, Number(options.settleMs ?? DEFAULT_SETTLE_MS) || 0);
731
+ const preserveViewport = options.preserveViewport ?? resolvePageDevice(page) === Device.Mobile;
732
+ const defaultSettleMs = preserveViewport ? DEFAULT_MOBILE_SETTLE_MS : DEFAULT_SETTLE_MS;
733
+ const requestedSettleMs = Math.max(0, Number(options.settleMs ?? defaultSettleMs) || 0);
734
+ const settleMs = preserveViewport ? Math.min(requestedSettleMs, DEFAULT_MOBILE_SETTLE_MS) : requestedSettleMs;
704
735
  const maxScrollHeight = await expandScrollableContent(page, {
705
736
  forceScrollableHeight: options.forceScrollableHeight,
706
- visibleOnly: options.visibleOnly !== false
737
+ visibleOnly: options.visibleOnly !== false,
738
+ expandDocumentElements: preserveViewport
707
739
  });
708
740
  const targetHeight = Math.min(maxScrollHeight, maxHeight);
709
- await page.setViewportSize({
710
- width: originalViewport.width,
711
- height: targetHeight
712
- });
741
+ let viewportResized = false;
742
+ if (!preserveViewport) {
743
+ await page.setViewportSize({
744
+ width: originalViewport.width,
745
+ height: targetHeight
746
+ });
747
+ viewportResized = true;
748
+ }
713
749
  if (settleMs > 0) {
714
750
  await delay(settleMs);
715
751
  }
716
752
  return {
717
753
  originalViewport,
718
754
  maxScrollHeight,
719
- targetHeight
755
+ targetHeight,
756
+ preserveViewport,
757
+ viewportResized
720
758
  };
721
759
  };
722
760
  var restoreExpandedFullPageScreenshot = async (page, state = {}) => {
723
761
  await page.evaluate((className) => {
724
- document.querySelectorAll(`.${className}`).forEach((el) => {
762
+ const targets = new Set([
763
+ ...document.querySelectorAll(`.${className}`),
764
+ document.documentElement,
765
+ document.body,
766
+ document.scrollingElement
767
+ ].filter((el) => el?.classList?.contains(className)));
768
+ targets.forEach((el) => {
725
769
  el.style.setProperty("overflow", el.dataset.pkOrigOverflow || "", el.dataset.pkOrigOverflowPriority || "");
726
770
  el.style.setProperty("height", el.dataset.pkOrigHeight || "", el.dataset.pkOrigHeightPriority || "");
727
771
  el.style.setProperty("min-height", el.dataset.pkOrigMinHeight || "", el.dataset.pkOrigMinHeightPriority || "");
@@ -737,7 +781,7 @@ var restoreExpandedFullPageScreenshot = async (page, state = {}) => {
737
781
  el.classList.remove(className);
738
782
  });
739
783
  }, EXPANDED_SCROLLABLE_CLASS);
740
- if (state?.originalViewport) {
784
+ if (state?.originalViewport && state?.viewportResized) {
741
785
  await page.setViewportSize(state.originalViewport);
742
786
  }
743
787
  };
@@ -1234,9 +1278,6 @@ var ProxyMeterRuntime = {
1234
1278
  getProxyMeterSnapshot
1235
1279
  };
1236
1280
 
1237
- // src/internals/constants.js
1238
- var PageRuntimeStateKey = "__playwright_toolkit_runtime_state__";
1239
-
1240
1281
  // src/runtime-env.js
1241
1282
  var BROWSER_PROFILE_SCHEMA_VERSION = 1;
1242
1283
  var rememberedRuntimeState = null;
@@ -2786,14 +2827,14 @@ var Humanize = {
2786
2827
  * @param {import('playwright').Page} page
2787
2828
  * @param {string|import('playwright').ElementHandle} target - CSS 选择器或元素句柄
2788
2829
  * @param {Object} [options]
2789
- * @param {number} [options.maxSteps=14] - 最大滚动步数
2830
+ * @param {number} [options.maxSteps=20] - 最大滚动步数
2790
2831
  * @param {number} [options.minStep=260] - 单次滚动最小步长
2791
2832
  * @param {number} [options.maxStep=800] - 单次滚动最大步长
2792
2833
  * @param {number} [options.maxDurationMs] - 最长耗时上限 (默认随 maxSteps 估算)
2793
2834
  */
2794
2835
  async humanScroll(page, target, options = {}) {
2795
2836
  const {
2796
- maxSteps = 14,
2837
+ maxSteps = 20,
2797
2838
  minStep = 260,
2798
2839
  maxStep = 800,
2799
2840
  maxDurationMs = maxSteps * 220 + 800
@@ -3714,7 +3755,7 @@ var MobileHumanize = {
3714
3755
  },
3715
3756
  async humanScroll(page, target, options = {}) {
3716
3757
  const {
3717
- maxSteps = 12,
3758
+ maxSteps = 20,
3718
3759
  minStep = 180,
3719
3760
  maxStep = 520,
3720
3761
  maxDurationMs = maxSteps * 280 + 1200,
@@ -7351,11 +7392,11 @@ var resolveScreenshotWatermarkifyMeta = async (page, options = {}) => {
7351
7392
  watermark: options.watermark,
7352
7393
  strip: options.strip,
7353
7394
  stripLogoSrc,
7354
- device: resolvePageDevice(page)
7395
+ device: resolvePageDevice2(page)
7355
7396
  };
7356
7397
  };
7357
7398
  var buildFontFamily = () => 'MiSans, "SF Pro Display", "PingFang SC", "Helvetica Neue", Arial, sans-serif';
7358
- var resolvePageDevice = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
7399
+ var resolvePageDevice2 = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
7359
7400
  var findStripSegment = (segments, kind) => {
7360
7401
  const found = Array.isArray(segments) ? segments.find((segment) => segment?.kind === kind) : null;
7361
7402
  return found && typeof found === "object" ? found : {};