@@ -12,13 +12,18 @@ const MIN_VIEWPORT_HEIGHT = 1080;
1212export default async ( snapshot : Snapshot , ctx : Context ) : Promise < Record < string , any > > => {
1313 ctx . log . debug ( `Processing snapshot ${ snapshot . name } ` ) ;
1414
15+ let launchOptions : Record < string , any > = { headless : true }
16+ let contextOptions : Record < string , any > = {
17+ javaScriptEnabled : ctx . config . enableJavaScript ,
18+ userAgent : constants . CHROME_USER_AGENT ,
19+ }
1520 if ( ! ctx . browser ) {
16- let launchOptions : Record < string , any > = { headless : true }
1721 if ( ctx . env . HTTP_PROXY || ctx . env . HTTPS_PROXY ) launchOptions . proxy = { server : ctx . env . HTTP_PROXY || ctx . env . HTTPS_PROXY } ;
1822 ctx . browser = await chromium . launch ( launchOptions ) ;
1923 ctx . log . debug ( `Chromium launched with options ${ JSON . stringify ( launchOptions ) } ` ) ;
2024 }
21- const context = await ctx . browser . newContext ( { userAgent : constants . CHROME_USER_AGENT } )
25+ const context = await ctx . browser . newContext ( contextOptions ) ;
26+ ctx . log . debug ( `Browser context created with options ${ JSON . stringify ( contextOptions ) } ` ) ;
2227 const page = await context . newPage ( ) ;
2328 let cache : Record < string , any > = { } ;
2429
@@ -132,15 +137,21 @@ export default async (snapshot: Snapshot, ctx: Context): Promise<Record<string,
132137
133138 // navigate to snapshot url once
134139 if ( ! navigated ) {
135- // domcontentloaded event is more reliable than load event
136- await page . goto ( snapshot . url , { waitUntil : "domcontentloaded" } ) ;
137- // adding extra timeout since domcontentloaded event is fired pretty quickly
138- await new Promise ( r => setTimeout ( r , 1250 ) ) ;
139- if ( ctx . config . waitForTimeout ) await page . waitForTimeout ( ctx . config . waitForTimeout ) ;
140- navigated = true ;
141- ctx . log . debug ( `Navigated to ${ snapshot . url } ` ) ;
140+ try {
141+ // domcontentloaded event is more reliable than load event
142+ await page . goto ( snapshot . url , { waitUntil : "domcontentloaded" } ) ;
143+ // adding extra timeout since domcontentloaded event is fired pretty quickly
144+ await new Promise ( r => setTimeout ( r , 1250 ) ) ;
145+ if ( ctx . config . waitForTimeout ) await page . waitForTimeout ( ctx . config . waitForTimeout ) ;
146+ navigated = true ;
147+ ctx . log . debug ( `Navigated to ${ snapshot . url } ` ) ;
148+ } catch ( error : any ) {
149+ ctx . log . debug ( `Navigation to discovery page failed; ${ error } ` )
150+ throw new Error ( error . message )
151+ }
152+
142153 }
143- if ( fullPage ) await page . evaluate ( scrollToBottomAndBackToTop ) ;
154+ if ( ctx . config . enableJavaScript && fullPage ) await page . evaluate ( scrollToBottomAndBackToTop ) ;
144155
145156 try {
146157 await page . waitForLoadState ( 'networkidle' , { timeout : 5000 } ) ;
@@ -181,9 +192,6 @@ export default async (snapshot: Snapshot, ctx: Context): Promise<Record<string,
181192 }
182193 }
183194
184- await page . close ( ) ;
185- await context . close ( ) ;
186-
187195 // add dom resources to cache
188196 if ( snapshot . dom . resources . length ) {
189197 for ( let resource of snapshot . dom . resources ) {
0 commit comments