@@ -145,14 +145,14 @@ const capitalizeFirstLetter = (str: string) => {
145145 return str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ;
146146} ;
147147
148- export const allScriptsFromDump = (
148+ export const allScriptsFromDump = async (
149149 dump :
150150 | GroupedActionDump
151151 | IGroupedActionDump
152152 | ExecutionDump
153153 | null
154154 | undefined ,
155- ) : ReplayScriptsInfo | null => {
155+ ) : Promise < ReplayScriptsInfo | null > => {
156156 if ( ! dump ) {
157157 console . warn ( '[allScriptsFromDump] dump is empty' ) ;
158158 return {
@@ -205,8 +205,9 @@ export const allScriptsFromDump = (
205205
206206 // Use first dimensions as default for the overall player size
207207 const allScripts : AnimationScript [ ] = [ ] ;
208- normalizedDump . executions ?. filter ( Boolean ) . forEach ( ( execution ) => {
209- const scripts = generateAnimationScripts (
208+ const executions = normalizedDump . executions ?. filter ( Boolean ) || [ ] ;
209+ for ( const execution of executions ) {
210+ const scripts = await generateAnimationScripts (
210211 execution ,
211212 - 1 ,
212213 firstWidth ! ,
@@ -227,7 +228,7 @@ export const allScriptsFromDump = (
227228 }
228229 }
229230 } ) ;
230- } ) ;
231+ }
231232
232233 const allScriptsWithoutIntermediateDoneFrame = allScripts . filter (
233234 ( script , index ) => {
@@ -270,12 +271,12 @@ export const allScriptsFromDump = (
270271 } ;
271272} ;
272273
273- export const generateAnimationScripts = (
274+ export const generateAnimationScripts = async (
274275 execution : ExecutionDump | IExecutionDump | null ,
275276 task : ExecutionTask | number ,
276277 imageWidth : number ,
277278 imageHeight : number ,
278- ) : AnimationScript [ ] | null => {
279+ ) : Promise < AnimationScript [ ] | null > => {
279280 if ( ! execution || ! execution . tasks . length ) return null ;
280281 if ( imageWidth === 0 || imageHeight === 0 ) {
281282 return null ;
@@ -342,8 +343,9 @@ export const generateAnimationScripts = (
342343 const taskCount = tasksIncluded . length ;
343344 let initSubTitle = '' ;
344345 let errorStateFlag = false ;
345- tasksIncluded . forEach ( ( task , index ) => {
346- if ( errorStateFlag ) return ;
346+ for ( let index = 0 ; index < tasksIncluded . length ; index ++ ) {
347+ const task = tasksIncluded [ index ] ;
348+ if ( errorStateFlag ) continue ;
347349
348350 if ( index === 0 ) {
349351 initSubTitle = paramStr ( task ) ;
@@ -395,7 +397,7 @@ export const generateAnimationScripts = (
395397 const screenshotData =
396398 typeof context . screenshot === 'string'
397399 ? context . screenshot
398- : context . screenshot . getData ( ) ;
400+ : await context . screenshot . getData ( ) ;
399401 scripts . push ( {
400402 type : 'img' ,
401403 img : screenshotData ,
@@ -450,8 +452,8 @@ export const generateAnimationScripts = (
450452
451453 const planningTask = task as ExecutionTaskPlanning ;
452454 if ( planningTask . recorder && planningTask . recorder . length > 0 ) {
453- const screenshotData =
454- planningTask . recorder [ 0 ] ?. screenshot ? .getData ( ) || '' ;
455+ const screenshot = planningTask . recorder [ 0 ] ?. screenshot ;
456+ const screenshotData = screenshot ? await screenshot . getData ( ) : '' ;
455457 scripts . push ( {
456458 type : 'img' ,
457459 img : screenshotData ,
@@ -488,8 +490,10 @@ export const generateAnimationScripts = (
488490
489491 currentCameraState = insightCameraState ?? fullPageCameraState ;
490492 // const ifLastTask = index === taskCount - 1;
491- const actionScreenshotData =
492- task . recorder ?. [ 0 ] ?. screenshot ?. getData ( ) || '' ;
493+ const actionScreenshot = task . recorder ?. [ 0 ] ?. screenshot ;
494+ const actionScreenshotData = actionScreenshot
495+ ? await actionScreenshot . getData ( )
496+ : '' ;
493497 scripts . push ( {
494498 type : 'img' ,
495499 img : actionScreenshotData ,
@@ -508,7 +512,7 @@ export const generateAnimationScripts = (
508512
509513 if ( screenshot ) {
510514 const screenshotData =
511- typeof screenshot === 'string' ? screenshot : screenshot . getData ( ) ;
515+ typeof screenshot === 'string' ? screenshot : await screenshot . getData ( ) ;
512516 scripts . push ( {
513517 type : 'img' ,
514518 img : screenshotData ,
@@ -529,10 +533,13 @@ export const generateAnimationScripts = (
529533 errorMsg . indexOf ( 'NOT_IMPLEMENTED_AS_DESIGNED' ) > 0
530534 ? 'Further actions cannot be performed in the current environment'
531535 : errorMsg ;
532- const errorScreenshotData =
536+ const errorScreenshot =
533537 task . recorder && task . recorder . length > 0
534- ? task . recorder [ task . recorder . length - 1 ] . screenshot ?. getData ( ) || ''
535- : '' ;
538+ ? task . recorder [ task . recorder . length - 1 ] . screenshot
539+ : undefined ;
540+ const errorScreenshotData = errorScreenshot
541+ ? await errorScreenshot . getData ( )
542+ : '' ;
536543 scripts . push ( {
537544 type : 'img' ,
538545 img : errorScreenshotData ,
0 commit comments