1- import { Snapshot , Context , ProcessedSnapshot } from "../types.js" ;
1+ import { Snapshot , Context , DiscoveryErrors } from "../types.js" ;
22import { scrollToBottomAndBackToTop , getRenderViewports , getRenderViewportsForOptions } from "./utils.js"
33import { chromium , Locator } from "@playwright/test"
44import constants from "./constants.js" ;
@@ -16,7 +16,17 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
1616 updateLogContext ( { task : 'discovery' } ) ;
1717 ctx . log . debug ( `Processing snapshot ${ snapshot . name } ${ snapshot . url } ` ) ;
1818 const isHeadless = process . env . HEADLESS ?. toLowerCase ( ) === 'false' ? false : true ;
19+ let discoveryErrors : DiscoveryErrors = {
20+ name : "" ,
21+ url : "" ,
22+ timestamp : "" ,
23+ snapshotUUID : "" ,
24+ browsers : {
25+ chrome : { }
26+ }
27+ } ;
1928
29+ let globalViewport = ""
2030 let launchOptions : Record < string , any > = {
2131 headless : isHeadless ,
2232 args : constants . LAUNCH_ARGS
@@ -84,7 +94,7 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
8494 ...constants . REQUEST_HEADERS
8595 }
8696 }
87-
97+
8898 try {
8999 // abort audio/video media requests
90100 if ( / \. ( m p 3 | m p 4 | w a v | o g g | w e b m ) $ / i. test ( request . url ( ) ) ) {
@@ -141,10 +151,23 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
141151 ctx . log . debug ( `Handling request ${ requestUrl } \n - skipping already cached resource` ) ;
142152 } else if ( body . length > MAX_RESOURCE_SIZE ) {
143153 ctx . log . debug ( `Handling request ${ requestUrl } \n - skipping resource larger than 15MB` ) ;
144- } else if ( ! ALLOWED_STATUSES . includes ( response . status ( ) ) ) {
145- ctx . log . debug ( `Handling request ${ requestUrl } \n - skipping disallowed status [${ response . status ( ) } ]` ) ;
146154 } else if ( ! ALLOWED_RESOURCES . includes ( request . resourceType ( ) ) ) {
147155 ctx . log . debug ( `Handling request ${ requestUrl } \n - skipping disallowed resource type [${ request . resourceType ( ) } ]` ) ;
156+ } else if ( ! ALLOWED_STATUSES . includes ( response . status ( ) ) ) {
157+ ctx . log . debug ( `${ globalViewport } Handling request ${ requestUrl } \n - skipping disallowed status [${ response . status ( ) } ]` ) ;
158+ let data = {
159+ statusCode : `${ response . status ( ) } ` ,
160+ url : requestUrl ,
161+ resourceType : request . resourceType ( ) ,
162+ }
163+ if ( ! discoveryErrors . browsers . chrome ) {
164+ discoveryErrors . browsers . chrome = { } ;
165+ }
166+ if ( ! discoveryErrors . browsers . chrome [ globalViewport ] ) {
167+ discoveryErrors . browsers . chrome [ globalViewport ] = [ ] ;
168+ }
169+ discoveryErrors . browsers . chrome [ globalViewport ] ?. push ( data ) ;
170+
148171 } else {
149172 ctx . log . debug ( `Handling request ${ requestUrl } \n - content-type ${ response . headers ( ) [ 'content-type' ] } ` ) ;
150173
@@ -304,10 +327,14 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
304327
305328 await page . setViewportSize ( { width : viewport . width , height : viewport . height || MIN_VIEWPORT_HEIGHT } ) ;
306329 ctx . log . debug ( `Page resized to ${ viewport . width } x${ viewport . height || MIN_VIEWPORT_HEIGHT } ` ) ;
330+ globalViewport = viewportString ;
331+ ctx . log . debug ( `globalViewport : ${ globalViewport } ` ) ;
307332
308333 // navigate to snapshot url once
309334 if ( ! navigated ) {
310335 try {
336+ discoveryErrors . url = snapshot . url ;
337+ discoveryErrors . name = snapshot . name ;
311338 // domcontentloaded event is more reliable than load event
312339 await page . goto ( snapshot . url , { waitUntil : "domcontentloaded" , timeout : ctx . config . waitForDiscovery } ) ;
313340 // adding extra timeout since domcontentloaded event is fired pretty quickly
@@ -399,6 +426,8 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
399426 ctx . log . debug ( `Processed options: ${ JSON . stringify ( processedOptions ) } ` ) ;
400427 }
401428
429+ discoveryErrors . timestamp = new Date ( ) . toISOString ( ) ;
430+
402431 return {
403432 processedSnapshot : {
404433 name : snapshot . name ,
@@ -407,6 +436,7 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
407436 resources : cache ,
408437 options : processedOptions
409438 } ,
410- warnings : [ ...optionWarnings , ...snapshot . dom . warnings ]
439+ warnings : [ ...optionWarnings , ...snapshot . dom . warnings ] ,
440+ discoveryErrors : discoveryErrors
411441 }
412442}
0 commit comments