Skip to content

Commit

Permalink
👷 fix comment about performance.timing.navigationStart (#3180)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-lebeau authored Nov 28, 2024
1 parent 06de05a commit 3485ca5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions packages/core/src/tools/utils/timeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/emulate/mockClock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3485ca5

Please sign in to comment.