@@ -417,6 +417,41 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
417417 ctx . log . debug ( `Network idle failed due to ${ error } ` ) ;
418418 }
419419
420+ if ( ctx . config . allowedAssets && ctx . config . allowedAssets . length ) {
421+ for ( let assetUrl of ctx . config . allowedAssets ) {
422+ if ( ! cache [ assetUrl ] ) {
423+ ctx . log . debug ( `Fetching asset ${ assetUrl } from allowedAssets array` ) ;
424+ try {
425+ const response = await page . request . fetch ( assetUrl , {
426+ timeout : 25000 ,
427+ headers : {
428+ ...constants . REQUEST_HEADERS
429+ }
430+ } ) ;
431+
432+ const body = await response . body ( ) ;
433+
434+ if ( body && body . length ) {
435+ ctx . log . debug ( `Caching asset ${ assetUrl } ` ) ;
436+ cache [ assetUrl ] = {
437+ body : body . toString ( 'base64' ) ,
438+ type : response . headers ( ) [ 'content-type' ]
439+ } ;
440+ } else {
441+ ctx . log . debug ( `Asset ${ assetUrl } returned empty or invalid body` ) ;
442+ }
443+ } catch ( error ) {
444+ if ( error && error . message ) {
445+ ctx . log . debug ( `Error fetching asset with error message ${ assetUrl } : ${ error . message } ` ) ;
446+ }
447+ ctx . log . debug ( `Error fetching asset ${ assetUrl } : ${ JSON . stringify ( error ) } ` ) ;
448+ }
449+ } else {
450+ ctx . log . debug ( `Asset ${ assetUrl } already cached` ) ;
451+ }
452+ }
453+ }
454+
420455 // snapshot options
421456 if ( processedOptions . element ) {
422457 let l = await page . locator ( processedOptions . element ) . all ( )
@@ -506,6 +541,18 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
506541 discoveryErrors . timestamp = new Date ( ) . toISOString ( ) ;
507542 // ctx.log.warn(discoveryErrors);
508543 }
544+
545+ if ( ctx . config . useGlobalCache ) {
546+ const keys = globalCache . keys ( ) ;
547+ keys . forEach ( ( key ) => {
548+ if ( ! ( key in cache ) ) {
549+ const globalCacheData = globalCache . get ( key ) ;
550+ if ( globalCacheData ) {
551+ cache [ key ] = globalCacheData ;
552+ }
553+ }
554+ } ) ;
555+ }
509556 return {
510557 processedSnapshot : {
511558 name : snapshot . name ,
0 commit comments