@@ -7,6 +7,17 @@ import constants from './constants.js'
77import chalk from 'chalk' ;
88import sharp from 'sharp' ;
99
10+ async function humanLikeScroll ( page : Page ) {
11+ // Move mouse in human like manner
12+ await page . waitForTimeout ( 2000 ) ;
13+ await page . mouse . move ( 100 , 100 ) ;
14+ await page . waitForTimeout ( 300 ) ;
15+ await page . mouse . move ( 300 , 200 ) ;
16+ await page . waitForTimeout ( 300 ) ;
17+ await page . mouse . move ( 500 , 300 ) ;
18+ await page . waitForTimeout ( 2000 ) ;
19+ }
20+
1021async function captureScreenshotsForConfig (
1122 ctx : Context ,
1223 browsers : Record < string , Browser > ,
@@ -253,7 +264,25 @@ async function captureScreenshotsForConfig(
253264 }
254265 let ssPath = `screenshots/${ ssId } /${ `${ browserName } -${ viewport . width } x${ viewport . height } ` } -${ ssId } .png` ;
255266 await page ?. setViewportSize ( { width : viewport . width , height : viewport . height || constants . MIN_VIEWPORT_HEIGHT } ) ;
256- if ( fullPage ) await page ?. evaluate ( utils . scrollToBottomAndBackToTop ) ;
267+ // again load page to apply viewport size properly
268+ await page ?. goto ( url . trim ( ) , pageOptions ) ;
269+ ctx . log . debug ( `Capturing screenshot for URL: ${ url } on ${ browserName } with viewport: ${ viewportString } (fullPage: ${ fullPage } )` ) ;
270+ if ( page && ctx . config . lazyLoadConfiguration ) {
271+ await humanLikeScroll ( page ) ;
272+ }
273+ if ( fullPage ) {
274+ if ( ctx . config . lazyLoadConfiguration && ctx . config . lazyLoadConfiguration . enabled ) {
275+ let stepValue = ctx . config . lazyLoadConfiguration . scrollStep || 250 ;
276+ let delayValue = ctx . config . lazyLoadConfiguration . scrollDelay || 300 ;
277+ let maxScrollsValue = ctx . config . lazyLoadConfiguration . maxScrolls || 50 ;
278+ let jumpBackToTopValue = ctx . config . lazyLoadConfiguration . jumpBackToTop !== false ;
279+ ctx . log . debug ( 'Capture: Starting lazy load scrolling with configuration: ' + JSON . stringify ( { step : stepValue , delay : delayValue , maxScrolls : maxScrollsValue , jumpBackToTop : jumpBackToTopValue } ) ) ;
280+ await page ?. evaluate ( utils . smoothScrollToBottom , { step : stepValue , delay : delayValue , maxScrolls : maxScrollsValue , jumpBackToTop : jumpBackToTopValue } ) ;
281+ ctx . log . debug ( 'Capture: Completed lazy load scrolling' ) ;
282+ } else {
283+ await page ?. evaluate ( utils . scrollToBottomAndBackToTop , { frequency : 100 , timing : ctx . config . scrollTime } ) ;
284+ }
285+ }
257286 await page ?. waitForTimeout ( waitForTimeout || 0 ) ;
258287 await executeDocumentScripts ( ctx , page , "beforeSnapshot" , beforeSnapshotScript )
259288
0 commit comments