Skip to content

Commit ef879bf

Browse files
authored
fix(apm): Use Performance API for timings when available (getsentry#2492)
Instead of downgrading to use the dumb performanceFallback, in the absence of a timeOrigin we can use INITIAL_TIME. This should give better timings in Safari Web Workers.
1 parent 098f4b8 commit ef879bf

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
66

7+
- [apm] fix: Use Performance API for timings when available, including Web Workers (#2492)
8+
79
## 5.14.1
810

911
- [apm] fix: Check for performance.timing in webworkers (#2491)

packages/utils/src/misc.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -378,19 +378,11 @@ export const crossPlatformPerformance: Pick<Performance, 'now' | 'timeOrigin'> =
378378
// is not as widely supported. Namely, performance.timeOrigin is undefined in Safari as of writing.
379379
// tslint:disable-next-line:strict-type-predicates
380380
if (performance.timeOrigin === undefined) {
381-
// For webworkers it could mean we don't have performance.timing then we fallback
382-
// tslint:disable-next-line:deprecation
383-
if (!performance.timing) {
384-
return performanceFallback;
385-
}
386-
// tslint:disable-next-line:deprecation
387-
if (!performance.timing.navigationStart) {
388-
return performanceFallback;
389-
}
390-
381+
// As of writing, performance.timing is not available in Web Workers in mainstream browsers, so it is not always a
382+
// valid fallback. In the absence of a initial time provided by the browser, fallback to INITIAL_TIME.
391383
// @ts-ignore
392384
// tslint:disable-next-line:deprecation
393-
performance.timeOrigin = performance.timing.navigationStart;
385+
performance.timeOrigin = (performance.timing && performance.timing.navigationStart) || INITIAL_TIME;
394386
}
395387
}
396388

0 commit comments

Comments
 (0)