@@ -12,13 +12,18 @@ const MIN_VIEWPORT_HEIGHT = 1080;
12
12
export default async ( snapshot : Snapshot , ctx : Context ) : Promise < Record < string , any > > => {
13
13
ctx . log . debug ( `Processing snapshot ${ snapshot . name } ` ) ;
14
14
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
+ }
15
20
if ( ! ctx . browser ) {
16
- let launchOptions : Record < string , any > = { headless : true }
17
21
if ( ctx . env . HTTP_PROXY || ctx . env . HTTPS_PROXY ) launchOptions . proxy = { server : ctx . env . HTTP_PROXY || ctx . env . HTTPS_PROXY } ;
18
22
ctx . browser = await chromium . launch ( launchOptions ) ;
19
23
ctx . log . debug ( `Chromium launched with options ${ JSON . stringify ( launchOptions ) } ` ) ;
20
24
}
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 ) } ` ) ;
22
27
const page = await context . newPage ( ) ;
23
28
let cache : Record < string , any > = { } ;
24
29
@@ -132,15 +137,21 @@ export default async (snapshot: Snapshot, ctx: Context): Promise<Record<string,
132
137
133
138
// navigate to snapshot url once
134
139
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
+
142
153
}
143
- if ( fullPage ) await page . evaluate ( scrollToBottomAndBackToTop ) ;
154
+ if ( ctx . config . enableJavaScript && fullPage ) await page . evaluate ( scrollToBottomAndBackToTop ) ;
144
155
145
156
try {
146
157
await page . waitForLoadState ( 'networkidle' , { timeout : 5000 } ) ;
@@ -181,9 +192,6 @@ export default async (snapshot: Snapshot, ctx: Context): Promise<Record<string,
181
192
}
182
193
}
183
194
184
- await page . close ( ) ;
185
- await context . close ( ) ;
186
-
187
195
// add dom resources to cache
188
196
if ( snapshot . dom . resources . length ) {
189
197
for ( let resource of snapshot . dom . resources ) {
0 commit comments