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): ignore the blank first load of the player frame (#97804)

posthog[bot]5d4916eb4686
diff --git a/frontend/src/scenes/session-recordings/player/PlayerFrame.test.tsx b/frontend/src/scenes/session-recordings/player/PlayerFrame.test.tsx
index 7efdedd7d5cb..c73536bf77ba 100644
--- a/frontend/src/scenes/session-recordings/player/PlayerFrame.test.tsx
+++ b/frontend/src/scenes/session-recordings/player/PlayerFrame.test.tsx
@@ -53,6 +53,21 @@ describe('PlayerFrame', () => {
expect(iframe).toHaveAttribute('sandbox', 'allow-same-origin')
})
+ // 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()
+ // jsdom does not load the frame's src, so its document already carries the shell URL.
+ Object.defineProperty(iframe.contentDocument!, 'URL', { value: 'about:blank' })
+
+ fireEvent.load(iframe)
+
+ expect(container.querySelector('iframe.PlayerFrame__document')).toBe(iframe)
+ expect(container.querySelector('div.PlayerFrame__content')).toBeNull()
+ expect(captureSpy).not.toHaveBeenCalled()
+ })
+
// 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 player must not stay blank with no report.
it('falls back to the app document and reports it when the frame loads without a mount node', () => {
diff --git a/frontend/src/scenes/session-recordings/player/PlayerFrame.tsx b/frontend/src/scenes/session-recordings/player/PlayerFrame.tsx
index 5ee90a4e5c60..b5c4b4c6f7b0 100644
--- a/frontend/src/scenes/session-recordings/player/PlayerFrame.tsx
+++ b/frontend/src/scenes/session-recordings/player/PlayerFrame.tsx
@@ -88,8 +88,14 @@ export const PlayerFrame = (): JSX.Element => {
}, [ownDocument, speed, maskingWindow])
const handleFrameLoad = useCallback((): void => {
- const content = iframeRef.current?.contentDocument?.getElementById(PLAYER_FRAME_CONTENT_ID)
+ 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.
+ return
+ }
// A same-origin error page, a login redirect, and a browser error page all fire load too,
// so a load event does not prove the shell document arrived.
playerFrameDocumentLoadFailed()