11import  {  Snapshot ,  Context ,  ProcessedSnapshot  }  from  "../types.js" ; 
22import  {  scrollToBottomAndBackToTop ,  getRenderViewports  }  from  "./utils.js" 
3- import  {  firefox ,  Locator  }  from  "@playwright/test" 
3+ import  {  chromium ,  Locator  }  from  "@playwright/test" 
44import  constants  from  "./constants.js" ; 
55import  {  updateLogContext  }  from  '../lib/logger.js' 
66
@@ -82,13 +82,13 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
8282
8383    let  launchOptions : Record < string ,  any >  =  {  headless : true  } 
8484    let  contextOptions : Record < string ,  any >  =  { 
85-         javaScriptEnabled : ctx . config . enableJavaScript , 
85+         javaScriptEnabled : ctx . config . cliEnableJavaScript , 
8686        userAgent : constants . CHROME_USER_AGENT , 
8787    } 
8888    if  ( ! ctx . browser ?. isConnected ( ) )  { 
8989        if  ( ctx . env . HTTP_PROXY  ||  ctx . env . HTTPS_PROXY )  launchOptions . proxy  =  {  server : ctx . env . HTTP_PROXY  ||  ctx . env . HTTPS_PROXY  } ; 
90-         ctx . browser  =  await  firefox . launch ( launchOptions ) ; 
91-         ctx . log . debug ( `Firefox  launched with options ${ JSON . stringify ( launchOptions ) }  ` ) ; 
90+         ctx . browser  =  await  chromium . launch ( launchOptions ) ; 
91+         ctx . log . debug ( `Chromium  launched with options ${ JSON . stringify ( launchOptions ) }  ` ) ; 
9292    } 
9393    const  context  =  await  ctx . browser . newContext ( contextOptions ) ; 
9494    ctx . log . debug ( `Browser context created with options ${ JSON . stringify ( contextOptions ) }  ` ) ; 
@@ -198,8 +198,21 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
198198
199199    // process for every viewport 
200200    let  navigated : boolean  =  false ; 
201+     let  previousDeviceType : string  |  null  =  null ; 
201202    let  renderViewports  =  getRenderViewports ( ctx ) ; 
202-     for  ( const  {  viewport,  viewportString,  fullPage }  of  renderViewports )  { 
203+ 
204+     for  ( const  {  viewport,  viewportString,  fullPage,  device }  of  renderViewports )  { 
205+ 
206+         // Check if this is the first iteration or if the device type has changed from the previous iteration 
207+         if  ( previousDeviceType  !==  null  &&  previousDeviceType  !==  device )  { 
208+             // If the device type has changed, reset `navigated` to false 
209+             // This indicates that we haven't navigated to the required page for the new device type yet 
210+             navigated  =  false ; 
211+         } 
212+ 
213+         // Update `previousDeviceType` to the current device type for comparison in the next iteration 
214+         previousDeviceType  =  device ; 
215+ 
203216        await  page . setViewportSize ( {  width : viewport . width ,  height : viewport . height  ||   MIN_VIEWPORT_HEIGHT  } ) ; 
204217        ctx . log . debug ( `Page resized to ${ viewport . width }  x${ viewport . height  ||   MIN_VIEWPORT_HEIGHT }  ` ) ; 
205218
@@ -219,14 +232,16 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
219232            } 
220233
221234        } 
222-         if  ( ctx . config . enableJavaScript  &&  fullPage )  await  page . evaluate ( scrollToBottomAndBackToTop ) ; 
235+         if  ( ctx . config . cliEnableJavaScript  &&  fullPage )  await  page . evaluate ( scrollToBottomAndBackToTop ,   {   frequency :  100 ,   timing :  ctx . config . scrollTime   } ) ; 
223236
224237        try  { 
225238            await  page . waitForLoadState ( 'networkidle' ,  {  timeout : 5000  } ) ; 
226239            ctx . log . debug ( 'Network idle 500ms' ) ; 
227240        }  catch  ( error )  { 
228241            ctx . log . debug ( `Network idle failed due to ${ error }  ` ) ; 
229242        } 
243+ 
244+         await  new  Promise ( r  =>  setTimeout ( r ,  1000 ) ) ; 
230245
231246        // snapshot options 
232247        if  ( processedOptions . element )  { 
0 commit comments