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