import { i18n } from '@kbn/i18n' ; import apm from 'elastic-apm-node' ; import type { Logger } from 'src/core/server' ; import type { HeadlessChromiumDriver } from '../browsers' ; import type { Layout } from '../layouts' ; import { CONTEXT_GETRENDERERRORS } from './constants' ; export const getRenderErrors = async ( browser , logger , layout ) : Promise < undefined | string [ ] > => { const span = apm . startSpan ( 'get_render_errors' , 'read' ) ; logger . debug ( 'reading render errors' ) ; const errorsFound = await browser . evaluate ( { fn : ( errorSelector , errorAttribute ) => { const visualizations = Array . from ( document . querySelectorAll ( errorSelector ) ) ; const errors = [ ] ; visualizations . forEach ( ( visualization ) => { const errorMessage = visualization . getAttribute ( errorAttribute ) ; if ( errorMessage ) { errors . push ( errorMessage ) ; } } ) ; return errors . length ? errors : undefined ; } , args : [ layout . selectors . renderError , layout . selectors . renderErrorAttribute ] , } , { context : CONTEXT_GETRENDERERRORS } , logger ) ; span ?. end ( ) ; if ( errorsFound ?. length ) { logger . warn ( i18n . translate ( 'xpack.screenshotting.screencapture.renderErrorsFound' , { defaultMessage : 'Found {count} error messages. See report object for more information.' , values : { count : errorsFound . length } , } ) ) ; } return errorsFound ; } ;