fix(tracker): current time function fallback

This commit is contained in:
Alex Kaminskii 2022-09-12 16:34:00 +02:00
parent c7072220b5
commit 6e474d0953

View file

@ -1,6 +1,12 @@
export function timestamp(): number {
return Math.round(performance.now()) + performance.timing.navigationStart
}
export const IN_BROWSER = !(typeof window === 'undefined')
const navigationStart: number | false =
(IN_BROWSER && performance.timing.navigationStart) || performance.timeOrigin
// performance.now() is buggy in some browsers
export const timestamp: () => number =
IN_BROWSER && performance.now() && navigationStart
? () => Math.round(performance.now() + navigationStart)
: () => Date.now()
export const stars: (str: string) => string =
'repeat' in String.prototype
@ -16,8 +22,6 @@ export function isURL(s: string): boolean {
return s.startsWith('https://') || s.startsWith('http://')
}
export const IN_BROWSER = !(typeof window === 'undefined')
// TODO: JOIN IT WITH LOGGER somehow (use logging decorators?); Don't forget about index.js loggin when there is no logger instance.
export const DOCS_HOST = 'https://docs.openreplay.com'