import apm from 'elastic-apm-node' ; import type { Logger } from 'src/core/server' ; import type { HeadlessChromiumDriver } from '../browsers' ; import { Layout } from '../layouts' ; import { CONTEXT_GETTIMERANGE } from './constants' ; export const getTimeRange = async ( browser , logger , layout ) : Promise < string | null > => { const span = apm . startSpan ( 'get_time_range' , 'read' ) ; logger . debug ( 'getting timeRange' ) ; const timeRange = await browser . evaluate ( { fn : ( durationAttribute ) => { const durationElement = document . querySelector ( `[${ durationAttribute }]` ) ; if ( ! durationElement ) { return null ; } const duration = durationElement . getAttribute ( durationAttribute ) ; if ( ! duration ) { return null ; } return duration ; } , args : [ layout . selectors . timefilterDurationAttribute ] , } , { context : CONTEXT_GETTIMERANGE } , logger ) ; if ( timeRange ) { logger . info ( `timeRange: ${ timeRange }` ) ; } else { logger . debug ( 'no timeRange' ) ; } span ?. end ( ) ; return timeRange ; } ;