Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👷 [RUM-6820] fix comment about performance.timing.navigationStart #3180

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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