: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(replay): warn when a later window has no full snapshot (#98062)
posthog[bot]92a89697238a
diff --git a/frontend/src/scenes/session-recordings/player/PurePlayer.tsx b/frontend/src/scenes/session-recordings/player/PurePlayer.tsxindex 14be5902ad0f..d583a250e9cb 100644--- a/frontend/src/scenes/session-recordings/player/PurePlayer.tsx+++ b/frontend/src/scenes/session-recordings/player/PurePlayer.tsx@@ -95,7 +95,10 @@ export function PurePlayer({ noMeta = false, noBorder = false }: PurePlayerPropsendReached,hasLateFullSnapshot,leadingUnplayableMs,+ hasUnrenderableWindow,+ unrenderableWindowMs,hasOversizedMutations,+ fullyLoaded,} = useValues(sessionRecordingPlayerLogic)const {@@ -170,6 +173,31 @@ export function PurePlayer({ noMeta = false, noBorder = false }: PurePlayerProps[hasLateFullSnapshot])+ // An unrenderable span keeps growing while sources arrive, so the duration is only final once+ // the recording is fully loaded. `fullyLoaded` also drops back while the inspector fetches full+ // event data, so remember which recording was reported to keep this one event per view.+ const reportedUnrenderableWindowFor = useRef<string | null>(null)++ useEffect(+ () => {+ if (+ !hasUnrenderableWindow ||+ !fullyLoaded ||+ reportedUnrenderableWindowFor.current === sessionRecordingId+ ) {+ return+ }+ reportedUnrenderableWindowFor.current = sessionRecordingId+ posthog.capture('session loaded with unrenderable window', {+ viewedSessionRecording: sessionRecordingId,+ recordingStartTime: sessionPlayerData?.start,+ unrenderableWindowMs,+ })+ },+ // eslint-disable-next-line react-hooks/exhaustive-deps+ [hasUnrenderableWindow, fullyLoaded, sessionRecordingId]+ )+// Track if the recording has ended to be able to reliably get it from the BE and stop the recordinguseEffect(() => {if (typeof window !== 'undefined') {@@ -357,7 +385,7 @@ export function PurePlayer({ noMeta = false, noBorder = false }: PurePlayerProps) : (<div className="flex w-full h-full"><div className="flex flex-col flex-1 w-full relative">- {hasLateFullSnapshot && !hidePlayerElements ? (+ {(hasLateFullSnapshot || hasUnrenderableWindow) && !hidePlayerElements ? (<LemonBannertype="warning"// The player column over-commits its height, so a flexible banner gets@@ -365,10 +393,26 @@ export function PurePlayer({ noMeta = false, noBorder = false }: PurePlayerPropsclassName="shrink-0"dismissKey={`late-full-snapshot-${sessionRecordingId}`}>- The first{' '}- {humanFriendlyDuration(leadingUnplayableMs / 1000, { maxUnits: 2 })} of this- recording can't be played. The first screen snapshot arrived late, so- playback starts at the first frame we can render.{' '}+ {hasLateFullSnapshot ? (+ <>+ The first{' '}+ {humanFriendlyDuration(leadingUnplayableMs / 1000, {+ maxUnits: 2,+ })}{' '}+ of this recording can't be played. The first screen snapshot arrived+ late, so playback starts at the first frame we can render.{' '}+ </>+ ) : null}+ {hasUnrenderableWindow ? (+ <>+ {humanFriendlyDuration(unrenderableWindowMs / 1000, {+ maxUnits: 2,+ })}{' '}+ of this recording can't be played. A browser window opened without+ sending a screen snapshot, so the player stays blank while that+ window is on screen.{' '}+ </>+ ) : null}<Link to="https://posthog.com/docs/session-replay/troubleshooting">Learn more</Link>diff --git a/frontend/src/scenes/session-recordings/player/controller/Seekbar.tsx b/frontend/src/scenes/session-recordings/player/controller/Seekbar.tsxindex 37342761076c..b07936fbe4a6 100644--- a/frontend/src/scenes/session-recordings/player/controller/Seekbar.tsx+++ b/frontend/src/scenes/session-recordings/player/controller/Seekbar.tsx@@ -77,8 +77,15 @@ const SeekbarSources = React.memo(function SeekbarSourcesRaw({})export function Seekbar(): JSX.Element {- const { sessionRecordingId, logicProps, hasSnapshots, hasLateFullSnapshot, leadingUnplayableMs } =- useValues(sessionRecordingPlayerLogic)+ const {+ sessionRecordingId,+ logicProps,+ hasSnapshots,+ hasLateFullSnapshot,+ leadingUnplayableMs,+ hasUnrenderableWindow,+ unrenderableWindowSpans,+ } = useValues(sessionRecordingPlayerLogic)const { seekToTime } = useActions(sessionRecordingPlayerLogic)const { seekbarItems } = useValues(playerInspectorLogic(logicProps))const { endTimeMs, thumbLeftPos, isScrubbing } = useValues(seekbarLogic(logicProps))@@ -104,6 +111,8 @@ export function Seekbar(): JSX.Element {const allowPreviewScrubbing = useFeatureFlag('SEEKBAR_PREVIEW_SCRUBBING')+ const recordingStartMs = sessionPlayerData.start?.valueOf() ?? 0+return (<div className="flex flex-col items-end mx-4 mt-2 h-8" data-attr="rrweb-controller"><PlayerSeekbarTicks@@ -127,7 +136,7 @@ export function Seekbar(): JSX.Element {><SeekbarSourcessourceLoadingStates={effectiveSourceLoadingStates}- recordingStartMs={sessionPlayerData.start?.valueOf() ?? 0}+ recordingStartMs={recordingStartMs}recordingEndMs={sessionPlayerData.end?.valueOf() ?? 0}/><ObservationSeekbarMarks endTimeMs={endTimeMs} onSeek={seekToTime} />@@ -145,6 +154,32 @@ export function Seekbar(): JSX.Element {/></Tooltip>) : null}+ {hasUnrenderableWindow && endTimeMs > 0+ ? unrenderableWindowSpans.map((span) => (+ <Tooltip+ key={span.startTimestamp}+ title={`${humanFriendlyDuration((span.endTimestamp - span.startTimestamp) / 1000, {+ maxUnits: 2,+ })} can't be played. A browser window opened without sending a screen snapshot.`}+ placement="top"+ >+ <div+ className="PlayerSeekbar__unplayable"+ // eslint-disable-next-line react/forbid-dom-props+ style={{+ left: `${Math.min(+ 100,+ ((span.startTimestamp - recordingStartMs) / endTimeMs) * 100+ )}%`,+ width: `${Math.min(+ 100,+ ((span.endTimestamp - span.startTimestamp) / endTimeMs) * 100+ )}%`,+ }}+ />+ </Tooltip>+ ))+ : null}<divclassName="PlayerSeekbar__played"// eslint-disable-next-line react/forbid-dom-propsdiff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.tsindex 5eb29496aa3f..2d71c838470c 100644--- a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts@@ -588,9 +588,26 @@ describe('sessionRecordingPlayerLogic', () => {const w2inc = (timestamp: number): RecordingSnapshot =>makeSnapshot(timestamp, EventType.IncrementalSnapshot, 2)const w2fs = (timestamp: number): RecordingSnapshot => makeSnapshot(timestamp, EventType.FullSnapshot, 2)+ const w2move = (timestamp: number): RecordingSnapshot =>+ makeSnapshot(timestamp, EventType.IncrementalSnapshot, 2, { source: IncrementalSource.MouseMove })+ // a continuously active second window, the shape that animates a cursor over a blank document+ const w2moves = (fromTimestamp: number, toTimestamp: number): RecordingSnapshot[] => {+ const moves: RecordingSnapshot[] = []+ for (let timestamp = fromTimestamp; timestamp <= toTimestamp; timestamp += 5000) {+ moves.push(w2move(timestamp))+ }+ return moves+ }// an ACTIVE first-window event, so the segmenter splits a real window-1 segment before itconst w1move = (timestamp: number): RecordingSnapshot =>makeSnapshot(timestamp, EventType.IncrementalSnapshot, 1, { source: IncrementalSource.MouseMove })+ const w1moves = (fromTimestamp: number, toTimestamp: number): RecordingSnapshot[] => {+ const moves: RecordingSnapshot[] = []+ for (let timestamp = fromTimestamp; timestamp <= toTimestamp; timestamp += 5000) {+ moves.push(w1move(timestamp))+ }+ return moves+ }// one-minute-per-source blob fixtures matching the store test helpersconst makeBlobSources = (@@ -1010,6 +1027,102 @@ describe('sessionRecordingPlayerLogic', () => {})+ it.each([+ {+ // the reported symptom: window 2 opens and only sends mouse moves, so it animates a+ // cursor over a document rrweb never built+ description: 'reports the span of a later window that never sent a full snapshot',+ secondSourceSnapshots: [w1move(START + 61000), ...w2moves(START + 62000, START + 122000)],+ expectedUnrenderableWindowMs: 60000,+ expectedHasUnrenderable: true,+ },+ {+ description: 'stops the span at the full snapshot a later window eventually sends',+ secondSourceSnapshots: [+ w1move(START + 61000),+ ...w2moves(START + 62000, START + 117000),+ w2fs(START + 122000),+ w2inc(START + 123000),+ ],+ expectedUnrenderableWindowMs: 60000,+ expectedHasUnrenderable: true,+ },+ {+ description: 'reports nothing when a later window opens with its own full snapshot',+ secondSourceSnapshots: [+ w1move(START + 61000),+ w2fs(START + 62000),+ ...w2moves(START + 67000, START + 122000),+ ],+ expectedUnrenderableWindowMs: 0,+ expectedHasUnrenderable: false,+ },+ {+ // a viewer moving between tabs interleaves the windows, and window 1 still plays+ description: 'leaves out the window that plays normally between two spans of a damaged one',+ secondSourceSnapshots: [+ w1move(START + 61000),+ ...w2moves(START + 62000, START + 82000),+ w1move(START + 87000),+ w1move(START + 92000),+ ...w2moves(START + 97000, START + 117000),+ ],+ expectedUnrenderableWindowMs: 50000,+ expectedHasUnrenderable: true,+ },+ {+ description: 'does not flag a later window whose span is only a backdated idle event',+ secondSourceSnapshots: [+ w1move(START + 61000),+ makeSnapshot(START + 62000, EventType.Custom, 2, { tag: 'sessionIdle', payload: {} }),+ ],+ expectedUnrenderableWindowMs: 0,+ expectedHasUnrenderable: false,+ },+ ])('$description', ({ secondSourceSnapshots, expectedUnrenderableWindowMs, expectedHasUnrenderable }) => {+ seedRecording([fs(START), inc(START + 1000)], secondSourceSnapshots)++ expect(logic.values.unrenderableWindowMs).toBe(expectedUnrenderableWindowMs)+ expect(logic.values.hasUnrenderableWindow).toBe(expectedHasUnrenderable)+ // the leading span selector still owns the recording's first window+ expect(logic.values.leadingUnplayableMs).toBe(0)+ })++ it('reports the first window when it goes blank again after the leading span', () => {+ // window 1 never sends a full snapshot, so the leading span recovers on window 2's+ // instead, and playback back in window 1 has nothing to clamp to+ seedRecording(+ [w1move(START), w2fs(START + 5000), ...w2moves(START + 10000, START + 55000)],+ w1moves(START + 61000, START + 91000)+ )++ expect(logic.values.leadingUnplayableMs).toBe(5000)+ expect(logic.values.hasLateFullSnapshot).toBe(false)+ expect(logic.values.unrenderableWindowSpans).toEqual([+ { startTimestamp: START + 61000, endTimestamp: START + 91000 },+ ])+ expect(logic.values.hasUnrenderableWindow).toBe(true)+ })++ it('leaves a recording with no full snapshot at all to the unplayable takeover', () => {+ // the full-screen error replaces the player here, so a banner behind it would count+ // recordings this warning never helped+ seedRecording(+ [w1move(START), w1move(START + 5000)],+ [w1move(START + 61000), ...w2moves(START + 66000, START + 126000)]+ )++ expect(logic.values.unrenderableWindowSpans).toEqual([])+ expect(logic.values.hasUnrenderableWindow).toBe(false)+ })++ it('holds the unrenderable-window warning back while earlier data is still loading', () => {+ seedRecording(null, [w1move(START + 61000), ...w2moves(START + 62000, START + 122000)])++ expect(logic.values.unrenderableWindowSpans).toEqual([])+ expect(logic.values.hasUnrenderableWindow).toBe(false)+ })+// Builds a stand-in replayer whose iframe document has (or lacks) a <head>. rrweb throws// synchronously when it rebuilds a full snapshot on a document without a head, which is the// WebKit failure this recovery path guards against.diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.tsindex 65c52527046a..efe0b4af9ca7 100644--- a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts@@ -185,6 +185,12 @@ const LATE_FULL_SNAPSHOT_THRESHOLD_MS = 20000// Safety-net cadence for re-running syncPlayerState while buffering, since neither backed-off source polling nor the non-reactive wall-clock grace check re-triggers verdict re-evaluation on its own.const BUFFERING_REEVALUATION_INTERVAL_MS = 120000+// a stretch of the recording playback cannot render+export interface UnplayableSpan {+ startTimestamp: number+ endTimestamp: number+}+export type SeekRenderability =// a FullSnapshot exists at or before the timestamp for its window| { kind: 'renderable' }@@ -607,6 +613,7 @@ export interface sessionRecordingPlayerLogicValues {fromRRWebPlayerTime: (time?: number | undefined) => number | undefinedhasLateFullSnapshot: booleanhasSnapshots: boolean+ hasUnrenderableWindow: booleanhoverModeIsEnabled: booleanisBuffering: booleanisCommenting: boolean@@ -655,6 +662,8 @@ export interface sessionRecordingPlayerLogicValues {timestampMatchesPrevious: number}toRRWebPlayerTime: (timestamp: number) => number | undefined+ unrenderableWindowMs: number+ unrenderableWindowSpans: UnplayableSpan[]wasMarkedViewed: boolean}@@ -1100,6 +1109,13 @@ export interface sessionRecordingPlayerLogicMeta {seekRenderability: (timestamp: number) => SeekRenderability) => numberhasLateFullSnapshot: (leadingUnplayableMs: number) => boolean+ unrenderableWindowSpans: (+ sessionPlayerData: SessionPlayerData,+ seekRenderability: (timestamp: number) => SeekRenderability,+ leadingUnplayableMs: number+ ) => UnplayableSpan[]+ unrenderableWindowMs: (unrenderableWindowSpans: UnplayableSpan[]) => number+ hasUnrenderableWindow: (unrenderableWindowMs: number) => booleanisWaitingForIngestion: (seekRenderability: (timestamp: number) => SeekRenderability,currentTimestamp: number | undefined@@ -1910,6 +1926,130 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>((leadingUnplayableMs: number): boolean => leadingUnplayableMs > LATE_FULL_SNAPSHOT_THRESHOLD_MS,],+ // Spans of a window that opened without ever sending its initial DOM. rrweb draws its own+ // cursor from the incremental mouse events, so the viewer sees a pointer moving over a blank+ // document. `leadingUnplayableMs` owns the stretch the player clamps past, so these are the+ // spans after it, where nothing clamps and nothing explains the blank frame.+ // One check per window is enough: once a window has a FullSnapshot, rrweb keeps its DOM for+ // every later segment of that window.+ unrenderableWindowSpans: [+ (s) => [s.sessionPlayerData, s.seekRenderability, s.leadingUnplayableMs],+ (+ sessionPlayerData: SessionPlayerData,+ seekRenderability: (timestamp: number) => SeekRenderability,+ leadingUnplayableMs: number+ ): UnplayableSpan[] => {+ // A recording where no window ever rendered belongs to the unplayable takeover, which+ // replaces the player instead of warning over it. Leaving it out also keeps this+ // countable against `recording_window_missing_full_snapshot`, which skips the same+ // recordings.+ const someWindowHasFullSnapshot = Object.values(sessionPlayerData.snapshotsByWindowId).some((events) =>+ events.some((event) => event.type === EventType.FullSnapshot)+ )+ if (!someWindowHasFullSnapshot) {+ return []+ }++ const lastEndByWindow = new Map<number, number>()+ for (const segment of sessionPlayerData.segments) {+ if (segment.kind === 'window' && segment.windowId !== undefined) {+ lastEndByWindow.set(segment.windowId, segment.endTimestamp)+ }+ }++ const firstWindowSegment = sessionPlayerData.segments.find((segment) => segment.kind === 'window')+ // Where the leading span hands over. Its recovery point can be another window's+ // FullSnapshot, so the first window can go blank again after it and still needs a span.+ const leadingRecoveryTimestamp = (sessionPlayerData.start?.valueOf() ?? 0) + leadingUnplayableMs+ const spans: UnplayableSpan[] = []+ const checkedWindows = new Set<number>()+ for (const segment of sessionPlayerData.segments) {+ if (segment.kind !== 'window' || segment.windowId === undefined) {+ continue+ }+ const windowId = segment.windowId+ if (+ windowId === firstWindowSegment?.windowId &&+ segment.startTimestamp < leadingRecoveryTimestamp+ ) {+ continue+ }+ if (checkedWindows.has(windowId)) {+ continue+ }+ if (segment.endTimestamp <= segment.startTimestamp) {+ // a zero-length segment shows nothing, and its start is shared with the preceding gap+ continue+ }+ checkedWindows.add(windowId)+ // Probe one millisecond in: a segment's start is also the preceding gap's end, and a gap+ // renders from whatever the last window left on screen. Both verdicts mean no FullSnapshot+ // renders this position and everything before it has loaded, so the gap in the data is+ // definitive rather than still arriving.+ const verdict = seekRenderability(segment.startTimestamp + 1)+ if (verdict.kind !== 'clampToFullSnapshot' && verdict.kind !== 'unplayable') {+ continue+ }+ const windowEvents = sessionPlayerData.snapshotsByWindowId[windowId] ?? []+ const recovery = windowEvents.find(+ (event) => event.type === EventType.FullSnapshot && event.timestamp >= segment.startTimestamp+ )+ const endTimestamp = recovery?.timestamp ?? lastEndByWindow.get(windowId) ?? segment.endTimestamp+ // A window that only carries Custom events over the span (e.g. a backdated+ // `sessionIdle`) has no content to lose, so it renders nothing either way.+ const hasLostContent = windowEvents.some(+ (event) =>+ event.timestamp >= segment.startTimestamp &&+ event.timestamp < endTimestamp &&+ event.type !== EventType.Custom+ )+ if (!hasLostContent) {+ continue+ }+ // Windows interleave when a viewer moves between tabs, so this range can hold+ // another window's segments, which play normally. Only the damaged window's own+ // segments stay blank, together with the gaps that hold it on screen.+ let openSpanIndex = -1+ for (const blankSegment of sessionPlayerData.segments) {+ if (blankSegment.startTimestamp >= endTimestamp) {+ break+ }+ if (blankSegment.endTimestamp <= segment.startTimestamp) {+ continue+ }+ if (blankSegment.windowId !== windowId) {+ continue+ }+ const spanStart = Math.max(blankSegment.startTimestamp, segment.startTimestamp)+ const spanEnd = Math.min(blankSegment.endTimestamp, endTimestamp)+ if (spanEnd <= spanStart) {+ continue+ }+ // consecutive segments of the damaged window read as one blank stretch+ if (openSpanIndex >= 0 && spans[openSpanIndex].endTimestamp === spanStart) {+ spans[openSpanIndex].endTimestamp = spanEnd+ } else {+ openSpanIndex = spans.length+ spans.push({ startTimestamp: spanStart, endTimestamp: spanEnd })+ }+ }+ }+ return spans+ },+ { resultEqualityCheck: objectsEqual },+ ],++ unrenderableWindowMs: [+ (s) => [s.unrenderableWindowSpans],+ (unrenderableWindowSpans: UnplayableSpan[]): number =>+ unrenderableWindowSpans.reduce((total, span) => total + span.endTimestamp - span.startTimestamp, 0),+ ],++ hasUnrenderableWindow: [+ (s) => [s.unrenderableWindowMs],+ (unrenderableWindowMs: number): boolean => unrenderableWindowMs > LATE_FULL_SNAPSHOT_THRESHOLD_MS,+ ],+// True while the player is buffering on a position whose FullSnapshot hasn't been// ingested yet but still might be (within the grace period). Lets the overlay show a// "still processing" message instead of the generic "Buffering…".diff --git a/products/replay/frontend/e2e/player.spec.ts b/products/replay/frontend/e2e/player.spec.tsindex ccc4db9637ae..40892116fa24 100644--- a/products/replay/frontend/e2e/player.spec.ts+++ b/products/replay/frontend/e2e/player.spec.ts@@ -53,6 +53,21 @@ function stripFullSnapshots(line: string): string {})}+// A window that opened without ever sending its initial DOM: the full snapshot is stripped and the+// remaining events are spread over `spanMs`, so the blank span clears the player's warning threshold.+function windowWithoutFullSnapshot(line: string, startOffsetMs: number, spanMs: number): string {+ const parsed = JSON.parse(line)+ const events = parsed.data.filter((e: { type: number }) => e.type !== 2)+ const stepMs = spanMs / (events.length - 1)+ return JSON.stringify({+ window_id: parsed.window_id,+ data: events.map((e: { timestamp: number }, index: number) => ({+ ...e,+ timestamp: BASE_TS + startOffsetMs + Math.round(index * stepMs),+ })),+ })+}+function lastEventTimestamp(line: string): number {const parsed = JSON.parse(line)return parsed.data[parsed.data.length - 1].timestamp@@ -80,6 +95,16 @@ const RECORDINGS: Record<string, MockRecording> = {meta: metaVariant(`${SESSION_ID}-late`, 6000),blobs: [lateFullSnapshotAsJSONLines(BASE_TS, 5000).trim()],},+ // A second window opens without a full snapshot, then the first window comes back. rrweb draws+ // its own cursor over the 40s it cannot build a document for, and playback runs straight through.+ [`${SESSION_ID}-windownofs`]: {+ meta: metaVariant(`${SESSION_ID}-windownofs`, 56000),+ blobs: [+ windowOneJSONL,+ windowWithoutFullSnapshot(windowTwoJSONL, 8000, 40000),+ shiftJSONLine(windowOneJSONL, 50000),+ ],+ },// No full snapshot at all — the recording can never render.[`${SESSION_ID}-nofs`]: {meta: metaVariant(`${SESSION_ID}-nofs`, lastEventTimestamp(windowOneJSONL) - BASE_TS),@@ -309,6 +334,14 @@ test.describe('Session replay player', () => {await expect(bufferingIndicator(page)).not.toBeVisible()})+ test('warns about the part a window without a full snapshot cannot render', async ({ page }) => {+ await page.goto(`/replay/${SESSION_ID}-windownofs?pause=true&t=0`)+ await expect(playerFrame(page)).toBeVisible({ timeout: 30000 })+ await expect(page.getByText("of this recording can't be played")).toBeVisible({ timeout: 30000 })+ await revealControls(page)+ await expect(page.locator('.PlayerSeekbar__unplayable')).toBeVisible()+ })+test('buffers while a source is still loading and recovers when it arrives', async ({ page }) => {await page.goto(`/replay/${SESSION_ID}-slow?pause=true&t=9`)// The target position lives in the delayed second source, so the player must buffer first...