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.

feat(replay): always mount the player in its own frame document (#100609)

Tom Piccirelloae3ec6f805d4
diff --git a/frontend/src/exporter/scenes/ExporterRecordingScene.tsx b/frontend/src/exporter/scenes/ExporterRecordingScene.tsx
index 21a2cbf35bde..cb1cbe0f9034 100644
--- a/frontend/src/exporter/scenes/ExporterRecordingScene.tsx
+++ b/frontend/src/exporter/scenes/ExporterRecordingScene.tsx
@@ -23,7 +23,8 @@ export default function ExporterRecordingScene({
playerKey="exporter"
sessionRecordingId={recording.id}
mode={mode ?? SessionRecordingPlayerMode.Sharing}
- autoPlay={autoplay ?? false}
+ // A shared recording link carries no autoplay field, and those pages play on open.
+ autoPlay={autoplay ?? true}
withSidebar={showInspector ?? false}
noBorder={noBorder ?? false}
accessToken={exportToken}
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 1a9916d1d117..80daf98f808a 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -220,7 +220,6 @@ export const FEATURE_FLAGS = {
QUERY_RUNNING_TIME: 'query_running_time', // owner: #team-analytics-platform
REPLAY_HOGQL_FILTERS: 'replay-hogql-filters', // owner: @pauldambra #team-replay
REPLAY_OVERSIZED_RECORDING_GATE: 'replay-oversized-recording-gate', // owner: #team-replay
- REPLAY_PLAYER_OWN_DOCUMENT: 'replay-player-own-document', // owner: #team-replay
REPLAY_PLAYER_PERSON_SESSIONS_TAB: 'replay-player-person-sessions-tab', // owner: @ksvat #team-replay
REPLAY_SETTINGS_HELP: 'replay-settings-help', // owner: @veryayskiy #team-replay
SCOUTS_MODEL_CONFIG: 'scouts-model-config', // owner: #team-self-driving, gates the per-scout model pin in the inbox scout settings (also checked server-side)
diff --git a/frontend/src/scenes/notebooks/Notebook/NotebookWidgetViews.stories.tsx b/frontend/src/scenes/notebooks/Notebook/NotebookWidgetViews.stories.tsx
index 11612627fc21..76993f6f526a 100644
--- a/frontend/src/scenes/notebooks/Notebook/NotebookWidgetViews.stories.tsx
+++ b/frontend/src/scenes/notebooks/Notebook/NotebookWidgetViews.stories.tsx
@@ -534,9 +534,29 @@ export const InsightViews: Story = {
},
}
export const RecordingViews: Story = {
+ decorators: [
+ (Story) => {
+ // Skipping inactivity moves the playhead on its own, and this recording resizes its
+ // viewport part way through, so the snapshot caught the page at whichever size the skip
+ // had reached. The setting is persisted, so the story pins it before the player mounts.
+ localStorage.setItem(
+ 'scenes.session-recordings.player.playerSettingsLogic.skipInactivitySetting',
+ JSON.stringify(false)
+ )
+ return <Story />
+ },
+ ],
parameters: {
- pageUrl: urls.notebook('recording-widget-views'),
- testOptions: { waitForLoadersToDisappear: false },
+ // `t=0` pins the player to the first frame. Without it the player picks its own start, which
+ // depends on how much of the recording has loaded, and the recording resizes its viewport
+ // five seconds in, so the snapshot caught the page at two different sizes.
+ pageUrl: `${urls.notebook('recording-widget-views')}?t=0`,
+ testOptions: {
+ waitForLoadersToDisappear: false,
+ // The player mounts rrweb inside its own frame document. Without this wait the snapshot is
+ // taken as soon as the notebook renders, so it catches whichever frame the replay reached.
+ waitForSelector: 'iframe.PlayerFrame__document >>> .PlayerFrame__content .replayer-wrapper iframe',
+ },
},
}
export const RecordingPlaylistViews: Story = {
diff --git a/frontend/src/scenes/session-recordings/SessionsRecordings-activity-modal.stories.tsx b/frontend/src/scenes/session-recordings/SessionsRecordings-activity-modal.stories.tsx
index ff724837aff4..d49f3fe725f4 100644
--- a/frontend/src/scenes/session-recordings/SessionsRecordings-activity-modal.stories.tsx
+++ b/frontend/src/scenes/session-recordings/SessionsRecordings-activity-modal.stories.tsx
@@ -79,7 +79,7 @@ export const EventExplorerWithModal: Story = {
},
parameters: {
testOptions: {
- waitForSelector: '.PlayerFrame__content .replayer-wrapper iframe',
+ waitForSelector: 'iframe.PlayerFrame__document >>> .PlayerFrame__content .replayer-wrapper iframe',
},
},
tags: ['test-skip'],
diff --git a/frontend/src/scenes/session-recordings/SessionsRecordings-group-scene.stories.tsx b/frontend/src/scenes/session-recordings/SessionsRecordings-group-scene.stories.tsx
index b930e11617d0..200b03e27533 100644
--- a/frontend/src/scenes/session-recordings/SessionsRecordings-group-scene.stories.tsx
+++ b/frontend/src/scenes/session-recordings/SessionsRecordings-group-scene.stories.tsx
@@ -237,7 +237,7 @@ export const GroupRecordingTabMultipleAndFound: Story = {
},
parameters: {
testOptions: {
- waitForSelector: '.PlayerFrame__content .replayer-wrapper iframe',
+ waitForSelector: 'iframe.PlayerFrame__document >>> .PlayerFrame__content .replayer-wrapper iframe',
},
},
tags: ['test-skip'],
@@ -291,7 +291,7 @@ export const GroupRecordingTabWide: Story = {
parameters: {
testOptions: {
viewport: { width: 1300, height: 720 },
- waitForSelector: '.PlayerFrame__content .replayer-wrapper iframe',
+ waitForSelector: 'iframe.PlayerFrame__document >>> .PlayerFrame__content .replayer-wrapper iframe',
},
},
tags: ['test-skip'],
@@ -345,7 +345,7 @@ export const GroupRecordingTabNarrow: Story = {
parameters: {
testOptions: {
viewport: { width: 568, height: 1024 },
- waitForSelector: '.PlayerFrame__content .replayer-wrapper iframe',
+ waitForSelector: 'iframe.PlayerFrame__document >>> .PlayerFrame__content .replayer-wrapper iframe',
},
},
tags: ['test-skip'],
@@ -400,7 +400,7 @@ export const GroupEventsTabWithModal: Story = {
},
parameters: {
testOptions: {
- waitForSelector: '.PlayerFrame__content .replayer-wrapper iframe',
+ waitForSelector: 'iframe.PlayerFrame__document >>> .PlayerFrame__content .replayer-wrapper iframe',
},
},
tags: ['test-skip'],
diff --git a/frontend/src/scenes/session-recordings/SessionsRecordings-person-scene.stories.tsx b/frontend/src/scenes/session-recordings/SessionsRecordings-person-scene.stories.tsx
index 34515e872321..0c0c78d1b5b3 100644
--- a/frontend/src/scenes/session-recordings/SessionsRecordings-person-scene.stories.tsx
+++ b/frontend/src/scenes/session-recordings/SessionsRecordings-person-scene.stories.tsx
@@ -224,7 +224,7 @@ export const PersonRecordingTabMultipleAndFound: Story = {
},
parameters: {
testOptions: {
- waitForSelector: '.PlayerFrame__content .replayer-wrapper iframe',
+ waitForSelector: 'iframe.PlayerFrame__document >>> .PlayerFrame__content .replayer-wrapper iframe',
},
},
tags: ['test-skip'],
@@ -273,7 +273,7 @@ export const PersonRecordingTabWide: Story = {
parameters: {
testOptions: {
viewport: { width: 1300, height: 720 },
- waitForSelector: '.PlayerFrame__content .replayer-wrapper iframe',
+ waitForSelector: 'iframe.PlayerFrame__document >>> .PlayerFrame__content .replayer-wrapper iframe',
},
},
tags: ['test-skip'],
@@ -322,7 +322,7 @@ export const PersonRecordingTabNarrow: Story = {
parameters: {
testOptions: {
viewport: { width: 568, height: 1024 },
- waitForSelector: '.PlayerFrame__content .replayer-wrapper iframe',
+ waitForSelector: 'iframe.PlayerFrame__document >>> .PlayerFrame__content .replayer-wrapper iframe',
},
},
tags: ['test-skip'],
@@ -370,7 +370,7 @@ export const PersonEventsTabWithModal: Story = {
},
parameters: {
testOptions: {
- waitForSelector: '.PlayerFrame__content .replayer-wrapper iframe',
+ waitForSelector: 'iframe.PlayerFrame__document >>> .PlayerFrame__content .replayer-wrapper iframe',
},
},
tags: ['test-skip'],
diff --git a/frontend/src/scenes/session-recordings/SessionsRecordings-player-success.stories.tsx b/frontend/src/scenes/session-recordings/SessionsRecordings-player-success.stories.tsx
index 9f4712738c0e..50890467de5e 100644
--- a/frontend/src/scenes/session-recordings/SessionsRecordings-player-success.stories.tsx
+++ b/frontend/src/scenes/session-recordings/SessionsRecordings-player-success.stories.tsx
@@ -4,7 +4,6 @@ import { Meta, StoryObj } from '@storybook/react'
import { combineUrl, router } from 'kea-router'
import { HttpResponse } from 'msw'
-import { FEATURE_FLAGS } from 'lib/constants'
import { App } from 'scenes/App'
import recordingEventsJson from 'scenes/session-recordings/__mocks__/recording_events_query'
import { recordingMetaJson } from 'scenes/session-recordings/__mocks__/recording_meta'
@@ -97,9 +96,6 @@ const meta: Meta = {
layout: 'fullscreen',
viewMode: 'story',
mockDate: '2023-02-01',
- // This file covers the REPLAY_PLAYER_OWN_DOCUMENT path, where rrweb mounts inside the
- // player's own document. The other replay story files stay on the default path.
- featureFlags: [FEATURE_FLAGS.REPLAY_PLAYER_OWN_DOCUMENT],
waitForSelector: 'iframe.PlayerFrame__document >>> .PlayerFrame__content .replayer-wrapper iframe',
pageUrl: urls.replay(),
},
diff --git a/frontend/src/scenes/session-recordings/player/PlayerFrame.scss b/frontend/src/scenes/session-recordings/player/PlayerFrame.scss
index 5fd26225cc94..133774738529 100644
--- a/frontend/src/scenes/session-recordings/player/PlayerFrame.scss
+++ b/frontend/src/scenes/session-recordings/player/PlayerFrame.scss
@@ -14,137 +14,11 @@
touch-action: pan-x pan-y;
}
- // Under REPLAY_PLAYER_OWN_DOCUMENT the wrapper renders inside this frame's document, which
- // this stylesheet cannot reach. The rules below are duplicated in
- // posthog/templates/replay_player_frame/index.html until the flag is removed and this copy goes.
+ // The rrweb wrapper renders inside this frame's document, which this stylesheet cannot reach, so
+ // posthog/templates/replay_player_frame/index.html carries the wrapper's styles.
.PlayerFrame__document {
width: 100%;
height: 100%;
border: 0;
}
-
- .PlayerFrame__content--masking-window .replayer-wrapper::before {
- position: absolute;
- inset: 0; /* Cover the entire wrapper */
- z-index: 10; /* Ensure it's above the iframe */
- pointer-events: auto; /* Block interactions */
- content: '';
- background-image: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBmaWxsPSJibGFjayIvPgo8cGF0aCBkPSJNOCAwSDE2TDAgMTZWOEw4IDBaIiBmaWxsPSIjMkQyRDJEIi8+CjxwYXRoIGQ9Ik0xNiA4VjE2SDhMMTYgOFoiIGZpbGw9IiMyRDJEMkQiLz4KPC9zdmc+Cg==');
- background-repeat: repeat;
- background-size: 16px 16px;
- }
-
- .PlayerFrame__content {
- position: absolute;
-
- // Center the frame so a letterboxed or not-yet-scaled recording sits in the
- // middle of the player rather than pinned to the top-left corner.
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
-
- iframe {
- background-color: white;
- border: 0;
- }
-
- // Copied over from rrweb replay css
- .replayer-wrapper {
- position: relative;
- }
-
- .replayer-mouse {
- position: absolute;
- width: 20px;
- height: 20px;
- background-image: url('data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9JzMwMHB4JyB3aWR0aD0nMzAwcHgnICBmaWxsPSIjMDAwMDAwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGRhdGEtbmFtZT0iTGF5ZXIgMSIgdmlld0JveD0iMCAwIDUwIDUwIiB4PSIwcHgiIHk9IjBweCI+PHRpdGxlPkRlc2lnbl90bnA8L3RpdGxlPjxwYXRoIGQ9Ik00OC43MSw0Mi45MUwzNC4wOCwyOC4yOSw0NC4zMywxOEExLDEsMCwwLDAsNDQsMTYuMzlMMi4zNSwxLjA2QTEsMSwwLDAsMCwxLjA2LDIuMzVMMTYuMzksNDRhMSwxLDAsMCwwLDEuNjUuMzZMMjguMjksMzQuMDgsNDIuOTEsNDguNzFhMSwxLDAsMCwwLDEuNDEsMGw0LjM4LTQuMzhBMSwxLDAsMCwwLDQ4LjcxLDQyLjkxWm0tNS4wOSwzLjY3TDI5LDMyYTEsMSwwLDAsMC0xLjQxLDBsLTkuODUsOS44NUwzLjY5LDMuNjlsMzguMTIsMTRMMzIsMjcuNThBMSwxLDAsMCwwLDMyLDI5TDQ2LjU5LDQzLjYyWiI+PC9wYXRoPjwvc3ZnPg==');
- background-repeat: no-repeat;
- background-position: center center;
- background-size: contain;
- border-color: transparent; /* otherwise we transition from black when .touch-device class is added */
- transition:
- left 0.05s linear,
- top 0.05s linear;
- }
-
- .replayer-mouse::after {
- display: inline-block;
- width: 20px;
- height: 20px;
- content: '';
- background: rgb(73 80 246);
- border-radius: 100%;
- opacity: 0.3;
- transform: translate(-50%, -50%);
- }
-
- .replayer-mouse.active::after {
- animation: PlayerFrame__click var(--player-frame-click-duration, 0.333s) ease-in-out 1;
- }
-
- .replayer-mouse.touch-device {
- width: 70px;
- height: 70px;
- margin-top: -37px;
- margin-left: -37px;
- background-image: none; /* there's no passive cursor on touch-only screens */
- border-color: rgb(73 80 246 / 0%);
- border-style: solid;
- border-width: 4px;
- border-radius: 100%;
- transition:
- left 0s linear,
- top 0s linear,
- border-color 0.2s ease-in-out;
- }
-
- .replayer-mouse.touch-device.touch-active {
- border-color: rgb(73 80 246 / 100%);
- transition:
- left 0.25s linear,
- top 0.25s linear,
- border-color 0.2s ease-in-out;
- }
-
- .replayer-mouse.touch-device::after {
- opacity: 0; /* there's no passive cursor on touch-only screens */
- }
-
- .replayer-mouse.touch-device.active::after {
- animation: PlayerFrame__touch-click var(--player-frame-click-duration, 0.333s) ease-in-out 1;
- }
-
- .replayer-mouse-tail {
- position: absolute;
- pointer-events: none;
- }
-
- @keyframes PlayerFrame__click {
- 0% {
- width: 20px;
- height: 20px;
- opacity: 0.3;
- }
-
- 50% {
- width: 10px;
- height: 10px;
- opacity: 0.5;
- }
- }
-
- @keyframes PlayerFrame__touch-click {
- 0% {
- width: 20px;
- height: 20px;
- opacity: 0;
- }
-
- 50% {
- width: 10px;
- height: 10px;
- opacity: 0.5;
- }
- }
- }
}
diff --git a/frontend/src/scenes/session-recordings/player/PlayerFrame.test.tsx b/frontend/src/scenes/session-recordings/player/PlayerFrame.test.tsx
index 30409ebc0535..98fbe2c791cf 100644
--- a/frontend/src/scenes/session-recordings/player/PlayerFrame.test.tsx
+++ b/frontend/src/scenes/session-recordings/player/PlayerFrame.test.tsx
@@ -4,8 +4,7 @@ import { act, fireEvent, render } from '@testing-library/react'
import { BindLogic, Provider } from 'kea'
import posthog from 'posthog-js'
-import { FEATURE_FLAGS } from 'lib/constants'
-import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { SessionPlayerState } from '~/types'
import { setupSessionRecordingTest } from './__mocks__/test-setup'
import { PlayerFrame } from './PlayerFrame'
@@ -16,13 +15,9 @@ describe('PlayerFrame', () => {
beforeEach(() => {
setupSessionRecordingTest()
- featureFlagLogic.mount()
- featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.REPLAY_PLAYER_OWN_DOCUMENT], {
- [FEATURE_FLAGS.REPLAY_PLAYER_OWN_DOCUMENT]: true,
- })
})
- function renderPlayerFrame(): { container: HTMLElement; iframe: HTMLIFrameElement } {
+ function renderPlayerFrame(): HTMLIFrameElement {
const { container } = render(
<Provider>
<BindLogic logic={sessionRecordingPlayerLogic} props={logicProps}>
@@ -32,13 +27,15 @@ describe('PlayerFrame', () => {
)
const iframe = container.querySelector('iframe.PlayerFrame__document')
if (!(iframe instanceof HTMLIFrameElement)) {
- throw new Error('the flag-on player did not render its frame')
+ throw new Error('the player did not render its frame')
}
- return { container, iframe }
+ // jsdom leaves the frame document mid-load, and the player judges a document that finished loading.
+ Object.defineProperty(iframe.contentDocument!, 'readyState', { value: 'complete', configurable: true })
+ return iframe
}
it('mounts the player on the frame document once the frame loads', () => {
- const { iframe } = renderPlayerFrame()
+ const iframe = renderPlayerFrame()
const frameDocument = iframe.contentDocument!
frameDocument.open()
frameDocument.write('<div id="player-frame-content"></div>')
@@ -56,13 +53,14 @@ describe('PlayerFrame', () => {
// A load event that never arrives used to leave rrweb with nowhere to mount, so the player
// showed an empty rectangle for as long as the tab stayed open. The timeout feeds the same
// failure action as a load without a mount node, so the first timeout retries the frame and
- // the retry flow (or the offline shortcut) reaches the app-document fallback.
- it('retries the frame when the load event never arrives, then falls back', () => {
+ // the retry flow reaches the player's error state.
+ it('retries the frame when the load event never arrives, then shows the player error', () => {
jest.useFakeTimers()
try {
const captureSpy = jest.spyOn(posthog, 'capture')
const captureExceptionSpy = jest.spyOn(posthog, 'captureException')
- const { container, iframe } = renderPlayerFrame()
+ const iframe = renderPlayerFrame()
+ const container = iframe.parentElement!
// The load never fires. The 10s timeout reports the first failure, which schedules a retry.
act(() => {
@@ -76,7 +74,7 @@ describe('PlayerFrame', () => {
// The retry changes the src, and the reloaded frame's load also never fires. The frame
// gets MAX_PLAYER_FRAME_LOAD_RETRIES retries, so failures 1 and 2 retry and failure 3
- // takes the app-document fallback.
+ // reaches the error state.
act(() => {
jest.advanceTimersByTime(1000)
})
@@ -99,10 +97,7 @@ describe('PlayerFrame', () => {
jest.advanceTimersByTime(10000)
})
- expect(container.querySelector('iframe')).toBeNull()
- const fallback = container.querySelector('div.PlayerFrame__content')
- expect(fallback).not.toBeNull()
- expect(sessionRecordingPlayerLogic(logicProps).values.rootFrame).toBe(fallback)
+ expect(sessionRecordingPlayerLogic(logicProps).values.currentPlayerState).toBe(SessionPlayerState.ERROR)
expect(captureExceptionSpy).toHaveBeenCalledTimes(1)
} finally {
jest.useRealTimers()
@@ -133,7 +128,8 @@ describe('PlayerFrame', () => {
jest.useFakeTimers()
try {
const captureSpy = jest.spyOn(posthog, 'capture')
- const { container, iframe } = renderPlayerFrame()
+ const iframe = renderPlayerFrame()
+ const container = iframe.parentElement!
Object.defineProperty(iframe, 'contentDocument', { value: frameDocument(), configurable: true })
act(() => {
@@ -151,33 +147,37 @@ describe('PlayerFrame', () => {
}
})
- // Firefox fires load for the frame's initial about:blank document, which has no mount node.
- // The shell document is still on its way, so the frame must keep its chance to load.
- it('keeps the frame and reports nothing when the blank first document loads', () => {
- const captureSpy = jest.spyOn(posthog, 'captureException')
- const { container, iframe } = renderPlayerFrame()
+ // Firefox fires load for the frame's initial about:blank document, and a load event for a previous
+ // document arrives while the shell is still parsing. Neither has a mount node, and neither is a failure.
+ it.each([
+ ['the blank first document loads', 'about:blank', 'complete'],
+ ['a load arrives while the shell is still parsing', '/replay_player_frame/index.html', 'loading'],
+ ])('reports nothing when %s', (_, url, readyState) => {
+ const captureSpy = jest.spyOn(posthog, 'capture')
+ const captureExceptionSpy = jest.spyOn(posthog, 'captureException')
+ const iframe = renderPlayerFrame()
// jsdom does not load the frame's src, so its document already carries the shell URL.
- Object.defineProperty(iframe.contentDocument!, 'URL', { value: 'about:blank' })
+ Object.defineProperty(iframe.contentDocument!, 'URL', { value: url })
+ Object.defineProperty(iframe.contentDocument!, 'readyState', { value: readyState, configurable: true })
fireEvent.load(iframe)
- expect(container.querySelector('iframe.PlayerFrame__document')).toBe(iframe)
- expect(container.querySelector('div.PlayerFrame__content')).toBeNull()
- expect(captureSpy).not.toHaveBeenCalled()
+ expect(captureExceptionSpy).not.toHaveBeenCalled()
+ expect(captureSpy).not.toHaveBeenCalledWith('replay player frame load retried', expect.anything())
})
// A same-origin error page, a login redirect, or a browser network-error page all fire load
- // with a document that has no mount node. The frame gets retried before the player falls back
- // to the app document. Each retry records what the frame showed, and only the fallback is an exception.
- it('retries a frame that loads without a mount node, then falls back to the app document', () => {
+ // with a document that has no mount node. The frame gets retried before the player shows its error
+ // state. Each retry records what the frame showed, and only the last failure is an exception.
+ it('retries a frame that loads without a mount node, then shows the player error', () => {
jest.useFakeTimers()
try {
const captureSpy = jest.spyOn(posthog, 'capture')
const captureExceptionSpy = jest.spyOn(posthog, 'captureException')
- const { container, iframe } = renderPlayerFrame()
+ const iframe = renderPlayerFrame()
+ const logic = sessionRecordingPlayerLogic(logicProps)
fireEvent.load(iframe)
- expect(container.querySelector('iframe')).toBe(iframe)
act(() => {
jest.advanceTimersByTime(1000)
})
@@ -190,13 +190,11 @@ describe('PlayerFrame', () => {
jest.advanceTimersByTime(2000)
})
expect(iframe).toHaveAttribute('src', '/replay_player_frame/index.html?retry=2')
+ expect(logic.values.currentPlayerState).not.toBe(SessionPlayerState.ERROR)
fireEvent.load(iframe)
- expect(container.querySelector('iframe')).toBeNull()
- const fallback = container.querySelector('div.PlayerFrame__content')
- expect(fallback).not.toBeNull()
- expect(sessionRecordingPlayerLogic(logicProps).values.rootFrame).toBe(fallback)
+ expect(logic.values.currentPlayerState).toBe(SessionPlayerState.ERROR)
expect(
captureSpy.mock.calls
.filter(([event]) => event === 'replay player frame load retried')
@@ -212,25 +210,23 @@ describe('PlayerFrame', () => {
}
})
- // A frame cannot load while the browser is offline, and the app-document fallback needs no network,
- // so the player falls back at once instead of waiting for a connection that may not come back.
- it('falls back to the app document without a retry while the browser is offline', () => {
+ // A frame cannot load while the browser is offline, so the player shows its error at once instead of
+ // staying blank while it waits for a connection that may not come back.
+ it('shows the player error without a retry while the browser is offline', () => {
const onLine = jest.spyOn(navigator, 'onLine', 'get').mockReturnValue(false)
jest.useFakeTimers()
try {
const captureSpy = jest.spyOn(posthog, 'capture')
const captureExceptionSpy = jest.spyOn(posthog, 'captureException')
- const { container, iframe } = renderPlayerFrame()
+ const iframe = renderPlayerFrame()
fireEvent.load(iframe)
act(() => {
jest.advanceTimersByTime(10000)
})
- expect(container.querySelector('iframe')).toBeNull()
- const fallback = container.querySelector('div.PlayerFrame__content')
- expect(fallback).not.toBeNull()
- expect(sessionRecordingPlayerLogic(logicProps).values.rootFrame).toBe(fallback)
+ expect(sessionRecordingPlayerLogic(logicProps).values.currentPlayerState).toBe(SessionPlayerState.ERROR)
+ expect(iframe).toHaveAttribute('src', '/replay_player_frame/index.html')
expect(captureSpy).not.toHaveBeenCalledWith('replay player frame load retried', expect.anything())
expect(captureExceptionSpy).toHaveBeenCalledTimes(1)
expect(captureExceptionSpy.mock.calls[0][1]).toMatchObject({ attempt: 1, browserOnline: false })
diff --git a/frontend/src/scenes/session-recordings/player/PlayerFrame.tsx b/frontend/src/scenes/session-recordings/player/PlayerFrame.tsx
index bd8308b0f183..e19b2c32d4b8 100644
--- a/frontend/src/scenes/session-recordings/player/PlayerFrame.tsx
+++ b/frontend/src/scenes/session-recordings/player/PlayerFrame.tsx
@@ -1,5 +1,4 @@
import './PlayerFrame.scss'
-import './PlayerFrameLLMHighlight.scss'
import useSize from '@react-hook/size'
import clsx from 'clsx'
@@ -7,8 +6,6 @@ import { useActions, useValues } from 'kea'
import { Handler, viewportResizeDimension } from 'posthog-js/rrweb-types'
import { useCallback, useEffect, useRef } from 'react'
-import { FEATURE_FLAGS } from 'lib/constants'
-import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { getPlayerFrameScale, isIOS } from 'scenes/session-recordings/player/playerFrameScaling'
import { sessionRecordingPlayerLogic } from 'scenes/session-recordings/player/sessionRecordingPlayerLogic'
@@ -26,27 +23,15 @@ const PLAYER_FRAME_LOAD_TIMEOUT_MS = 10000
export const PlayerFrame = (): JSX.Element => {
const replayDimensionRef = useRef<viewportResizeDimension>()
- const {
- player,
- sessionRecordingId,
- maskingWindow,
- speed,
- resolution,
- playerFrameDocumentFailed,
- playerFrameLoadRetries,
- } = useValues(sessionRecordingPlayerLogic)
+ const { player, sessionRecordingId, maskingWindow, speed, resolution, playerFrameLoadRetries } =
+ useValues(sessionRecordingPlayerLogic)
const { setScale, setRootFrame, playerFrameDocumentLoadFailed } = useActions(sessionRecordingPlayerLogic)
- const { featureFlags } = useValues(featureFlagLogic)
-
- // A frame that loaded without its mount node falls back to the container below, which is the
- // flag-off path. That path still works, so the player renders rather than staying blank.
- const ownDocument = !!featureFlags[FEATURE_FLAGS.REPLAY_PLAYER_OWN_DOCUMENT] && !playerFrameDocumentFailed
// A frame loads again only when its src changes, so each retry adds a query string the server ignores.
const frameSrc = playerFrameLoadRetries ? `${PLAYER_FRAME_SRC}?retry=${playerFrameLoadRetries}` : PLAYER_FRAME_SRC
const iframeRef = useRef<HTMLIFrameElement | null>(null)
- // rrweb's mount point. Under the flag it lives in the player frame's document, not this one.
+ // rrweb's mount point, which lives in the player frame's document rather than this one.
const frameRef = useRef<HTMLDivElement | null>(null)
const containerRef = useRef<HTMLDivElement | null>(null)
const containerDimensions = useSize(containerRef)
@@ -66,7 +51,7 @@ export const PlayerFrame = (): JSX.Element => {
replayDimensionRef.current = dimensions
// rrweb scales its wrapper to fit the wrapper's parent, so measure that parent rather than
- // this container. Under the flag the parent is the player frame's body.
+ // this container. The parent is the player frame's body.
const parentDimensions = frameRef.current.parentElement.getBoundingClientRect()
const { scale, transform } = getPlayerFrameScale(parentDimensions, dimensions)
@@ -88,25 +73,23 @@ export const PlayerFrame = (): JSX.Element => {
}, [updatePlayerDimensions])
// The app stylesheet cannot reach inside the player frame, so the click duration and the
- // masking overlay are applied to that document rather than to the container below.
+ // masking overlay are applied to that document.
const applyFrameStyles = useCallback((): void => {
- if (!ownDocument) {
- return
- }
iframeRef.current?.contentDocument?.documentElement?.style?.setProperty(
'--player-frame-click-duration',
`${BASE_CLICK_INDICATOR_DURATION_S / speed}s`
)
frameRef.current?.classList?.toggle('PlayerFrame__content--masking-window', !!maskingWindow)
- }, [ownDocument, speed, maskingWindow])
+ }, [speed, maskingWindow])
const handleFrameLoad = useCallback((): void => {
const frameDocument = iframeRef.current?.contentDocument
const content = frameDocument?.getElementById(PLAYER_FRAME_CONTENT_ID)
if (!content) {
- if (frameDocument?.URL === 'about:blank') {
- // Firefox fires load for the frame's initial about:blank document. The shell document
- // is still on its way, so this load says nothing about it.
+ // Firefox fires load for the frame's initial about:blank document, and a load event for a
+ // previous document arrives while the shell is still parsing, which is common in a hidden tab.
+ // The shell is still on its way in both cases, and its own load event follows.
+ if (frameDocument?.URL === 'about:blank' || (frameDocument && frameDocument.readyState !== 'complete')) {
return
}
// A same-origin error page, a login redirect, and a browser error page all fire load too,
@@ -124,28 +107,21 @@ export const PlayerFrame = (): JSX.Element => {
// frameSrc is a dependency so each retry, which swaps the frame's document, arms its own
// timeout instead of reusing the one armed for the previous document.
useEffect(() => {
- if (!ownDocument) {
- return
- }
const timer = setTimeout(() => {
if (!frameRef.current) {
playerFrameDocumentLoadFailed(iframeRef.current)
}
}, PLAYER_FRAME_LOAD_TIMEOUT_MS)
return () => clearTimeout(timer)
- }, [ownDocument, frameSrc, playerFrameDocumentLoadFailed])
+ }, [frameSrc, playerFrameDocumentLoadFailed])
- // Need useEffect to populate replayer on component paint. Under the flag the frame may still be
+ // Need useEffect to populate replayer on component paint. On the first paint the frame is still
// loading, in which case handleFrameLoad does this instead.
- // ownDocument is a dependency because flags resolve after the first paint. A user who holds a
- // stale enabled flag paints the frame, then React swaps in the container below when the fresh
- // value arrives, and the replayer must move with it. The fallback after a failed frame load
- // swaps the same way.
useEffect(() => {
if (frameRef.current) {
setRootFrame(frameRef.current)
}
- }, [sessionRecordingId, ownDocument, setRootFrame])
+ }, [sessionRecordingId, setRootFrame])
useEffect(() => {
applyFrameStyles()
@@ -172,39 +148,21 @@ export const PlayerFrame = (): JSX.Element => {
}, [containerDimensions, windowResize])
return (
- // Adding the LLM highlight class to override clicks animation, in case we decide to make it conditional.
- // The initial approach was conditional, but everyone liked how it looked, so we decided to make it the default.
- // Click indicator duration scales with playback speed: 1/3s at 1x, 1/6s at 2x, etc.
- <div
- ref={containerRef}
- className={clsx('PlayerFrame ph-no-capture PlayerFrame--llm-highlight', isIOS() && 'PlayerFrame--ios')}
- style={
- {
- '--player-frame-click-duration': `${BASE_CLICK_INDICATOR_DURATION_S / speed}s`,
- } as React.CSSProperties
- }
- >
- {ownDocument ? (
- <iframe
- ref={iframeRef}
- className="PlayerFrame__document"
- src={frameSrc}
- onLoad={handleFrameLoad}
- title="Session replay player"
- // Interaction belongs to the app's controls, not the recorded page.
- // Do not add allow-scripts even though the browser reports it missing. That
- // report is from rrweb's own replay frame, which carries the same sandbox and
- // cannot inherit a permission it does not request, so it changes nothing a
- // recording renders. It only lets this document, same-origin with the app, drop
- // its own sandbox.
- sandbox="allow-same-origin"
- />
- ) : (
- <div
- className={clsx('PlayerFrame__content', maskingWindow && 'PlayerFrame__content--masking-window')}
- ref={frameRef}
- />
- )}
+ <div ref={containerRef} className={clsx('PlayerFrame ph-no-capture', isIOS() && 'PlayerFrame--ios')}>
+ <iframe
+ ref={iframeRef}
+ className="PlayerFrame__document"
+ src={frameSrc}
+ onLoad={handleFrameLoad}
+ title="Session replay player"
+ // Interaction belongs to the app's controls, not the recorded page.
+ // Do not add allow-scripts even though the browser reports it missing. That
+ // report is from rrweb's own replay frame, which carries the same sandbox and
+ // cannot inherit a permission it does not request, so it changes nothing a
+ // recording renders. It only lets this document, same-origin with the app, drop
+ // its own sandbox.
+ sandbox="allow-same-origin"
+ />
</div>
)
}
diff --git a/frontend/src/scenes/session-recordings/player/PlayerFrameLLMHighlight.scss b/frontend/src/scenes/session-recordings/player/PlayerFrameLLMHighlight.scss
deleted file mode 100644
index 5341efcae308..000000000000
--- a/frontend/src/scenes/session-recordings/player/PlayerFrameLLMHighlight.scss
+++ /dev/null
@@ -1,66 +0,0 @@
-.PlayerFrame--llm-highlight {
- .PlayerFrame__content {
- .replayer-mouse.active::after {
- // Animation speed slower than 0.33s generates confusions, as the mouse moves (on the other element, but still red)
- // However, to properly catch it we need FPS 3 (1s/0.33)
- // Duration scales with playback speed: 1/3s / speed (set by PlayerFrame.tsx)
- animation: PlayerFrame__click--llm-highlight var(--player-frame-click-duration, 0.333s) ease-in-out 1;
- }
-
- .replayer-mouse.touch-device.active::after {
- animation: PlayerFrame__touch-click--llm-highlight var(--player-frame-click-duration, 0.333s) ease-in-out 1;
- }
-
- // Desktop
- @keyframes PlayerFrame__click--llm-highlight {
- 0% {
- // Start at full size to highlight the click area
- width: 60px;
- height: 60px;
-
- // Using Magenta as it's bright and less likely to blend in with UI elements
- background: rgb(236 72 153);
- opacity: 0.8;
- }
-
- // Shrink unevenly to keep the highlight visible as long as possible
- 80% {
- width: 40px;
- height: 40px;
- background: rgb(236 72 153);
- opacity: 0.8;
- }
-
- 100% {
- width: 20px;
- height: 20px;
- background: rgb(236 72 153);
- opacity: 0.3;
- }
- }
-
- // Mobile (touch devices normally have no passive cursor, so we fade to invisible)
- @keyframes PlayerFrame__touch-click--llm-highlight {
- 0% {
- width: 60px;
- height: 60px;
- background: rgb(236 72 153);
- opacity: 0.8;
- }
-
- 80% {
- width: 40px;
- height: 40px;
- background: rgb(236 72 153);
- opacity: 0.8;
- }
-
- 100% {
- width: 40px;
- height: 40px;
- background: rgb(236 72 153);
- opacity: 0;
- }
- }
- }
-}
diff --git a/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsx b/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsx
index 44a308449081..871a809b9636 100644
--- a/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsx
+++ b/frontend/src/scenes/session-recordings/player/PlayerFrameOverlay.tsx
@@ -84,6 +84,7 @@ const PlayerFrameOverlayContent = (): JSX.Element | null => {
endReached,
logicProps,
playerError,
+ playerFrameDocumentFailed,
isWaitingForIngestion,
sessionPlayerMetaData,
matchingEventSkipTarget,
@@ -102,7 +103,11 @@ const PlayerFrameOverlayContent = (): JSX.Element | null => {
const playerMode = logicProps.mode ?? SessionRecordingPlayerMode.Standard
const showActionsOnOverlay = playerMode === SessionRecordingPlayerMode.Standard && pausedState
- if (currentPlayerState === SessionPlayerState.ERROR && playerError === 'recordingTooLarge') {
+ if (
+ currentPlayerState === SessionPlayerState.ERROR &&
+ playerError === 'recordingTooLarge' &&
+ !playerFrameDocumentFailed
+ ) {
const totalSize = sessionPlayerMetaData?.total_size
content = (
<div className="flex flex-col justify-center items-center p-6 bg-surface-primary rounded m-6 gap-2 max-w-120 shadow-sm">
@@ -125,23 +130,31 @@ const PlayerFrameOverlayContent = (): JSX.Element | null => {
</div>
)
} else if (currentPlayerState === SessionPlayerState.ERROR) {
- const isMissingFullSnapshot = playerError === 'noPlayableFullSnapshot'
- const isUnauthorized = playerError === 'snapshotUnauthorized'
- const isRecoverable = !!playerError && RECOVERABLE_SNAPSHOT_ERRORS.includes(playerError)
+ // A player frame that never loaded leaves nothing to draw into, so its message outranks any snapshot error.
+ const isMissingFullSnapshot = !playerFrameDocumentFailed && playerError === 'noPlayableFullSnapshot'
+ const isUnauthorized = !playerFrameDocumentFailed && playerError === 'snapshotUnauthorized'
+ const isRecoverable =
+ !playerFrameDocumentFailed && !!playerError && RECOVERABLE_SNAPSHOT_ERRORS.includes(playerError)
content = (
<div className="flex flex-col justify-center items-center p-6 bg-surface-primary rounded m-6 gap-2 max-w-120 shadow-sm">
<IconWarning className="text-danger text-5xl" />
<div className="font-bold text-text-3000 text-lg">
- {isRecoverable ? "We couldn't load this recording" : "We're unable to play this recording"}
+ {playerFrameDocumentFailed
+ ? "We couldn't load the replay player"
+ : isRecoverable
+ ? "We couldn't load this recording"
+ : "We're unable to play this recording"}
</div>
<div className="text-secondary text-sm text-center">
- {isMissingFullSnapshot
- ? 'This part of the recording is missing the snapshot data needed to render it. The data never reached PostHog, usually because the browser was closed or went offline before the recording finished uploading.'
- : isUnauthorized
- ? 'Your session has expired. Sign in again to keep watching this recording.'
- : isRecoverable
- ? "We couldn't fetch the recording data. This is usually a temporary network problem. Retry, and if it keeps failing contact support."
- : 'An error occurred that is preventing this recording from being played. You can refresh the page to reload the recording.'}
+ {playerFrameDocumentFailed
+ ? "Your browser couldn't load the player. Check your internet connection and reload the page. If it keeps happening, a browser extension or security setting may be blocking it. Try turning off extensions for PostHog or using another browser."
+ : isMissingFullSnapshot
+ ? 'This part of the recording is missing the snapshot data needed to render it. The data never reached PostHog, usually because the browser was closed or went offline before the recording finished uploading.'
+ : isUnauthorized
+ ? 'Your session has expired. Sign in again to keep watching this recording.'
+ : isRecoverable
+ ? "We couldn't fetch the recording data. This is usually a temporary network problem. Retry, and if it keeps failing contact support."
+ : 'An error occurred that is preventing this recording from being played. You can refresh the page to reload the recording.'}
</div>
{isUnauthorized && (
<LemonButton to={urls.login()} type="primary" fullWidth center>
diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts
index 0191c1f014b2..f7f9e6588d57 100644
--- a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts
+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.test.ts
@@ -15,7 +15,7 @@ import { makeLogger } from 'scenes/session-recordings/player/utils/player-loggin
import { urls } from 'scenes/urls'
import { resumeKeaLoadersErrors, silenceKeaLoadersErrors } from '~/initKea'
-import { ExporterFormat, RecordingSegment, RecordingSnapshot } from '~/types'
+import { ExporterFormat, RecordingSegment, RecordingSnapshot, SessionPlayerState } from '~/types'
import { analysisNudgeLogic } from 'products/replay_vision/frontend/logics/analysisNudgeLogic'
import { isUsableHeatmapUrl } from 'products/web_analytics/frontend/heatmaps/replayIframeData'
@@ -413,6 +413,23 @@ describe('sessionRecordingPlayerLogic', () => {
resumeKeaLoadersErrors()
})
+ it('stays paused if autoplay is off', async () => {
+ logic.unmount()
+ logic = sessionRecordingPlayerLogic({ sessionRecordingId: '2', playerKey: 'test', autoPlay: false })
+ logic.mount()
+
+ silenceKeaLoadersErrors()
+
+ await expectLogic(logic).toDispatchActions([
+ sessionRecordingDataCoordinatorLogic({ sessionRecordingId: '2' }).actionTypes.loadRecordingMetaSuccess,
+ snapshotDataLogic({ sessionRecordingId: '2' }).actionTypes.loadSnapshotSourcesSuccess,
+ ])
+
+ expect(logic.values.playingState).toEqual(SessionPlayerState.PAUSE)
+
+ resumeKeaLoadersErrors()
+ })
+
it('marks as viewed once playing', async () => {
logic.unmount()
logic = sessionRecordingPlayerLogic({ sessionRecordingId: '2', playerKey: 'test', autoPlay: true })
diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts
index d0fce649f71c..7393cc54714b 100644
--- a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts
+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts
@@ -96,7 +96,7 @@ export const PLAYBACK_SPEEDS = [0.5, 1, 1.5, 2, 3, 4, 8, 16]
export const ONE_FRAME_MS = 100 // We don't really have frames but this feels granular enough
export const ONE_SECOND_MS = 1000
// A failed frame load is usually transient, so the frame gets a few more chances before the player
-// falls back to the app document.
+// shows its error.
const MAX_PLAYER_FRAME_LOAD_RETRIES = 2
const PLAYER_FRAME_RETRY_DELAY_MS = 1000
@@ -1092,7 +1092,8 @@ export interface sessionRecordingPlayerLogicMeta {
isSkippingInactivity: boolean,
isSkippingToMatchingEvent: boolean,
snapshotsLoaded: boolean,
- snapshotsLoading: boolean
+ snapshotsLoading: boolean,
+ playerFrameDocumentFailed: boolean
) =>
| SessionPlayerState.READY
| SessionPlayerState.BUFFER
@@ -1497,7 +1498,11 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
},
],
playingState: [
- SessionPlayerState.PLAY as SessionPlayerState.PLAY | SessionPlayerState.PAUSE,
+ // The first syncPlayerState plays whatever this default holds, so a player that opts out
+ // of autoplay has to start paused. An unset autoPlay keeps the playing default.
+ (props.autoPlay === false ? SessionPlayerState.PAUSE : SessionPlayerState.PLAY) as
+ | SessionPlayerState.PLAY
+ | SessionPlayerState.PAUSE,
{
setPlay: () => SessionPlayerState.PLAY,
setPause: () => SessionPlayerState.PAUSE,
@@ -1702,6 +1707,7 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
s.isSkippingToMatchingEvent,
s.snapshotsLoaded,
s.snapshotsLoading,
+ s.playerFrameDocumentFailed,
],
(
playingState: SessionPlayerState.PLAY | SessionPlayerState.PAUSE,
@@ -1711,9 +1717,13 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
isSkippingInactivity: boolean,
isSkippingToMatchingEvent: boolean,
snapshotsLoaded: boolean,
- snapshotsLoading: boolean
+ snapshotsLoading: boolean,
+ playerFrameDocumentFailed: boolean
) => {
switch (true) {
+ // The frame failure stays out of playerError, because playback clears that whenever it buffers.
+ case playerFrameDocumentFailed:
+ return SessionPlayerState.ERROR
case isScrubbing:
// If scrubbing, playingState takes precedence
return playingState
@@ -2336,17 +2346,21 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
}
},
playerFrameDocumentLoadFailed: ({ iframe }) => {
+ // The load timeout and a late load event both fire after the player gave up, and the viewer
+ // already has the error, so the failure is reported once per player.
+ if (values.playerFrameLoadStopped) {
+ return
+ }
const report = {
sessionRecordingId: props.sessionRecordingId,
attempt: values.playerFrameLoadFailures,
...getPlayerFrameLoadDiagnostics(iframe),
}
- // A load retried while offline fails again, and the app-document fallback needs no network, so
- // an offline browser gets that fallback now. A connection can stay away for the rest of the
- // session, and a viewer whose snapshots are loaded already must not wait for it.
+ // A load retried while offline fails again, and a connection can stay away for the rest of the
+ // session. An offline browser stops retrying at once, so the viewer sees the error instead of a
+ // blank player that waits for the network.
if (values.playerFrameDocumentFailed || !navigator.onLine) {
actions.stopRetryingPlayerFrameLoad()
- // The app-document fallback hides the failure from the viewer, so the only sign of it is the report.
posthog.captureException(new Error('Replay player frame loaded without its mount node'), {
feature: 'session-recording-player-frame',
...report,
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
index 07efcc9c815a..3fac9c2e7809 100644
--- 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
@@ -19,6 +19,14 @@ describe('parseDeepLinkTime', () => {
t: 30,
expected: { kind: 'offset', valueMs: 30000 },
},
+ {
+ // kea-router turns `?t=0` into the number 0, and a truthiness check drops it, so the
+ // recording started wherever the player chose instead of at the beginning.
+ name: 'zero t is the start of the recording',
+ timestamp: undefined,
+ t: 0,
+ expected: { kind: 'offset', valueMs: 0 },
+ },
{
name: 'numeric timestamp is absolute unix ms',
timestamp: 1756720830000,
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
index 393a761885e7..3da2f702c4bd 100644
--- a/frontend/src/scenes/session-recordings/player/utils/deep-link-time.ts
+++ b/frontend/src/scenes/session-recordings/player/utils/deep-link-time.ts
@@ -14,13 +14,13 @@ export function parseDeepLinkTime(
timestampParam: string | number | undefined,
tParam: string | number | undefined
): DeepLinkTime | null {
- if (timestampParam) {
+ if (isPresent(timestampParam)) {
const absolute = parseAbsoluteMs(timestampParam)
if (absolute !== null) {
return { kind: 'timestamp', valueMs: absolute }
}
}
- if (tParam) {
+ if (isPresent(tParam)) {
const seconds = toFiniteNumber(tParam)
if (seconds !== null) {
return { kind: 'offset', valueMs: seconds * 1000 }
@@ -33,6 +33,12 @@ export function parseDeepLinkTime(
return null
}
+// kea-router parses a numeric query param into a number, so `?t=0` arrives as 0, which is present
+// but falsy. A truthiness check drops it and the recording starts wherever the player chooses.
+function isPresent(value: string | number | undefined): value is string | number {
+ return value != null && value !== ''
+}
+
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)
diff --git a/frontend/src/scenes/session-recordings/playlist/SessionRecordingsPlaylistScene.stories.tsx b/frontend/src/scenes/session-recordings/playlist/SessionRecordingsPlaylistScene.stories.tsx
index 3e250722fd9a..6a4e02a58aa3 100644
--- a/frontend/src/scenes/session-recordings/playlist/SessionRecordingsPlaylistScene.stories.tsx
+++ b/frontend/src/scenes/session-recordings/playlist/SessionRecordingsPlaylistScene.stories.tsx
@@ -88,7 +88,7 @@ const meta: Meta = {
mockDate: '2023-07-04',
testOptions: {
loaderTimeout: 15000,
- waitForSelector: '.PlayerFrame__content .replayer-wrapper iframe',
+ waitForSelector: 'iframe.PlayerFrame__document >>> .PlayerFrame__content .replayer-wrapper iframe',
},
},
decorators: [
diff --git a/posthog/templates/replay_player_frame/index.html b/posthog/templates/replay_player_frame/index.html
index 9e94353a3a6b..09d2d241cc98 100644
--- a/posthog/templates/replay_player_frame/index.html
+++ b/posthog/templates/replay_player_frame/index.html
@@ -5,10 +5,8 @@
<title>Session replay player</title>
<style>
/*
- Copied from PlayerFrame.scss and PlayerFrameLLMHighlight.scss. These rules style the
- rrweb wrapper, which under REPLAY_PLAYER_OWN_DOCUMENT lives in this document rather than
- the app's, so the app's stylesheet can no longer reach them. Both copies stay until the
- flag is removed, at which point the app's copy goes and this one remains.
+ These rules style the rrweb wrapper, which lives in this document rather than the app's,
+ so the app's stylesheet cannot reach them.
*/
html, body {
width: 100%;
@@ -108,10 +106,6 @@
pointer-events: none;
}
- /*
- The click highlight was conditional on a `.PlayerFrame--llm-highlight` class on the app-side
- container. The app sets that class unconditionally, so the rules apply unconditionally here.
- */
.PlayerFrame__content .replayer-mouse.active::after {
/* Duration scales with playback speed; the app sets the property on this document. */
animation: PlayerFrame__click--llm-highlight var(--player-frame-click-duration, 0.333s) ease-in-out 1;
diff --git a/posthog/test/test_middleware.py b/posthog/test/test_middleware.py
index c5d640050faf..19a127669e40 100644
--- a/posthog/test/test_middleware.py
+++ b/posthog/test/test_middleware.py
@@ -1978,8 +1978,7 @@ class TestCSPMiddleware(APIBaseTest):
self.client.logout()
response = self.client.get("/replay_player_frame/index.html")
assert response.status_code == 200
- # PlayerFrame.tsx looks the mount node up by this id. A rename here makes every player fall
- # back to the app document.
+ # PlayerFrame.tsx looks the mount node up by this id. A rename here makes every player show its load error.
assert 'id="player-frame-content"' in response.content.decode()
def test_non_html_response_gets_strict_csp(self):
diff --git a/products/replay/frontend/e2e/player.spec.ts b/products/replay/frontend/e2e/player.spec.ts
index 40892116fa24..3809a02fa903 100644
--- a/products/replay/frontend/e2e/player.spec.ts
+++ b/products/replay/frontend/e2e/player.spec.ts
@@ -1,9 +1,7 @@
-import { mockFeatureFlags } from '@playwright-utils/mockApi'
import { PlaywrightWorkspaceSetupResult, expect, test } from '@playwright-utils/workspace-test-base'
import { Locator, Page } from '@playwright/test'
import snappy from 'snappyjs'
-import { FEATURE_FLAGS } from 'lib/constants'
import { recordingMetaJson } from 'scenes/session-recordings/__mocks__/recording_meta'
import {
lateFullSnapshotAsJSONLines,
@@ -172,14 +170,9 @@ async function mockRecordingApi(page: Page): Promise<void> {
}
}
-// The frame shell (posthog/templates/replay_player_frame/index.html) reuses these class names, so
-// only the document boundary differs between paths, and a Locator searches one document.
-const PLAYER_CONTENT_SELECTOR = '.PlayerFrame__content .replayer-wrapper iframe'
-
-function playerFrame(page: Page, ownDocument = false): Locator {
- return ownDocument
- ? page.frameLocator('iframe.PlayerFrame__document').locator(PLAYER_CONTENT_SELECTOR)
- : page.locator(PLAYER_CONTENT_SELECTOR)
+// rrweb mounts inside the player frame's own document, and a Locator searches one document.
+function playerFrame(page: Page): Locator {
+ return page.frameLocator('iframe.PlayerFrame__document').locator('.PlayerFrame__content .replayer-wrapper iframe')
}
// One button whose data-attr reflects player state and stays assertable while the auto-hiding controls chrome is hidden (hover via revealControls before clicking it).
@@ -203,36 +196,6 @@ async function scrubTo(page: Page, fraction: number): Promise<void> {
await page.mouse.click(box.x + box.width * fraction, box.y + box.height / 2)
}
-// featureFlagLogic merges the server's `persisted_feature_flags` list as an always-on baseline over
-// posthog-js flags, so an instance that force-enables this flag picks the path on its own.
-// Pinning has to override both sources.
-async function pinOwnDocumentFlag(page: Page, enabled: boolean): Promise<void> {
- await page.addInitScript(
- ({ flag, enabled }: { flag: string; enabled: boolean }) => {
- let context: Record<string, any> | undefined
- // The app context lands in a later inline script, so intercept the assignment.
- Object.defineProperty(window, 'POSTHOG_APP_CONTEXT', {
- configurable: true,
- get: () => context,
- set: (value: Record<string, any> | undefined) => {
- const persisted = value?.persisted_feature_flags
- if (!value || !Array.isArray(persisted)) {
- context = value
- return
- }
- const withoutFlag = persisted.filter((f: string) => f !== flag)
- context = {
- ...value,
- persisted_feature_flags: enabled ? [...withoutFlag, flag] : withoutFlag,
- }
- },
- })
- },
- { flag: FEATURE_FLAGS.REPLAY_PLAYER_OWN_DOCUMENT, enabled }
- )
- await mockFeatureFlags(page, { [FEATURE_FLAGS.REPLAY_PLAYER_OWN_DOCUMENT]: enabled })
-}
-
test.describe.configure({ mode: 'serial' })
let workspace: PlaywrightWorkspaceSetupResult | null = null
@@ -243,11 +206,20 @@ test.beforeAll(async ({ playwrightSetup }) => {
test.describe('Session replay player', () => {
test.beforeEach(async ({ page, playwrightSetup }) => {
- await pinOwnDocumentFlag(page, false)
await playwrightSetup.loginAndNavigateToTeam(page, workspace!)
await mockRecordingApi(page)
})
+ test('mounts the player inside the frame document and plays', async ({ page }) => {
+ await page.goto(`/replay/${SESSION_ID}?t=0`)
+
+ await expect(page.locator('iframe.PlayerFrame__document')).toBeVisible({ timeout: 30000 })
+ await expect(playerFrame(page)).toBeVisible({ timeout: 30000 })
+
+ await expect(playPauseButton(page)).toHaveAttribute('data-attr', 'recording-pause')
+ await expect(page.getByTestId('recording-timestamp')).toHaveText(/00:0[1-9]|00:1[01]/, { timeout: 15000 })
+ })
+
test('plays a multi-source recording, pauses, seeks, scrubs, and reaches the end', async ({ page }) => {
await test.step('boots and autoplays from the start', async () => {
await page.goto(`/replay/${SESSION_ID}?t=0`)
@@ -352,25 +324,3 @@ test.describe('Session replay player', () => {
await expect(bufferingIndicator(page)).not.toBeVisible()
})
})
-
-test.describe('Session replay player in its own document', () => {
- test.beforeEach(async ({ page, playwrightSetup }) => {
- await pinOwnDocumentFlag(page, true)
- await playwrightSetup.loginAndNavigateToTeam(page, workspace!)
- await mockRecordingApi(page)
- })
-
- test('mounts the player inside the frame document and plays', async ({ page }) => {
- await page.goto(`/replay/${SESSION_ID}?t=0`)
-
- await expect(page.locator('iframe.PlayerFrame__document')).toBeVisible({ timeout: 30000 })
- // PlayerFrame swaps in this container when the frame loads without its mount node. Its absence
- // proves no fallback, which would otherwise satisfy the assertions below and hide a broken frame.
- await expect(page.locator('div.PlayerFrame__content')).toHaveCount(0)
-
- await expect(playerFrame(page, true)).toBeVisible({ timeout: 30000 })
-
- await expect(playPauseButton(page)).toHaveAttribute('data-attr', 'recording-pause')
- await expect(page.getByTestId('recording-timestamp')).toHaveText(/00:0[1-9]|00:1[01]/, { timeout: 15000 })
- })
-})