@@ -117,6 +117,15 @@ function waitForDiscoveryNetworkIdle(page, options) {
117117 return page . network . idle ( filter , networkIdleTimeout , captureResponsiveAssetsEnabled ) ;
118118}
119119
120+ async function waitForFontLoading ( page ) {
121+ return await logger . measure ( 'core:discovery' , 'waitForFontLoading' , undefined , async ( ) => {
122+ return await Promise . race ( [
123+ page . eval ( 'await document.fonts.ready;' ) ,
124+ new Promise ( ( res ) => setTimeout ( res , 5000 ) )
125+ ] ) ;
126+ } ) ;
127+ }
128+
120129// Creates an initial resource map for a snapshot containing serialized DOM
121130function parseDomResources ( { url, domSnapshot } ) {
122131 const map = new Map ( ) ;
@@ -231,6 +240,7 @@ async function* captureSnapshotResources(page, snapshot, options) {
231240 deviceScaleFactor : device . deviceScaleFactor ,
232241 mobile : true
233242 } ) ;
243+ yield waitForFontLoading ( page ) ;
234244 yield waitForDiscoveryNetworkIdle ( page , discovery ) ;
235245 }
236246 }
@@ -301,6 +311,7 @@ async function* captureSnapshotResources(page, snapshot, options) {
301311 for ( let i = 0 ; i < widths . length - 1 ; i ++ ) {
302312 if ( captureWidths ) yield * takeSnapshot ( snap , width ) ;
303313 yield page . evaluate ( execute ?. beforeResize ) ;
314+ yield waitForFontLoading ( page ) ;
304315 yield waitForDiscoveryNetworkIdle ( page , discovery ) ;
305316 yield resizePage ( width = widths [ i + 1 ] ) ;
306317 if ( snapshot . responsiveSnapshotCapture ) { yield page . goto ( snapshot . url , { cookies, forceReload : true } ) ; }
@@ -328,6 +339,7 @@ async function* captureSnapshotResources(page, snapshot, options) {
328339
329340 // wait for final network idle when not capturing DOM
330341 if ( capture && snapshot . domSnapshot ) {
342+ yield waitForFontLoading ( page ) ;
331343 yield waitForDiscoveryNetworkIdle ( page , discovery ) ;
332344 yield * captureResponsiveAssets ( ) ;
333345 capture ( processSnapshotResources ( snapshot ) ) ;
0 commit comments