@skrillex1224/playwright-toolkit 3.0.22 → 3.0.24
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.cjs +32 -3
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +32 -3
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -515,6 +515,10 @@ var DEFAULT_STITCH_SETTLE_MS = 120;
|
|
|
515
515
|
var DEFAULT_STITCH_OVERLAP_PX = 24;
|
|
516
516
|
var MIN_VIRTUALIZED_SCROLL_RATIO = 2.2;
|
|
517
517
|
var MIN_SPARSE_SCROLL_RATIO = 4;
|
|
518
|
+
var MIN_STITCH_VISIBLE_HEIGHT_PX = 120;
|
|
519
|
+
var MIN_STITCH_VISIBLE_HEIGHT_RATIO = 0.22;
|
|
520
|
+
var MIN_STITCH_OUTPUT_HEIGHT_RATIO = 0.35;
|
|
521
|
+
var MIN_STITCH_OUTPUT_VIEWPORT_RATIO = 1.15;
|
|
518
522
|
var MOBILE_VIEWPORT_WIDTH_THRESHOLD = 520;
|
|
519
523
|
var DEFAULT_QUALITY_RETRY_ATTEMPTS = 2;
|
|
520
524
|
var DEFAULT_QUALITY_RETRY_DELAY_MS = 2500;
|
|
@@ -1237,12 +1241,20 @@ var resolveVirtualizedScrollTarget = async (page, options = {}) => {
|
|
|
1237
1241
|
const scrollHeight = Math.ceil(el2.scrollHeight || 0);
|
|
1238
1242
|
const clientHeight = Math.ceil(el2.clientHeight || viewportHeight || 0);
|
|
1239
1243
|
if (scrollHeight < Math.max(900, clientHeight * config.minScrollRatio)) return;
|
|
1244
|
+
const visibleTop = Math.max(0, Math.round(rect.top || 0));
|
|
1245
|
+
const visibleBottom = Math.min(viewportHeight, Math.round(rect.bottom || viewportHeight));
|
|
1246
|
+
const visibleHeight = Math.max(0, visibleBottom - visibleTop);
|
|
1247
|
+
const minVisibleHeight = Math.max(
|
|
1248
|
+
config.minVisibleHeightPx,
|
|
1249
|
+
Math.floor(viewportHeight * config.minVisibleHeightRatio)
|
|
1250
|
+
);
|
|
1251
|
+
if (!config.force && !isDocumentElement(el2) && visibleHeight < minVisibleHeight) return;
|
|
1240
1252
|
const { textHeight, textNodes } = textHeightFor(el2);
|
|
1241
1253
|
const sparseRatio = scrollHeight / Math.max(1, textHeight);
|
|
1242
1254
|
const sparse = config.force || textNodes > 0 && sparseRatio >= config.minSparseRatio && scrollHeight - textHeight > clientHeight;
|
|
1243
1255
|
if (!sparse) return;
|
|
1244
1256
|
const visibleWidth = Math.max(1, Math.ceil(rect.width || viewportWidth || 1));
|
|
1245
|
-
const score2 = scrollHeight * Math.min(visibleWidth, viewportWidth || visibleWidth);
|
|
1257
|
+
const score2 = scrollHeight * Math.min(visibleWidth, viewportWidth || visibleWidth) * Math.min(1, visibleHeight / Math.max(1, viewportHeight));
|
|
1246
1258
|
if (!best || score2 > best.score) {
|
|
1247
1259
|
best = {
|
|
1248
1260
|
el: el2,
|
|
@@ -1258,6 +1270,7 @@ var resolveVirtualizedScrollTarget = async (page, options = {}) => {
|
|
|
1258
1270
|
width: Math.max(1, Math.round(rect.width || viewportWidth || 1)),
|
|
1259
1271
|
height: Math.max(1, Math.round(rect.height || viewportHeight || 1))
|
|
1260
1272
|
},
|
|
1273
|
+
visibleHeight,
|
|
1261
1274
|
textHeight,
|
|
1262
1275
|
textNodes,
|
|
1263
1276
|
sparseRatio
|
|
@@ -1284,7 +1297,9 @@ var resolveVirtualizedScrollTarget = async (page, options = {}) => {
|
|
|
1284
1297
|
attrName: STITCH_SCROLL_TARGET_ATTR,
|
|
1285
1298
|
force: stitchMode === "force",
|
|
1286
1299
|
minScrollRatio: MIN_VIRTUALIZED_SCROLL_RATIO,
|
|
1287
|
-
minSparseRatio: MIN_SPARSE_SCROLL_RATIO
|
|
1300
|
+
minSparseRatio: MIN_SPARSE_SCROLL_RATIO,
|
|
1301
|
+
minVisibleHeightPx: MIN_STITCH_VISIBLE_HEIGHT_PX,
|
|
1302
|
+
minVisibleHeightRatio: MIN_STITCH_VISIBLE_HEIGHT_RATIO
|
|
1288
1303
|
}).catch((error) => {
|
|
1289
1304
|
logger.warning(`\u865A\u62DF\u6EDA\u52A8\u622A\u56FE\u63A2\u6D4B\u5931\u8D25: ${error?.message || error}`);
|
|
1290
1305
|
return null;
|
|
@@ -1397,6 +1412,17 @@ var captureStitchedScrollableScreenshot = async (page, target, options = {}) =>
|
|
|
1397
1412
|
logger.info(
|
|
1398
1413
|
`\u865A\u62DF\u6EDA\u52A8\u5206\u6BB5\u622A\u56FE: segments=${segments.length}, height=${totalHeight}, scrollHeight=${target.scrollHeight}, textNodes=${target.textNodes}, sparseRatio=${Number(target.sparseRatio || 0).toFixed(2)}`
|
|
1399
1414
|
);
|
|
1415
|
+
const expectedHeight = Math.min(maxHeight, Math.max(target.scrollHeight || 0, viewport.height || 0));
|
|
1416
|
+
const minPlausibleHeight = Math.max(
|
|
1417
|
+
Math.floor((viewport.height || rect.height || 0) * MIN_STITCH_OUTPUT_VIEWPORT_RATIO),
|
|
1418
|
+
Math.floor(expectedHeight * MIN_STITCH_OUTPUT_HEIGHT_RATIO)
|
|
1419
|
+
);
|
|
1420
|
+
if (positions.length > 1 && expectedHeight > (viewport.height || rect.height || 0) * 1.3 && totalHeight < minPlausibleHeight) {
|
|
1421
|
+
logger.warning(
|
|
1422
|
+
`\u865A\u62DF\u6EDA\u52A8\u5206\u6BB5\u622A\u56FE\u7ED3\u679C\u8FC7\u77ED\uFF0C\u964D\u7EA7\u666E\u901A\u957F\u622A\u56FE: segments=${segments.length}, height=${totalHeight}, expectedMin=${minPlausibleHeight}, scrollHeight=${target.scrollHeight}, rect=${rect.width}x${rect.height}@${rect.top}`
|
|
1423
|
+
);
|
|
1424
|
+
return null;
|
|
1425
|
+
}
|
|
1400
1426
|
return await canvas.getBuffer(JimpMime.png);
|
|
1401
1427
|
} finally {
|
|
1402
1428
|
await setStitchScrollTop(page, target, target.scrollTop || 0).catch(() => {
|
|
@@ -1513,7 +1539,10 @@ var cropBufferToContentBounds = async (buffer, bounds, options = {}) => {
|
|
|
1513
1539
|
var captureExpandedFullPageScreenshotOnce = async (page, options = {}) => {
|
|
1514
1540
|
const stitchedTarget = await resolveVirtualizedScrollTarget(page, options);
|
|
1515
1541
|
if (stitchedTarget) {
|
|
1516
|
-
|
|
1542
|
+
const buffer = await captureStitchedScrollableScreenshot(page, stitchedTarget, options);
|
|
1543
|
+
if (buffer) {
|
|
1544
|
+
return buffer;
|
|
1545
|
+
}
|
|
1517
1546
|
}
|
|
1518
1547
|
const state2 = await prepareExpandedFullPageScreenshot(page, options);
|
|
1519
1548
|
try {
|