@skrillex1224/playwright-toolkit 2.1.237 → 2.1.239
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/browser.js +2 -1
- package/dist/browser.js.map +2 -2
- package/dist/index.cjs +87 -1
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +87 -1
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -140,8 +140,9 @@ var ActorInfo = {
|
|
|
140
140
|
qbot: createActorInfo({
|
|
141
141
|
key: "qbot",
|
|
142
142
|
name: "QQ\u6D4F\u89C8\u5668AI\u641C",
|
|
143
|
-
domain: "sogou.com",
|
|
143
|
+
domain: "m.sogou.com",
|
|
144
144
|
path: "/web",
|
|
145
|
+
device: Device.Mobile,
|
|
145
146
|
share: {
|
|
146
147
|
mode: "dom",
|
|
147
148
|
prefix: "",
|
|
@@ -722,6 +723,84 @@ var expandScrollableContent = async (page, options = {}) => {
|
|
|
722
723
|
expandDocumentElements: options.expandDocumentElements === true
|
|
723
724
|
});
|
|
724
725
|
};
|
|
726
|
+
var pinBottomAffixedElements = async (page, options = {}) => {
|
|
727
|
+
return await page.evaluate(({ className, targetHeight }) => {
|
|
728
|
+
const viewportHeight = window.innerHeight || document.documentElement?.clientHeight || document.body?.clientHeight || 0;
|
|
729
|
+
const safeTargetHeight = Math.ceil(Number(targetHeight) || 0);
|
|
730
|
+
const deltaY = safeTargetHeight - viewportHeight;
|
|
731
|
+
if (deltaY <= 1) {
|
|
732
|
+
return 0;
|
|
733
|
+
}
|
|
734
|
+
const isVisible = (el, style, rect) => {
|
|
735
|
+
if (!el || !style || !rect) return false;
|
|
736
|
+
if (style.display === "none" || style.visibility === "hidden" || style.visibility === "collapse") {
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
if (Number(style.opacity) === 0) return false;
|
|
740
|
+
return rect.width > 0 && rect.height > 0;
|
|
741
|
+
};
|
|
742
|
+
const bottomThreshold = Math.max(24, Math.min(96, viewportHeight * 0.12));
|
|
743
|
+
const maxAffixedHeight = Math.max(56, viewportHeight * 0.65);
|
|
744
|
+
const candidates = [];
|
|
745
|
+
document.querySelectorAll("*").forEach((el) => {
|
|
746
|
+
const style = window.getComputedStyle(el);
|
|
747
|
+
const position = String(style.position || "").toLowerCase();
|
|
748
|
+
if (position !== "fixed" && position !== "sticky") return;
|
|
749
|
+
const rect = el.getBoundingClientRect();
|
|
750
|
+
if (!isVisible(el, style, rect)) return;
|
|
751
|
+
if (rect.height > maxAffixedHeight) return;
|
|
752
|
+
if (rect.bottom < viewportHeight - bottomThreshold) return;
|
|
753
|
+
const bottom = Number.parseFloat(style.bottom);
|
|
754
|
+
const hasBottomRule = Number.isFinite(bottom) && bottom <= Math.max(160, viewportHeight * 0.25);
|
|
755
|
+
const isNearViewportBottom = rect.bottom >= viewportHeight - bottomThreshold;
|
|
756
|
+
if (!hasBottomRule && !isNearViewportBottom) return;
|
|
757
|
+
candidates.push(el);
|
|
758
|
+
});
|
|
759
|
+
const candidateSet = new Set(candidates);
|
|
760
|
+
const topLevelCandidates = candidates.filter((el) => {
|
|
761
|
+
for (let parent = el.parentElement; parent; parent = parent.parentElement) {
|
|
762
|
+
if (candidateSet.has(parent)) return false;
|
|
763
|
+
}
|
|
764
|
+
return true;
|
|
765
|
+
});
|
|
766
|
+
topLevelCandidates.forEach((el) => {
|
|
767
|
+
if (!Object.prototype.hasOwnProperty.call(el.dataset, "pkBottomPinned")) {
|
|
768
|
+
el.dataset.pkBottomPinned = "1";
|
|
769
|
+
el.dataset.pkOrigTranslate = el.style.getPropertyValue("translate") || "";
|
|
770
|
+
el.dataset.pkOrigTranslatePriority = el.style.getPropertyPriority("translate") || "";
|
|
771
|
+
}
|
|
772
|
+
el.classList.add(className);
|
|
773
|
+
el.style.setProperty("translate", `0 ${Math.round(deltaY)}px`, "important");
|
|
774
|
+
});
|
|
775
|
+
return topLevelCandidates.length;
|
|
776
|
+
}, {
|
|
777
|
+
className: EXPANDED_SCROLLABLE_CLASS,
|
|
778
|
+
targetHeight: options.targetHeight
|
|
779
|
+
});
|
|
780
|
+
};
|
|
781
|
+
var restoreBottomAffixedElements = async (page) => {
|
|
782
|
+
await page.evaluate((className) => {
|
|
783
|
+
const hasOwn = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
|
|
784
|
+
const expansionKeys = [
|
|
785
|
+
"pkOrigOverflow",
|
|
786
|
+
"pkOrigHeight",
|
|
787
|
+
"pkOrigMinHeight",
|
|
788
|
+
"pkOrigMaxHeight"
|
|
789
|
+
];
|
|
790
|
+
document.querySelectorAll('[data-pk-bottom-pinned="1"]').forEach((el) => {
|
|
791
|
+
if (hasOwn(el.dataset, "pkOrigTranslate")) {
|
|
792
|
+
el.style.setProperty("translate", el.dataset.pkOrigTranslate || "", el.dataset.pkOrigTranslatePriority || "");
|
|
793
|
+
delete el.dataset.pkOrigTranslate;
|
|
794
|
+
delete el.dataset.pkOrigTranslatePriority;
|
|
795
|
+
}
|
|
796
|
+
delete el.dataset.pkBottomPinned;
|
|
797
|
+
const stillExpanded = expansionKeys.some((key) => hasOwn(el.dataset, key));
|
|
798
|
+
if (!stillExpanded) {
|
|
799
|
+
el.classList.remove(className);
|
|
800
|
+
}
|
|
801
|
+
});
|
|
802
|
+
}, EXPANDED_SCROLLABLE_CLASS);
|
|
803
|
+
};
|
|
725
804
|
var prepareExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
726
805
|
const originalViewport = await resolveCurrentViewportSize(page);
|
|
727
806
|
const maxHeight = toPositiveInteger(options.maxHeight, DEFAULT_MAX_HEIGHT);
|
|
@@ -742,6 +821,10 @@ var prepareExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
|
742
821
|
height: targetHeight
|
|
743
822
|
});
|
|
744
823
|
viewportResized = true;
|
|
824
|
+
} else {
|
|
825
|
+
await pinBottomAffixedElements(page, { targetHeight }).catch((error) => {
|
|
826
|
+
logger.warning(`\u79FB\u52A8\u7AEF\u5438\u5E95\u5143\u7D20\u91CD\u5B9A\u4F4D\u5931\u8D25: ${error?.message || error}`);
|
|
827
|
+
});
|
|
745
828
|
}
|
|
746
829
|
if (settleMs > 0) {
|
|
747
830
|
await delay(settleMs);
|
|
@@ -846,6 +929,9 @@ var captureExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
|
846
929
|
maxClipHeight: state.targetHeight
|
|
847
930
|
});
|
|
848
931
|
} finally {
|
|
932
|
+
await restoreBottomAffixedElements(page).catch((error) => {
|
|
933
|
+
logger.warning(`\u79FB\u52A8\u7AEF\u5438\u5E95\u5143\u7D20\u6062\u590D\u5931\u8D25: ${error?.message || error}`);
|
|
934
|
+
});
|
|
849
935
|
if (options.restore) {
|
|
850
936
|
await restoreExpandedFullPageScreenshot(page, state);
|
|
851
937
|
}
|