import { i18n } from '@kbn/i18n' ; import { ReportingCore } from '../..' ; import { API_DIAGNOSE_URL } from '../../../common/constants' ; import { LevelLogger as Logger } from '../../lib' ; import { authorizedUserPreRouting } from '../lib/authorized_user_pre_routing' ; import { DiagnosticResponse } from './' ; const logsToHelpMap = { 'error while loading shared libraries' : i18n . translate ( 'xpack.reporting.diagnostic.browserMissingDependency' , { defaultMessage : `The browser couldn't start properly due to missing system dependencies. Please see {url}` , values : { url : 'https://www.elastic.co/guide/en/kibana/current/reporting-troubleshooting.html#reporting-troubleshooting-system-dependencies' , } , } ) , 'Could not find the default font' : i18n . translate ( 'xpack.reporting.diagnostic.browserMissingFonts' , { defaultMessage : `The browser couldn't locate a default font. Please see {url} to fix this issue.` , values : { url : 'https://www.elastic.co/guide/en/kibana/current/reporting-troubleshooting.html#reporting-troubleshooting-system-dependencies' , } , } ) , 'No usable sandbox' : i18n . translate ( 'xpack.reporting.diagnostic.noUsableSandbox' , { defaultMessage : `Unable to use Chromium sandbox. This can be disabled at your own risk with 'xpack.reporting.capture.browser.chromium.disableSandbox'. Please see {url}` , values : { url : 'https://www.elastic.co/guide/en/kibana/current/reporting-troubleshooting.html#reporting-troubleshooting-sandbox-dependency' , } , } ) , } ; export const registerDiagnoseBrowser = ( reporting , logger ) => { const { router } = reporting . getPluginSetupDeps ( ) ; router . post ( { path : `${ API_DIAGNOSE_URL }/browser` , validate : { } , } , authorizedUserPreRouting ( reporting , async ( _user , _context , _req , res ) => { try { const { screenshotting } = await reporting . getPluginStartDeps ( ) ; const logs = await screenshotting . diagnose ( ) . toPromise ( ) ; const knownIssues = Object . keys ( logsToHelpMap ) as Array < keyof typeof logsToHelpMap > ; const boundSuccessfully = logs . includes ( `DevTools listening on` ) ; const help = knownIssues . reduce ( ( helpTexts , knownIssue ) => { const helpText = logsToHelpMap [ knownIssue ] ; if ( logs . includes ( knownIssue ) ) { helpTexts . push ( helpText ) ; } return helpTexts ; } , [ ] ) ; const response = { success : boundSuccessfully && ! help . length , help , logs , } ; return res . ok ( { body : response } ) ; } catch ( err ) { logger . error ( err ) ; return res . custom ( { statusCode : 500 } ) ; } } ) ) ; } ;