feat/fix(tracker):4.1.8:recalculate timeOrigin on start
This commit is contained in:
parent
4e78f2ddc7
commit
a903d5c1b7
5 changed files with 21 additions and 10 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@openreplay/tracker",
|
||||
"description": "The OpenReplay tracker main package",
|
||||
"version": "4.1.7",
|
||||
"version": "4.1.8",
|
||||
"keywords": [
|
||||
"logging",
|
||||
"replay"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import type Message from './messages.gen.js'
|
||||
import { Timestamp, Metadata, UserID } from './messages.gen.js'
|
||||
import { now, deprecationWarn } from '../utils.js'
|
||||
import { now, adjustTimeOrigin, deprecationWarn } from '../utils.js'
|
||||
import Nodes from './nodes.js'
|
||||
import Observer from './observer/top_observer.js'
|
||||
import Sanitizer from './sanitizer.js'
|
||||
|
|
@ -369,6 +369,7 @@ export default class App {
|
|||
this.sessionStorage.removeItem(this.options.session_reset_key)
|
||||
}
|
||||
}
|
||||
|
||||
private _start(startOpts: StartOptions = {}, resetByWorker = false): Promise<StartPromiseReturn> {
|
||||
if (!this.worker) {
|
||||
return Promise.resolve(UnsuccessfulStart('No worker found: perhaps, CSP is not set.'))
|
||||
|
|
@ -381,6 +382,7 @@ export default class App {
|
|||
)
|
||||
}
|
||||
this.activityState = ActivityState.Starting
|
||||
adjustTimeOrigin()
|
||||
|
||||
if (startOpts.sessionHash) {
|
||||
this.session.applySessionHash(startOpts.sessionHash)
|
||||
|
|
|
|||
|
|
@ -226,13 +226,13 @@ export default function (app: App, opts: Partial<Options>): void {
|
|||
paintBlocks === null
|
||||
? 0
|
||||
: calculateSpeedIndex(firstContentfulPaint || firstPaint, paintBlocks)
|
||||
const { domContentLoadedEventEnd, navigationStart } = performance.timing
|
||||
const timeToInteractive =
|
||||
interactiveWindowTickTime === null
|
||||
? Math.max(
|
||||
interactiveWindowStartTime,
|
||||
firstContentfulPaint,
|
||||
performance.timing.domContentLoadedEventEnd - performance.timing.navigationStart ||
|
||||
0,
|
||||
domContentLoadedEventEnd - navigationStart || 0,
|
||||
)
|
||||
: 0
|
||||
app.send(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import type App from '../app/index.js'
|
||||
import { getTimeOrigin } from '../utils.js'
|
||||
import { SetPageLocation, SetViewportSize, SetPageVisibility } from '../app/messages.gen.js'
|
||||
|
||||
export default function (app: App): void {
|
||||
let url: string, width: number, height: number
|
||||
let navigationStart = performance.timing.navigationStart
|
||||
let navigationStart: number
|
||||
|
||||
const sendSetPageLocation = app.safe(() => {
|
||||
const { URL } = document
|
||||
|
|
@ -30,6 +31,7 @@ export default function (app: App): void {
|
|||
|
||||
app.attachStartCallback(() => {
|
||||
url = ''
|
||||
navigationStart = getTimeOrigin()
|
||||
width = height = -1
|
||||
sendSetPageLocation()
|
||||
sendSetViewportSize()
|
||||
|
|
|
|||
|
|
@ -6,12 +6,19 @@ export const IS_FIREFOX = IN_BROWSER && navigator.userAgent.match(/firefox|fxios
|
|||
|
||||
export const MAX_STR_LEN = 1e5
|
||||
|
||||
const navigationStart: number | false =
|
||||
IN_BROWSER && (performance.timing.navigationStart || performance.timeOrigin)
|
||||
// performance.now() is buggy in some browsers
|
||||
// Buggy to use `performance.timeOrigin || performance.timing.navigationStart`
|
||||
// https://github.com/mdn/content/issues/4713
|
||||
// Maybe move to timer/ticker
|
||||
let timeOrigin: number = IN_BROWSER ? Date.now() - performance.now() : 0
|
||||
export function adjustTimeOrigin() {
|
||||
timeOrigin = Date.now() - performance.now()
|
||||
}
|
||||
export function getTimeOrigin() {
|
||||
return timeOrigin
|
||||
}
|
||||
export const now: () => number =
|
||||
IN_BROWSER && performance.now() && navigationStart
|
||||
? () => Math.round(performance.now() + navigationStart)
|
||||
IN_BROWSER && !!performance.now
|
||||
? () => Math.round(performance.now() + timeOrigin)
|
||||
: () => Date.now()
|
||||
|
||||
export const stars: (str: string) => string =
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue