diff --git a/packages/core/src/tools/utils/timeUtils.ts b/packages/core/src/tools/utils/timeUtils.ts index 648b23b00c..44d974b824 100644 --- a/packages/core/src/tools/utils/timeUtils.ts +++ b/packages/core/src/tools/utils/timeUtils.ts @@ -80,13 +80,7 @@ export function addDuration(a: number, b: number) { return a + b } -/** - * Get the time since the navigation was started. - * - * Note: this does not use `performance.timeOrigin` because it doesn't seem to reflect the actual - * time on which the navigation has started: it may be much farther in the past, at least in Firefox 71. - * Related issue in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1429926 - */ +// Get the time since the navigation was started. export function getRelativeTime(timestamp: TimeStamp) { return (timestamp - getNavigationStart()) as RelativeTime } @@ -104,6 +98,12 @@ export function looksLikeRelativeTime(time: RelativeTime | TimeStamp): time is R */ let navigationStart: TimeStamp | undefined +/** + * Notes: this does not use `performance.timeOrigin` because: + * - It doesn't seem to reflect the actual time on which the navigation has started: it may be much farther in the past, + * at least in Firefox 71. (see: https://bugzilla.mozilla.org/show_bug.cgi?id=1429926) + * - It is not supported in Safari <15 + */ function getNavigationStart() { if (navigationStart === undefined) { navigationStart = performance.timing.navigationStart as TimeStamp diff --git a/packages/core/test/emulate/mockClock.ts b/packages/core/test/emulate/mockClock.ts index bb4bb6dcde..c53f05c438 100644 --- a/packages/core/test/emulate/mockClock.ts +++ b/packages/core/test/emulate/mockClock.ts @@ -6,7 +6,7 @@ export function mockClock() { jasmine.clock().install() jasmine.clock().mockDate() - const timeOrigin = performance.timing.navigationStart // TODO: use performance.timeOrigin when we drop IE11 support + const timeOrigin = performance.timing.navigationStart // @see getNavigationStart() in timeUtils.ts const timeStampStart = Date.now() const relativeStart = timeStampStart - timeOrigin