@skrillex1224/playwright-toolkit 2.1.230 → 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 +68 -22
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +68 -22
- 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,16 @@ 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;
|
|
555
585
|
};
|
|
556
586
|
const measureNeededHeight = (el) => {
|
|
557
587
|
if (!el) return 0;
|
|
@@ -568,13 +598,42 @@ var expandScrollableContent = async (page, options = {}) => {
|
|
|
568
598
|
return documentTop + scrollHeight;
|
|
569
599
|
};
|
|
570
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
|
+
}
|
|
629
|
+
};
|
|
571
630
|
candidates.forEach((el) => {
|
|
572
631
|
const style = window.getComputedStyle(el);
|
|
573
632
|
const rect = el.getBoundingClientRect();
|
|
574
633
|
if (visibleOnly && !isVisible(el, style, rect)) {
|
|
575
634
|
return;
|
|
576
635
|
}
|
|
577
|
-
if (!isScrollableY(el, style)) {
|
|
636
|
+
if (!isScrollableY(el, style, rect)) {
|
|
578
637
|
return;
|
|
579
638
|
}
|
|
580
639
|
const neededHeight = measureNeededHeight(el);
|
|
@@ -588,25 +647,12 @@ var expandScrollableContent = async (page, options = {}) => {
|
|
|
588
647
|
if (isDocumentElement(el)) {
|
|
589
648
|
return;
|
|
590
649
|
}
|
|
591
|
-
|
|
592
|
-
el.dataset.pkOrigOverflow = el.style.overflow;
|
|
593
|
-
el.dataset.pkOrigOverflowPriority = el.style.getPropertyPriority("overflow") || "";
|
|
594
|
-
el.dataset.pkOrigHeight = el.style.height;
|
|
595
|
-
el.dataset.pkOrigHeightPriority = el.style.getPropertyPriority("height") || "";
|
|
596
|
-
el.dataset.pkOrigMinHeight = el.style.minHeight;
|
|
597
|
-
el.dataset.pkOrigMinHeightPriority = el.style.getPropertyPriority("min-height") || "";
|
|
598
|
-
el.dataset.pkOrigMaxHeight = el.style.maxHeight;
|
|
599
|
-
el.dataset.pkOrigMaxHeightPriority = el.style.getPropertyPriority("max-height") || "";
|
|
600
|
-
el.classList.add(className);
|
|
601
|
-
}
|
|
650
|
+
expandClippingAncestors(el);
|
|
602
651
|
if (forceScrollableHeight) {
|
|
603
|
-
|
|
604
|
-
el.style.setProperty("overflow", "visible", "important");
|
|
605
|
-
el.style.setProperty("height", `${scrollHeight}px`, "important");
|
|
606
|
-
el.style.setProperty("min-height", `${scrollHeight}px`, "important");
|
|
607
|
-
el.style.setProperty("max-height", "none", "important");
|
|
652
|
+
expandElementToScrollHeight(el);
|
|
608
653
|
return;
|
|
609
654
|
}
|
|
655
|
+
rememberOriginalBoxStyles(el);
|
|
610
656
|
el.style.overflow = "visible";
|
|
611
657
|
el.style.height = "auto";
|
|
612
658
|
el.style.maxHeight = "none";
|
|
@@ -626,7 +672,7 @@ var expandScrollableContent = async (page, options = {}) => {
|
|
|
626
672
|
};
|
|
627
673
|
var prepareExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
628
674
|
const originalViewport = await resolveCurrentViewportSize(page);
|
|
629
|
-
const defaultBuffer =
|
|
675
|
+
const defaultBuffer = resolveDefaultBuffer(originalViewport);
|
|
630
676
|
const buffer = options.buffer ?? defaultBuffer;
|
|
631
677
|
const maxHeight = toPositiveInteger(options.maxHeight, DEFAULT_MAX_HEIGHT);
|
|
632
678
|
const settleMs = Math.max(0, Number(options.settleMs ?? DEFAULT_SETTLE_MS) || 0);
|
|
@@ -8297,7 +8343,7 @@ var Share = {
|
|
|
8297
8343
|
*
|
|
8298
8344
|
* @param {import('playwright').Page} page
|
|
8299
8345
|
* @param {Object} [options]
|
|
8300
|
-
* @param {number} [options.buffer]
|
|
8346
|
+
* @param {number} [options.buffer] 额外缓冲高度;默认按视口高度自动计算,传 0 可关闭
|
|
8301
8347
|
* @param {boolean} [options.restore]
|
|
8302
8348
|
* @param {number} [options.maxHeight]
|
|
8303
8349
|
* @param {number} [options.maxBytes] 默认 5MiB,返回 base64 超过后会压缩
|
|
@@ -8310,7 +8356,7 @@ var Share = {
|
|
|
8310
8356
|
const screenshotWatermarkify = resolveCaptureScreenWatermarkify(page, options.watermarkify);
|
|
8311
8357
|
const compression = resolveImageCompression(options);
|
|
8312
8358
|
const captureOptions = {
|
|
8313
|
-
buffer: options.buffer
|
|
8359
|
+
...Object.prototype.hasOwnProperty.call(options, "buffer") ? { buffer: options.buffer } : {},
|
|
8314
8360
|
restore,
|
|
8315
8361
|
maxHeight: options.maxHeight,
|
|
8316
8362
|
type: "png",
|