diff --git a/packages/utils/src/misc.ts b/packages/utils/src/misc.ts index cc63caa8f165..76720fe7575a 100644 --- a/packages/utils/src/misc.ts +++ b/packages/utils/src/misc.ts @@ -382,22 +382,26 @@ export const crossPlatformPerformance: CrossPlatformPerformance = (() => { } } - if (getGlobalObject().performance) { - // Polyfill for performance.timeOrigin. - // - // While performance.timing.navigationStart is deprecated in favor of performance.timeOrigin, performance.timeOrigin - // is not as widely supported. Namely, performance.timeOrigin is undefined in Safari as of writing. - // tslint:disable-next-line:strict-type-predicates - if (performance.timeOrigin === undefined) { - // As of writing, performance.timing is not available in Web Workers in mainstream browsers, so it is not always a - // valid fallback. In the absence of a initial time provided by the browser, fallback to INITIAL_TIME. - // @ts-ignore - // tslint:disable-next-line:deprecation - performance.timeOrigin = (performance.timing && performance.timing.navigationStart) || INITIAL_TIME; - } + const { performance } = getGlobalObject(); + + if (!performance || !performance.now) { + return performanceFallback; + } + + // Polyfill for performance.timeOrigin. + // + // While performance.timing.navigationStart is deprecated in favor of performance.timeOrigin, performance.timeOrigin + // is not as widely supported. Namely, performance.timeOrigin is undefined in Safari as of writing. + // tslint:disable-next-line:strict-type-predicates + if (performance.timeOrigin === undefined) { + // As of writing, performance.timing is not available in Web Workers in mainstream browsers, so it is not always a + // valid fallback. In the absence of a initial time provided by the browser, fallback to INITIAL_TIME. + // @ts-ignore + // tslint:disable-next-line:deprecation + performance.timeOrigin = (performance.timing && performance.timing.navigationStart) || INITIAL_TIME; } - return getGlobalObject().performance || performanceFallback; + return performance; })(); /**