@skrillex1224/playwright-toolkit 2.1.233 → 2.1.234

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
@@ -285,6 +285,7 @@ var ActorInfo = {
285
285
  name: "\u901A\u4E49\u5343\u95EE",
286
286
  domain: "www.qianwen.com",
287
287
  path: "/chat",
288
+ device: Device.Mobile,
288
289
  share: {
289
290
  mode: "response",
290
291
  prefix: "https://www.qianwen.com/share/chat/",
@@ -442,6 +443,9 @@ function createInternalLogger(moduleName, explicitLogger) {
442
443
  // src/internals/screenshot.js
443
444
  import delay from "delay";
444
445
 
446
+ // src/internals/constants.js
447
+ var PageRuntimeStateKey = "__playwright_toolkit_runtime_state__";
448
+
445
449
  // src/internals/viewport.js
446
450
  var toPositiveInt = (value) => {
447
451
  const number = Math.round(Number(value) || 0);
@@ -478,6 +482,7 @@ var SUPPORTED_TYPES = /* @__PURE__ */ new Set(["png", "jpeg", "webp"]);
478
482
  var EXPANDED_SCROLLABLE_CLASS = "__pk_expanded__";
479
483
  var DEFAULT_MAX_HEIGHT = 8e3;
480
484
  var DEFAULT_SETTLE_MS = 1e3;
485
+ var DEFAULT_MOBILE_SETTLE_MS = 50;
481
486
  var toPositiveNumber = (value, fallback = 0) => {
482
487
  const n = Number(value);
483
488
  if (!Number.isFinite(n) || n <= 0) return fallback;
@@ -500,6 +505,7 @@ var normalizeQuality = (value, type) => {
500
505
  if (rounded < 0 || rounded > 100) return void 0;
501
506
  return rounded;
502
507
  };
508
+ var resolvePageDevice = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
503
509
  var buildFullPageClip = (metrics, viewport, maxClipHeight) => {
504
510
  const contentSize = metrics && typeof metrics === "object" ? metrics.contentSize || null : null;
505
511
  const width = Math.max(1, Math.ceil(viewport.width || contentSize?.width || 1));
@@ -516,7 +522,7 @@ var buildFullPageClip = (metrics, viewport, maxClipHeight) => {
516
522
  };
517
523
  };
518
524
  var expandScrollableContent = async (page, options = {}) => {
519
- return await page.evaluate(({ className, forceScrollableHeight, visibleOnly }) => {
525
+ return await page.evaluate(({ className, forceScrollableHeight, visibleOnly, expandDocumentElements }) => {
520
526
  const body = document.body;
521
527
  const root = document.documentElement;
522
528
  const scrollingElement = document.scrollingElement;
@@ -541,8 +547,8 @@ var expandScrollableContent = async (page, options = {}) => {
541
547
  if (Number(style.opacity) === 0) return false;
542
548
  return rect.width > 0 && rect.height > 0;
543
549
  };
544
- const rememberOriginalBoxStyles = (el) => {
545
- if (!el || isDocumentElement(el) || el.classList.contains(className)) {
550
+ const rememberOriginalBoxStyles = (el, { includeDocumentElement = false } = {}) => {
551
+ if (!el || !includeDocumentElement && isDocumentElement(el) || el.classList.contains(className)) {
546
552
  return;
547
553
  }
548
554
  el.dataset.pkOrigOverflow = el.style.overflow;
@@ -555,6 +561,19 @@ var expandScrollableContent = async (page, options = {}) => {
555
561
  el.dataset.pkOrigMaxHeightPriority = el.style.getPropertyPriority("max-height") || "";
556
562
  el.classList.add(className);
557
563
  };
564
+ const expandDocumentElementsToHeight = (height) => {
565
+ if (!expandDocumentElements) return;
566
+ const targetHeight = Math.ceil(Number(height) || 0);
567
+ if (targetHeight <= 0) return;
568
+ [root, body, scrollingElement].forEach((el) => {
569
+ if (!el) return;
570
+ rememberOriginalBoxStyles(el, { includeDocumentElement: true });
571
+ el.style.setProperty("overflow", "visible", "important");
572
+ el.style.setProperty("height", `${targetHeight}px`, "important");
573
+ el.style.setProperty("min-height", `${targetHeight}px`, "important");
574
+ el.style.setProperty("max-height", "none", "important");
575
+ });
576
+ };
558
577
  const isScrollableY = (el, style, rect) => {
559
578
  if (!el || el.scrollHeight <= el.clientHeight + 1) {
560
579
  return false;
@@ -690,38 +709,61 @@ var expandScrollableContent = async (page, options = {}) => {
690
709
  }
691
710
  });
692
711
  maxHeight = Math.max(maxHeight, measureDocumentScrollHeight(), measureExpandedRenderedBottom());
712
+ if (expandDocumentElements) {
713
+ for (let pass = 0; pass < 2; pass += 1) {
714
+ expandDocumentElementsToHeight(maxHeight);
715
+ maxHeight = Math.max(maxHeight, measureDocumentScrollHeight(), measureExpandedRenderedBottom());
716
+ }
717
+ }
693
718
  return Math.ceil(maxHeight);
694
719
  }, {
695
720
  className: EXPANDED_SCROLLABLE_CLASS,
696
721
  forceScrollableHeight: options.forceScrollableHeight !== false,
697
- visibleOnly: options.visibleOnly !== false
722
+ visibleOnly: options.visibleOnly !== false,
723
+ expandDocumentElements: options.expandDocumentElements === true
698
724
  });
699
725
  };
700
726
  var prepareExpandedFullPageScreenshot = async (page, options = {}) => {
701
727
  const originalViewport = await resolveCurrentViewportSize(page);
702
728
  const maxHeight = toPositiveInteger(options.maxHeight, DEFAULT_MAX_HEIGHT);
703
- const settleMs = Math.max(0, Number(options.settleMs ?? DEFAULT_SETTLE_MS) || 0);
729
+ const preserveViewport = options.preserveViewport ?? resolvePageDevice(page) === Device.Mobile;
730
+ const defaultSettleMs = preserveViewport ? DEFAULT_MOBILE_SETTLE_MS : DEFAULT_SETTLE_MS;
731
+ const requestedSettleMs = Math.max(0, Number(options.settleMs ?? defaultSettleMs) || 0);
732
+ const settleMs = preserveViewport ? Math.min(requestedSettleMs, DEFAULT_MOBILE_SETTLE_MS) : requestedSettleMs;
704
733
  const maxScrollHeight = await expandScrollableContent(page, {
705
734
  forceScrollableHeight: options.forceScrollableHeight,
706
- visibleOnly: options.visibleOnly !== false
735
+ visibleOnly: options.visibleOnly !== false,
736
+ expandDocumentElements: preserveViewport
707
737
  });
708
738
  const targetHeight = Math.min(maxScrollHeight, maxHeight);
709
- await page.setViewportSize({
710
- width: originalViewport.width,
711
- height: targetHeight
712
- });
739
+ let viewportResized = false;
740
+ if (!preserveViewport) {
741
+ await page.setViewportSize({
742
+ width: originalViewport.width,
743
+ height: targetHeight
744
+ });
745
+ viewportResized = true;
746
+ }
713
747
  if (settleMs > 0) {
714
748
  await delay(settleMs);
715
749
  }
716
750
  return {
717
751
  originalViewport,
718
752
  maxScrollHeight,
719
- targetHeight
753
+ targetHeight,
754
+ preserveViewport,
755
+ viewportResized
720
756
  };
721
757
  };
722
758
  var restoreExpandedFullPageScreenshot = async (page, state = {}) => {
723
759
  await page.evaluate((className) => {
724
- document.querySelectorAll(`.${className}`).forEach((el) => {
760
+ const targets = new Set([
761
+ ...document.querySelectorAll(`.${className}`),
762
+ document.documentElement,
763
+ document.body,
764
+ document.scrollingElement
765
+ ].filter((el) => el?.classList?.contains(className)));
766
+ targets.forEach((el) => {
725
767
  el.style.setProperty("overflow", el.dataset.pkOrigOverflow || "", el.dataset.pkOrigOverflowPriority || "");
726
768
  el.style.setProperty("height", el.dataset.pkOrigHeight || "", el.dataset.pkOrigHeightPriority || "");
727
769
  el.style.setProperty("min-height", el.dataset.pkOrigMinHeight || "", el.dataset.pkOrigMinHeightPriority || "");
@@ -737,7 +779,7 @@ var restoreExpandedFullPageScreenshot = async (page, state = {}) => {
737
779
  el.classList.remove(className);
738
780
  });
739
781
  }, EXPANDED_SCROLLABLE_CLASS);
740
- if (state?.originalViewport) {
782
+ if (state?.originalViewport && state?.viewportResized) {
741
783
  await page.setViewportSize(state.originalViewport);
742
784
  }
743
785
  };
@@ -1234,9 +1276,6 @@ var ProxyMeterRuntime = {
1234
1276
  getProxyMeterSnapshot
1235
1277
  };
1236
1278
 
1237
- // src/internals/constants.js
1238
- var PageRuntimeStateKey = "__playwright_toolkit_runtime_state__";
1239
-
1240
1279
  // src/runtime-env.js
1241
1280
  var BROWSER_PROFILE_SCHEMA_VERSION = 1;
1242
1281
  var rememberedRuntimeState = null;
@@ -7351,11 +7390,11 @@ var resolveScreenshotWatermarkifyMeta = async (page, options = {}) => {
7351
7390
  watermark: options.watermark,
7352
7391
  strip: options.strip,
7353
7392
  stripLogoSrc,
7354
- device: resolvePageDevice(page)
7393
+ device: resolvePageDevice2(page)
7355
7394
  };
7356
7395
  };
7357
7396
  var buildFontFamily = () => 'MiSans, "SF Pro Display", "PingFang SC", "Helvetica Neue", Arial, sans-serif';
7358
- var resolvePageDevice = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
7397
+ var resolvePageDevice2 = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
7359
7398
  var findStripSegment = (segments, kind) => {
7360
7399
  const found = Array.isArray(segments) ? segments.find((segment) => segment?.kind === kind) : null;
7361
7400
  return found && typeof found === "object" ? found : {};