Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(replay): stop the player reporting times the recording lacks (#90671)

posthog[bot]2b3f3197530a
diff --git a/frontend/src/scenes/session-recordings/player/controller/seekbarLogic.ts b/frontend/src/scenes/session-recordings/player/controller/seekbarLogic.ts
index 4412f4307f2e..d3102db72965 100644
--- a/frontend/src/scenes/session-recordings/player/controller/seekbarLogic.ts
+++ b/frontend/src/scenes/session-recordings/player/controller/seekbarLogic.ts
@@ -189,7 +189,10 @@ export const seekbarLogic = kea<seekbarLogicType>([
sessionPlayerData: import('../../../../types').SessionPlayerData
) => {
if (thumbLeftPos && slider && sessionPlayerData?.durationMs) {
- return ((thumbLeftPos + THUMB_OFFSET) / slider.offsetWidth) * sessionPlayerData.durationMs
+ // thumbLeftPos is not recomputed when the slider resizes, so the ratio can exceed 1
+ return (
+ clamp((thumbLeftPos + THUMB_OFFSET) / slider.offsetWidth, 0, 1) * sessionPlayerData.durationMs
+ )
}
return 0
},
diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts
index 115c9c69fc0e..5eb29496aa3f 100644
--- a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts
+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts
@@ -523,6 +523,32 @@ describe('sessionRecordingPlayerLogic', () => {
expect(logic.values.currentTimestamp).toBeGreaterThanOrEqual(start)
expect(logic.values.isBuffering).toBe(false)
})
+
+ it('re-seeks a deep link only when the linked time changes or the same URL is pushed again', async () => {
+ logic.unmount()
+ router.actions.push('/replay/2', { t: 5 })
+ logic = sessionRecordingPlayerLogic({
+ sessionRecordingId: '2',
+ playerKey: 'test',
+ blobV2PollingDisabled: true,
+ })
+ logic.mount()
+
+ await expectLogic(logic).toDispatchActions(['initializePlayerFromStart']).toFinishAllListeners()
+
+ const start = logic.values.sessionPlayerData.start?.valueOf() ?? 0
+ logic.actions.setCurrentTimestamp(start + 8000)
+
+ await expectLogic(logic, () => {
+ router.actions.push('/replay/2', { t: 5, inspectorSideBar: true })
+ }).toFinishAllListeners()
+ expect(logic.values.currentTimestamp).toBe(start + 8000)
+
+ await expectLogic(logic, () => {
+ router.actions.push('/replay/2', { t: 5, inspectorSideBar: true })
+ }).toFinishAllListeners()
+ expect(logic.values.currentTimestamp).toBe(start + 5000)
+ })
})
describe('seek renderability clamping', () => {
diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts
index 850d1025c19e..519b2adde139 100644
--- a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts
+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts
@@ -83,6 +83,7 @@ import {
GroupedAssetErrors,
ResourceErrorDetails,
} from './utils/asset-error-grouping'
+import { parseDeepLinkTime } from './utils/deep-link-time'
import { makeLogger, makeNoOpLogger } from './utils/player-logging'
import { deleteRecording } from './utils/playerUtils'
import { initialFrameState, resolveFrameTimestamp } from './utils/resolve-frame-timestamp'
@@ -1681,7 +1682,8 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
return 0
}
const time = currentTimestamp - sessionPlayerData.start.valueOf()
- return clamp(time, 0, sessionPlayerData.durationMs || Infinity)
+ // durationMs is 0 until the recording loads; the clock must read 0 then, not run unbounded
+ return clamp(time, 0, sessionPlayerData.durationMs)
},
],
@@ -2524,13 +2526,17 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
if (searchParams.fullscreen) {
actions.setIsFullScreen(true)
}
- const timestampParam = Number(searchParams.timestamp)
- const tParam = Number(searchParams.t) * 1000
- if (searchParams.timestamp && Number.isFinite(timestampParam)) {
- actions.seekToTimestamp(timestampParam, true)
- } else if (searchParams.t && Number.isFinite(tParam)) {
- actions.seekToTime(tParam)
+ const deepLinkTime = parseDeepLinkTime(searchParams.timestamp, searchParams.t)
+ if (deepLinkTime?.kind === 'timestamp') {
+ actions.seekToTimestamp(deepLinkTime.valueMs, true)
+ } else if (deepLinkTime?.kind === 'offset') {
+ actions.seekToTime(deepLinkTime.valueMs)
} else {
+ if (searchParams.timestamp || searchParams.t) {
+ lemonToast.warning(
+ "Couldn't read the time in this link, so the recording starts from the beginning."
+ )
+ }
actions.setSkipToFirstMatchingEvent(true)
}
}
@@ -3471,21 +3477,28 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
}),
urlToAction(({ actions, values }) => ({
- '*': (_, searchParams, hashParams) => {
+ '*': (_, searchParams, hashParams, { pathname, search, hash }, previousLocation) => {
const shouldPause = searchParams.pause || hashParams.pause
if (shouldPause && !values.pauseForced) {
actions.forcePause()
}
- if (searchParams.timestamp) {
- const desiredStartTime = Number(searchParams.timestamp)
- if (!isNaN(desiredStartTime)) {
- actions.seekToTimestamp(desiredStartTime, true)
- }
- } else if (searchParams.t) {
- const desiredStartTime = Number(searchParams.t) * 1000
- if (!isNaN(desiredStartTime)) {
- actions.seekToTime(desiredStartTime)
- }
+ // Unrelated param changes (inspector toggle, sidebar tab) keep `t`. Seek only when the
+ // linked time changed, or the same URL was pushed again so a repeat click still seeks.
+ const linkedTimeUnchanged =
+ previousLocation.searchParams.timestamp === searchParams.timestamp &&
+ previousLocation.searchParams.t === searchParams.t
+ const sameUrl =
+ previousLocation.pathname === pathname &&
+ previousLocation.search === search &&
+ previousLocation.hash === hash
+ if (linkedTimeUnchanged && !sameUrl) {
+ return
+ }
+ const deepLinkTime = parseDeepLinkTime(searchParams.timestamp, searchParams.t)
+ if (deepLinkTime?.kind === 'timestamp') {
+ actions.seekToTimestamp(deepLinkTime.valueMs, true)
+ } else if (deepLinkTime?.kind === 'offset') {
+ actions.seekToTime(deepLinkTime.valueMs)
}
},
})),
diff --git a/frontend/src/scenes/session-recordings/player/utils/deep-link-time.test.ts b/frontend/src/scenes/session-recordings/player/utils/deep-link-time.test.ts
new file mode 100644
index 000000000000..07efcc9c815a
--- /dev/null
+++ b/frontend/src/scenes/session-recordings/player/utils/deep-link-time.test.ts
@@ -0,0 +1,56 @@
+import { DeepLinkTime, parseDeepLinkTime } from './deep-link-time'
+
+describe('parseDeepLinkTime', () => {
+ // 2026-09-01T10:00:30.000Z
+ const isoDate = '2026-09-01T10:00:30.000Z'
+ const isoMs = Date.parse(isoDate)
+
+ const cases: {
+ name: string
+ timestamp?: string | number
+ t?: string | number
+ expected: DeepLinkTime | null
+ }[] = [
+ { name: 'no params', timestamp: undefined, t: undefined, expected: null },
+ {
+ // kea-router coerces a numeric query param to a number, so `t.trim()` must not be assumed.
+ name: 'numeric t is a seconds offset',
+ timestamp: undefined,
+ t: 30,
+ expected: { kind: 'offset', valueMs: 30000 },
+ },
+ {
+ name: 'numeric timestamp is absolute unix ms',
+ timestamp: 1756720830000,
+ t: undefined,
+ expected: { kind: 'timestamp', valueMs: 1756720830000 },
+ },
+ {
+ // Regression: the Slack destination docs emit an ISO date in `t`, which used to
+ // yield NaN and start the recording from the beginning (issue #90565).
+ name: 'ISO date in t is an absolute timestamp',
+ timestamp: undefined,
+ t: isoDate,
+ expected: { kind: 'timestamp', valueMs: isoMs },
+ },
+ {
+ name: 'ISO date in timestamp is an absolute timestamp',
+ timestamp: isoDate,
+ t: undefined,
+ expected: { kind: 'timestamp', valueMs: isoMs },
+ },
+ { name: 'unparseable t', timestamp: undefined, t: 'not-a-time', expected: null },
+ { name: 'zone-less datetime in t', timestamp: undefined, t: '2026-09-01T10:00:30', expected: null },
+ { name: 'date-only t', timestamp: undefined, t: '2026-09-01', expected: null },
+ {
+ name: 'timestamp wins over t when both are present',
+ timestamp: 1756720830000,
+ t: 30,
+ expected: { kind: 'timestamp', valueMs: 1756720830000 },
+ },
+ ]
+
+ it.each(cases)('$name', ({ timestamp, t, expected }) => {
+ expect(parseDeepLinkTime(timestamp, t)).toEqual(expected)
+ })
+})
diff --git a/frontend/src/scenes/session-recordings/player/utils/deep-link-time.ts b/frontend/src/scenes/session-recordings/player/utils/deep-link-time.ts
new file mode 100644
index 000000000000..393a761885e7
--- /dev/null
+++ b/frontend/src/scenes/session-recordings/player/utils/deep-link-time.ts
@@ -0,0 +1,59 @@
+import { dayjs } from 'lib/dayjs'
+
+export interface DeepLinkTime {
+ // 'timestamp' is an absolute point in the recording (unix ms).
+ // 'offset' is a distance from the start of the recording (ms).
+ kind: 'timestamp' | 'offset'
+ valueMs: number
+}
+
+// `timestamp` is absolute (unix ms or ISO date). `t` is a seconds offset, but the CDP destination
+// docs emit an ISO date in `t`, so `t` accepts a date too. kea-router coerces numeric params to numbers.
+// Returns null when a param is present but unparseable.
+export function parseDeepLinkTime(
+ timestampParam: string | number | undefined,
+ tParam: string | number | undefined
+): DeepLinkTime | null {
+ if (timestampParam) {
+ const absolute = parseAbsoluteMs(timestampParam)
+ if (absolute !== null) {
+ return { kind: 'timestamp', valueMs: absolute }
+ }
+ }
+ if (tParam) {
+ const seconds = toFiniteNumber(tParam)
+ if (seconds !== null) {
+ return { kind: 'offset', valueMs: seconds * 1000 }
+ }
+ const absolute = parseDate(tParam)
+ if (absolute !== null) {
+ return { kind: 'timestamp', valueMs: absolute }
+ }
+ }
+ return null
+}
+
+function parseAbsoluteMs(value: string | number): number | null {
+ // A bare number is a unix-ms timestamp; anything else must be a parseable date.
+ return toFiniteNumber(value) ?? parseDate(value)
+}
+
+function toFiniteNumber(value: string | number): number | null {
+ if (typeof value === 'string' && value.trim() === '') {
+ return null
+ }
+ const asNumber = Number(value)
+ return Number.isFinite(asNumber) ? asNumber : null
+}
+
+// Zone-less and partial dates parse in the viewer's local zone, so the same link would land on
+// different frames for different viewers. Require a full ISO datetime with an explicit zone.
+const ISO_DATETIME_WITH_ZONE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})$/
+
+function parseDate(value: string | number): number | null {
+ if (typeof value !== 'string' || !ISO_DATETIME_WITH_ZONE.test(value)) {
+ return null
+ }
+ const parsed = dayjs(value)
+ return parsed.isValid() ? parsed.valueOf() : null
+}