|
1 | 1 | import { Snapshot, Context, DiscoveryErrors } from "../types.js"; |
2 | | -import { scrollToBottomAndBackToTop, getRenderViewports, getRenderViewportsForOptions, validateCoordinates, resolveCustomCSS, parseCSSFile, validateCSSSelectors, generateCSSInjectionReport } from "./utils.js" |
| 2 | +import { scrollToBottomAndBackToTop, smoothScrollToBottom, getRenderViewports, getRenderViewportsForOptions, validateCoordinates, resolveCustomCSS, parseCSSFile, validateCSSSelectors, generateCSSInjectionReport } from "./utils.js" |
3 | 3 | import { chromium, Locator } from "@playwright/test" |
4 | 4 | import constants from "./constants.js"; |
5 | 5 | import { updateLogContext } from '../lib/logger.js' |
@@ -169,6 +169,21 @@ export async function prepareSnapshot(snapshot: Snapshot, ctx: Context): Promise |
169 | 169 | processedOptions.useExtendedViewport = true; |
170 | 170 | } |
171 | 171 |
|
| 172 | + if (ctx.config.lazyLoadConfiguration && ctx.config.lazyLoadConfiguration.enabled) { |
| 173 | + let stepValue = ctx.config.lazyLoadConfiguration.scrollStep || 250; |
| 174 | + let delayValue = ctx.config.lazyLoadConfiguration.scrollDelay || 100; |
| 175 | + let maxScrollsValue = ctx.config.lazyLoadConfiguration.maxScrolls || 50; |
| 176 | + let jumpBackToTopValue = ctx.config.lazyLoadConfiguration.jumpBackToTop !== false; |
| 177 | + //Add this in processed options inside lazyLoadConfiguration key |
| 178 | + processedOptions.lazyLoadConfiguration = { |
| 179 | + enabled: true, |
| 180 | + scrollStep: stepValue, |
| 181 | + scrollDelay: delayValue, |
| 182 | + maxScrolls: maxScrollsValue, |
| 183 | + jumpBackToTop: jumpBackToTopValue |
| 184 | + }; |
| 185 | + } |
| 186 | + |
172 | 187 | try { |
173 | 188 | if (options?.customCSS) { |
174 | 189 | const resolvedCSS = resolveCustomCSS(options.customCSS, '', ctx.log); |
@@ -654,6 +669,21 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context): |
654 | 669 | renderViewports = getRenderViewports(ctx); |
655 | 670 | } |
656 | 671 |
|
| 672 | + if (ctx.config.lazyLoadConfiguration && ctx.config.lazyLoadConfiguration.enabled) { |
| 673 | + let stepValue = ctx.config.lazyLoadConfiguration.scrollStep || 250; |
| 674 | + let delayValue = ctx.config.lazyLoadConfiguration.scrollDelay || 100; |
| 675 | + let maxScrollsValue = ctx.config.lazyLoadConfiguration.maxScrolls || 50; |
| 676 | + let jumpBackToTopValue = ctx.config.lazyLoadConfiguration.jumpBackToTop || false; |
| 677 | + //Add this in processed options inside lazyLoadConfiguration key |
| 678 | + processedOptions.lazyLoadConfiguration = { |
| 679 | + enabled: true, |
| 680 | + scrollStep: stepValue, |
| 681 | + scrollDelay: delayValue, |
| 682 | + maxScrolls: maxScrollsValue, |
| 683 | + jumpBackToTop: jumpBackToTopValue |
| 684 | + }; |
| 685 | + } |
| 686 | + |
657 | 687 | for (const { viewport, viewportString, fullPage, device } of renderViewports) { |
658 | 688 |
|
659 | 689 | // Check if this is the first iteration or if the device type has changed from the previous iteration |
@@ -707,7 +737,19 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context): |
707 | 737 | } |
708 | 738 |
|
709 | 739 | } |
710 | | - if (ctx.config.cliEnableJavaScript && fullPage) await page.evaluate(scrollToBottomAndBackToTop, { frequency: 100, timing: ctx.config.scrollTime }); |
| 740 | + if (ctx.config.cliEnableJavaScript && fullPage) { |
| 741 | + if (ctx.config.lazyLoadConfiguration && ctx.config.lazyLoadConfiguration.enabled) { |
| 742 | + let stepValue = ctx.config.lazyLoadConfiguration.scrollStep || 250; |
| 743 | + let delayValue = ctx.config.lazyLoadConfiguration.scrollDelay || 300; |
| 744 | + let maxScrollsValue = ctx.config.lazyLoadConfiguration.maxScrolls || 50; |
| 745 | + let jumpBackToTopValue = ctx.config.lazyLoadConfiguration.jumpBackToTop !== false; |
| 746 | + ctx.log.debug('Starting lazy load scrolling with configuration: ' + JSON.stringify({ step: stepValue, delay: delayValue, maxScrolls: maxScrollsValue, jumpBackToTop: jumpBackToTopValue })); |
| 747 | + await page.evaluate(smoothScrollToBottom, { step: stepValue, delay: delayValue, maxScrolls: maxScrollsValue, jumpBackToTop: jumpBackToTopValue }); |
| 748 | + ctx.log.debug('Completed lazy load scrolling'); |
| 749 | + } else { |
| 750 | + await page.evaluate(scrollToBottomAndBackToTop, { frequency: 100, timing: ctx.config.scrollTime }); |
| 751 | + } |
| 752 | + } |
711 | 753 |
|
712 | 754 | try { |
713 | 755 | await page.waitForLoadState('networkidle', { timeout: 15000 }); |
|
0 commit comments