@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 CHANGED
@@ -542,6 +542,10 @@ var DEFAULT_STITCH_SETTLE_MS = 120;
542
542
  var DEFAULT_STITCH_OVERLAP_PX = 24;
543
543
  var MIN_VIRTUALIZED_SCROLL_RATIO = 2.2;
544
544
  var MIN_SPARSE_SCROLL_RATIO = 4;
545
+ var MIN_STITCH_VISIBLE_HEIGHT_PX = 120;
546
+ var MIN_STITCH_VISIBLE_HEIGHT_RATIO = 0.22;
547
+ var MIN_STITCH_OUTPUT_HEIGHT_RATIO = 0.35;
548
+ var MIN_STITCH_OUTPUT_VIEWPORT_RATIO = 1.15;
545
549
  var MOBILE_VIEWPORT_WIDTH_THRESHOLD = 520;
546
550
  var DEFAULT_QUALITY_RETRY_ATTEMPTS = 2;
547
551
  var DEFAULT_QUALITY_RETRY_DELAY_MS = 2500;
@@ -1264,12 +1268,20 @@ var resolveVirtualizedScrollTarget = async (page, options = {}) => {
1264
1268
  const scrollHeight = Math.ceil(el2.scrollHeight || 0);
1265
1269
  const clientHeight = Math.ceil(el2.clientHeight || viewportHeight || 0);
1266
1270
  if (scrollHeight < Math.max(900, clientHeight * config.minScrollRatio)) return;
1271
+ const visibleTop = Math.max(0, Math.round(rect.top || 0));
1272
+ const visibleBottom = Math.min(viewportHeight, Math.round(rect.bottom || viewportHeight));
1273
+ const visibleHeight = Math.max(0, visibleBottom - visibleTop);
1274
+ const minVisibleHeight = Math.max(
1275
+ config.minVisibleHeightPx,
1276
+ Math.floor(viewportHeight * config.minVisibleHeightRatio)
1277
+ );
1278
+ if (!config.force && !isDocumentElement(el2) && visibleHeight < minVisibleHeight) return;
1267
1279
  const { textHeight, textNodes } = textHeightFor(el2);
1268
1280
  const sparseRatio = scrollHeight / Math.max(1, textHeight);
1269
1281
  const sparse = config.force || textNodes > 0 && sparseRatio >= config.minSparseRatio && scrollHeight - textHeight > clientHeight;
1270
1282
  if (!sparse) return;
1271
1283
  const visibleWidth = Math.max(1, Math.ceil(rect.width || viewportWidth || 1));
1272
- const score2 = scrollHeight * Math.min(visibleWidth, viewportWidth || visibleWidth);
1284
+ const score2 = scrollHeight * Math.min(visibleWidth, viewportWidth || visibleWidth) * Math.min(1, visibleHeight / Math.max(1, viewportHeight));
1273
1285
  if (!best || score2 > best.score) {
1274
1286
  best = {
1275
1287
  el: el2,
@@ -1285,6 +1297,7 @@ var resolveVirtualizedScrollTarget = async (page, options = {}) => {
1285
1297
  width: Math.max(1, Math.round(rect.width || viewportWidth || 1)),
1286
1298
  height: Math.max(1, Math.round(rect.height || viewportHeight || 1))
1287
1299
  },
1300
+ visibleHeight,
1288
1301
  textHeight,
1289
1302
  textNodes,
1290
1303
  sparseRatio
@@ -1311,7 +1324,9 @@ var resolveVirtualizedScrollTarget = async (page, options = {}) => {
1311
1324
  attrName: STITCH_SCROLL_TARGET_ATTR,
1312
1325
  force: stitchMode === "force",
1313
1326
  minScrollRatio: MIN_VIRTUALIZED_SCROLL_RATIO,
1314
- minSparseRatio: MIN_SPARSE_SCROLL_RATIO
1327
+ minSparseRatio: MIN_SPARSE_SCROLL_RATIO,
1328
+ minVisibleHeightPx: MIN_STITCH_VISIBLE_HEIGHT_PX,
1329
+ minVisibleHeightRatio: MIN_STITCH_VISIBLE_HEIGHT_RATIO
1315
1330
  }).catch((error) => {
1316
1331
  logger.warning(`\u865A\u62DF\u6EDA\u52A8\u622A\u56FE\u63A2\u6D4B\u5931\u8D25: ${error?.message || error}`);
1317
1332
  return null;
@@ -1424,6 +1439,17 @@ var captureStitchedScrollableScreenshot = async (page, target, options = {}) =>
1424
1439
  logger.info(
1425
1440
  `\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)}`
1426
1441
  );
1442
+ const expectedHeight = Math.min(maxHeight, Math.max(target.scrollHeight || 0, viewport.height || 0));
1443
+ const minPlausibleHeight = Math.max(
1444
+ Math.floor((viewport.height || rect.height || 0) * MIN_STITCH_OUTPUT_VIEWPORT_RATIO),
1445
+ Math.floor(expectedHeight * MIN_STITCH_OUTPUT_HEIGHT_RATIO)
1446
+ );
1447
+ if (positions.length > 1 && expectedHeight > (viewport.height || rect.height || 0) * 1.3 && totalHeight < minPlausibleHeight) {
1448
+ logger.warning(
1449
+ `\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}`
1450
+ );
1451
+ return null;
1452
+ }
1427
1453
  return await canvas.getBuffer(import_jimp.JimpMime.png);
1428
1454
  } finally {
1429
1455
  await setStitchScrollTop(page, target, target.scrollTop || 0).catch(() => {
@@ -1540,7 +1566,10 @@ var cropBufferToContentBounds = async (buffer, bounds, options = {}) => {
1540
1566
  var captureExpandedFullPageScreenshotOnce = async (page, options = {}) => {
1541
1567
  const stitchedTarget = await resolveVirtualizedScrollTarget(page, options);
1542
1568
  if (stitchedTarget) {
1543
- return await captureStitchedScrollableScreenshot(page, stitchedTarget, options);
1569
+ const buffer = await captureStitchedScrollableScreenshot(page, stitchedTarget, options);
1570
+ if (buffer) {
1571
+ return buffer;
1572
+ }
1544
1573
  }
1545
1574
  const state2 = await prepareExpandedFullPageScreenshot(page, options);
1546
1575
  try {