@skrillex1224/playwright-toolkit 2.1.229 → 2.1.231
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/README.md +1 -0
- package/dist/index.cjs +95 -26
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +95 -26
- package/dist/index.js.map +2 -2
- package/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -478,6 +478,9 @@ var SUPPORTED_TYPES = /* @__PURE__ */ new Set(["png", "jpeg", "webp"]);
|
|
|
478
478
|
var EXPANDED_SCROLLABLE_CLASS = "__pk_expanded__";
|
|
479
479
|
var DEFAULT_MAX_HEIGHT = 8e3;
|
|
480
480
|
var DEFAULT_SETTLE_MS = 1e3;
|
|
481
|
+
var DEFAULT_BUFFER_RATIO = 0.25;
|
|
482
|
+
var DEFAULT_BUFFER_MIN = 120;
|
|
483
|
+
var DEFAULT_BUFFER_MAX = 320;
|
|
481
484
|
var toPositiveNumber = (value, fallback = 0) => {
|
|
482
485
|
const n = Number(value);
|
|
483
486
|
if (!Number.isFinite(n) || n <= 0) return fallback;
|
|
@@ -487,6 +490,10 @@ var toPositiveInteger = (value, fallback = 0) => {
|
|
|
487
490
|
const number = Math.round(Number(value) || 0);
|
|
488
491
|
return number > 0 ? number : fallback;
|
|
489
492
|
};
|
|
493
|
+
var resolveDefaultBuffer = (viewport = {}) => {
|
|
494
|
+
const height = Math.max(1, Number(viewport.height) || 0);
|
|
495
|
+
return Math.round(Math.min(DEFAULT_BUFFER_MAX, Math.max(DEFAULT_BUFFER_MIN, height * DEFAULT_BUFFER_RATIO)));
|
|
496
|
+
};
|
|
490
497
|
var normalizeType = (value) => {
|
|
491
498
|
const raw = String(value || "png").trim().toLowerCase();
|
|
492
499
|
if (!SUPPORTED_TYPES.has(raw)) return "png";
|
|
@@ -541,7 +548,21 @@ var expandScrollableContent = async (page, options = {}) => {
|
|
|
541
548
|
if (Number(style.opacity) === 0) return false;
|
|
542
549
|
return rect.width > 0 && rect.height > 0;
|
|
543
550
|
};
|
|
544
|
-
const
|
|
551
|
+
const rememberOriginalBoxStyles = (el) => {
|
|
552
|
+
if (!el || isDocumentElement(el) || el.classList.contains(className)) {
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
el.dataset.pkOrigOverflow = el.style.overflow;
|
|
556
|
+
el.dataset.pkOrigOverflowPriority = el.style.getPropertyPriority("overflow") || "";
|
|
557
|
+
el.dataset.pkOrigHeight = el.style.height;
|
|
558
|
+
el.dataset.pkOrigHeightPriority = el.style.getPropertyPriority("height") || "";
|
|
559
|
+
el.dataset.pkOrigMinHeight = el.style.minHeight;
|
|
560
|
+
el.dataset.pkOrigMinHeightPriority = el.style.getPropertyPriority("min-height") || "";
|
|
561
|
+
el.dataset.pkOrigMaxHeight = el.style.maxHeight;
|
|
562
|
+
el.dataset.pkOrigMaxHeightPriority = el.style.getPropertyPriority("max-height") || "";
|
|
563
|
+
el.classList.add(className);
|
|
564
|
+
};
|
|
565
|
+
const isScrollableY = (el, style, rect) => {
|
|
545
566
|
if (!el || el.scrollHeight <= el.clientHeight + 1) {
|
|
546
567
|
return false;
|
|
547
568
|
}
|
|
@@ -551,7 +572,60 @@ var expandScrollableContent = async (page, options = {}) => {
|
|
|
551
572
|
const overflowY = String(style.overflowY || "").toLowerCase();
|
|
552
573
|
const overflow = String(style.overflow || "").toLowerCase();
|
|
553
574
|
const scrollableOverflow = /* @__PURE__ */ new Set(["auto", "scroll", "overlay"]);
|
|
554
|
-
|
|
575
|
+
if (scrollableOverflow.has(overflowY) || scrollableOverflow.has(overflow)) {
|
|
576
|
+
return true;
|
|
577
|
+
}
|
|
578
|
+
const clippingOverflow = /* @__PURE__ */ new Set(["hidden", "clip"]);
|
|
579
|
+
const clipsY = clippingOverflow.has(overflowY) || clippingOverflow.has(overflow);
|
|
580
|
+
if (!clipsY || !rect) {
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
const viewportHeight = window.innerHeight || 0;
|
|
584
|
+
return rect.height >= viewportHeight * 0.25 || el.scrollHeight >= viewportHeight * 0.75;
|
|
585
|
+
};
|
|
586
|
+
const measureNeededHeight = (el) => {
|
|
587
|
+
if (!el) return 0;
|
|
588
|
+
const scrollHeight = Math.ceil(el.scrollHeight || 0);
|
|
589
|
+
if (scrollHeight <= 0) return 0;
|
|
590
|
+
if (isDocumentElement(el)) {
|
|
591
|
+
return scrollHeight;
|
|
592
|
+
}
|
|
593
|
+
const rect = el.getBoundingClientRect();
|
|
594
|
+
if (!rect || rect.width <= 0 || rect.height <= 0) {
|
|
595
|
+
return 0;
|
|
596
|
+
}
|
|
597
|
+
const documentTop = Math.max(0, Math.ceil(rect.top + (window.scrollY || window.pageYOffset || 0)));
|
|
598
|
+
return documentTop + scrollHeight;
|
|
599
|
+
};
|
|
600
|
+
const scrollableElements = [];
|
|
601
|
+
const expandElementToScrollHeight = (el) => {
|
|
602
|
+
if (!el || isDocumentElement(el)) return;
|
|
603
|
+
const scrollHeight = Math.ceil(el.scrollHeight || 0);
|
|
604
|
+
if (scrollHeight <= 0) return;
|
|
605
|
+
rememberOriginalBoxStyles(el);
|
|
606
|
+
el.style.setProperty("overflow", "visible", "important");
|
|
607
|
+
el.style.setProperty("height", `${scrollHeight}px`, "important");
|
|
608
|
+
el.style.setProperty("min-height", `${scrollHeight}px`, "important");
|
|
609
|
+
el.style.setProperty("max-height", "none", "important");
|
|
610
|
+
};
|
|
611
|
+
const expandClippingAncestors = (el) => {
|
|
612
|
+
for (let node = el?.parentElement; node && !isDocumentElement(node); node = node.parentElement) {
|
|
613
|
+
const style = window.getComputedStyle(node);
|
|
614
|
+
const rect = node.getBoundingClientRect();
|
|
615
|
+
if (!isVisible(node, style, rect)) continue;
|
|
616
|
+
const overflowY = String(style.overflowY || "").toLowerCase();
|
|
617
|
+
const overflow = String(style.overflow || "").toLowerCase();
|
|
618
|
+
const clipsContent = ["hidden", "clip", "auto", "scroll", "overlay"].includes(overflowY) || ["hidden", "clip", "auto", "scroll", "overlay"].includes(overflow);
|
|
619
|
+
if (!clipsContent) continue;
|
|
620
|
+
rememberOriginalBoxStyles(node);
|
|
621
|
+
node.style.setProperty("overflow", "visible", "important");
|
|
622
|
+
node.style.setProperty("max-height", "none", "important");
|
|
623
|
+
if (node.scrollHeight > node.clientHeight + 1) {
|
|
624
|
+
const scrollHeight = Math.ceil(node.scrollHeight || 0);
|
|
625
|
+
node.style.setProperty("height", `${scrollHeight}px`, "important");
|
|
626
|
+
node.style.setProperty("min-height", `${scrollHeight}px`, "important");
|
|
627
|
+
}
|
|
628
|
+
}
|
|
555
629
|
};
|
|
556
630
|
candidates.forEach((el) => {
|
|
557
631
|
const style = window.getComputedStyle(el);
|
|
@@ -559,51 +633,46 @@ var expandScrollableContent = async (page, options = {}) => {
|
|
|
559
633
|
if (visibleOnly && !isVisible(el, style, rect)) {
|
|
560
634
|
return;
|
|
561
635
|
}
|
|
562
|
-
if (!isScrollableY(el, style)) {
|
|
636
|
+
if (!isScrollableY(el, style, rect)) {
|
|
563
637
|
return;
|
|
564
638
|
}
|
|
565
|
-
const
|
|
566
|
-
if (
|
|
639
|
+
const neededHeight = measureNeededHeight(el);
|
|
640
|
+
if (neededHeight <= 0) {
|
|
567
641
|
return;
|
|
568
642
|
}
|
|
569
|
-
if (
|
|
570
|
-
maxHeight =
|
|
643
|
+
if (neededHeight > maxHeight) {
|
|
644
|
+
maxHeight = neededHeight;
|
|
571
645
|
}
|
|
646
|
+
scrollableElements.push(el);
|
|
572
647
|
if (isDocumentElement(el)) {
|
|
573
648
|
return;
|
|
574
649
|
}
|
|
575
|
-
|
|
576
|
-
el.dataset.pkOrigOverflow = el.style.overflow;
|
|
577
|
-
el.dataset.pkOrigOverflowPriority = el.style.getPropertyPriority("overflow") || "";
|
|
578
|
-
el.dataset.pkOrigHeight = el.style.height;
|
|
579
|
-
el.dataset.pkOrigHeightPriority = el.style.getPropertyPriority("height") || "";
|
|
580
|
-
el.dataset.pkOrigMinHeight = el.style.minHeight;
|
|
581
|
-
el.dataset.pkOrigMinHeightPriority = el.style.getPropertyPriority("min-height") || "";
|
|
582
|
-
el.dataset.pkOrigMaxHeight = el.style.maxHeight;
|
|
583
|
-
el.dataset.pkOrigMaxHeightPriority = el.style.getPropertyPriority("max-height") || "";
|
|
584
|
-
el.classList.add(className);
|
|
585
|
-
}
|
|
650
|
+
expandClippingAncestors(el);
|
|
586
651
|
if (forceScrollableHeight) {
|
|
587
|
-
el
|
|
588
|
-
el.style.setProperty("height", `${scrollHeight}px`, "important");
|
|
589
|
-
el.style.setProperty("min-height", `${scrollHeight}px`, "important");
|
|
590
|
-
el.style.setProperty("max-height", "none", "important");
|
|
652
|
+
expandElementToScrollHeight(el);
|
|
591
653
|
return;
|
|
592
654
|
}
|
|
655
|
+
rememberOriginalBoxStyles(el);
|
|
593
656
|
el.style.overflow = "visible";
|
|
594
657
|
el.style.height = "auto";
|
|
595
658
|
el.style.maxHeight = "none";
|
|
596
659
|
});
|
|
660
|
+
scrollableElements.forEach((el) => {
|
|
661
|
+
const neededHeight = measureNeededHeight(el);
|
|
662
|
+
if (neededHeight > maxHeight) {
|
|
663
|
+
maxHeight = neededHeight;
|
|
664
|
+
}
|
|
665
|
+
});
|
|
597
666
|
return maxHeight;
|
|
598
667
|
}, {
|
|
599
668
|
className: EXPANDED_SCROLLABLE_CLASS,
|
|
600
|
-
forceScrollableHeight:
|
|
669
|
+
forceScrollableHeight: options.forceScrollableHeight !== false,
|
|
601
670
|
visibleOnly: options.visibleOnly !== false
|
|
602
671
|
});
|
|
603
672
|
};
|
|
604
673
|
var prepareExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
605
674
|
const originalViewport = await resolveCurrentViewportSize(page);
|
|
606
|
-
const defaultBuffer =
|
|
675
|
+
const defaultBuffer = resolveDefaultBuffer(originalViewport);
|
|
607
676
|
const buffer = options.buffer ?? defaultBuffer;
|
|
608
677
|
const maxHeight = toPositiveInteger(options.maxHeight, DEFAULT_MAX_HEIGHT);
|
|
609
678
|
const settleMs = Math.max(0, Number(options.settleMs ?? DEFAULT_SETTLE_MS) || 0);
|
|
@@ -8274,7 +8343,7 @@ var Share = {
|
|
|
8274
8343
|
*
|
|
8275
8344
|
* @param {import('playwright').Page} page
|
|
8276
8345
|
* @param {Object} [options]
|
|
8277
|
-
* @param {number} [options.buffer]
|
|
8346
|
+
* @param {number} [options.buffer] 额外缓冲高度;默认按视口高度自动计算,传 0 可关闭
|
|
8278
8347
|
* @param {boolean} [options.restore]
|
|
8279
8348
|
* @param {number} [options.maxHeight]
|
|
8280
8349
|
* @param {number} [options.maxBytes] 默认 5MiB,返回 base64 超过后会压缩
|
|
@@ -8287,7 +8356,7 @@ var Share = {
|
|
|
8287
8356
|
const screenshotWatermarkify = resolveCaptureScreenWatermarkify(page, options.watermarkify);
|
|
8288
8357
|
const compression = resolveImageCompression(options);
|
|
8289
8358
|
const captureOptions = {
|
|
8290
|
-
buffer: options.buffer
|
|
8359
|
+
...Object.prototype.hasOwnProperty.call(options, "buffer") ? { buffer: options.buffer } : {},
|
|
8291
8360
|
restore,
|
|
8292
8361
|
maxHeight: options.maxHeight,
|
|
8293
8362
|
type: "png",
|