Skip to content

Commit 13ab8e5

Browse files
authored
fix(apm): Remove Performance references (getsentry#2495)
* fix: Calling Performance to not require dom * meta: Changelog * ref: Type
1 parent ef879bf commit 13ab8e5

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
66

77
- [apm] fix: Use Performance API for timings when available, including Web Workers (#2492)
8+
- [apm] fix: Remove Performance references (#2495)
89

910
## 5.14.1
1011

packages/utils/src/misc.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,18 @@ function _htmlElementAsString(el: unknown): string {
349349
const INITIAL_TIME = Date.now();
350350
let prevNow = 0;
351351

352-
const performanceFallback: Pick<Performance, 'now' | 'timeOrigin'> = {
352+
/**
353+
* Cross platform compatible partial performance implementation
354+
*/
355+
interface CrossPlatformPerformance {
356+
/**
357+
* Returns the current timestamp in ms
358+
*/
359+
now(): number;
360+
timeOrigin: number;
361+
}
362+
363+
const performanceFallback: CrossPlatformPerformance = {
353364
now(): number {
354365
let now = Date.now() - INITIAL_TIME;
355366
if (now < prevNow) {
@@ -361,10 +372,10 @@ const performanceFallback: Pick<Performance, 'now' | 'timeOrigin'> = {
361372
timeOrigin: INITIAL_TIME,
362373
};
363374

364-
export const crossPlatformPerformance: Pick<Performance, 'now' | 'timeOrigin'> = (() => {
375+
export const crossPlatformPerformance: CrossPlatformPerformance = (() => {
365376
if (isNodeEnv()) {
366377
try {
367-
const perfHooks = dynamicRequire(module, 'perf_hooks') as { performance: Performance };
378+
const perfHooks = dynamicRequire(module, 'perf_hooks') as { performance: CrossPlatformPerformance };
368379
return perfHooks.performance;
369380
} catch (_) {
370381
return performanceFallback;

0 commit comments

Comments
 (0)