: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): keep a failed player frame able to retry (#101293)
posthog[bot]e9b3dd89743c
diff --git a/frontend/src/scenes/session-recordings/player/PlayerFrame.test.tsx b/frontend/src/scenes/session-recordings/player/PlayerFrame.test.tsxindex 835b9fd7b36b..30409ebc0535 100644--- a/frontend/src/scenes/session-recordings/player/PlayerFrame.test.tsx+++ b/frontend/src/scenes/session-recordings/player/PlayerFrame.test.tsx@@ -109,6 +109,48 @@ describe('PlayerFrame', () => {}})+ it.each([+ {+ state: 'no browsing context',+ // jsdom gives a document made this way no browsing context, the same as a browser does.+ frameDocument: (): Document => document.implementation.createHTMLDocument(),+ report: { attempt: 1, frameUrlPath: null },+ },+ {+ state: 'a read that throws',+ frameDocument: (): Document => {+ const frameDocument = document.implementation.createHTMLDocument()+ Object.defineProperty(frameDocument, 'title', {+ get: () => {+ throw new Error('read failed')+ },+ })+ return frameDocument+ },+ report: { attempt: 1, frameDocumentReadable: true },+ },+ ])('retries the frame when the timed-out frame has $state', ({ frameDocument, report }) => {+ jest.useFakeTimers()+ try {+ const captureSpy = jest.spyOn(posthog, 'capture')+ const { container, iframe } = renderPlayerFrame()+ Object.defineProperty(iframe, 'contentDocument', { value: frameDocument(), configurable: true })++ act(() => {+ jest.advanceTimersByTime(10000)+ })++ expect(captureSpy).toHaveBeenCalledWith('replay player frame load retried', expect.objectContaining(report))+ act(() => {+ jest.advanceTimersByTime(1000)+ })+ expect(container.querySelector('iframe')).toBe(iframe)+ expect(iframe).toHaveAttribute('src', '/replay_player_frame/index.html?retry=1')+ } finally {+ jest.useRealTimers()+ }+ })+// 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', () => {diff --git a/frontend/src/scenes/session-recordings/player/playerFrameLoadDiagnostics.ts b/frontend/src/scenes/session-recordings/player/playerFrameLoadDiagnostics.tsindex f46c66f73130..5e64f8fe294a 100644--- a/frontend/src/scenes/session-recordings/player/playerFrameLoadDiagnostics.ts+++ b/frontend/src/scenes/session-recordings/player/playerFrameLoadDiagnostics.ts@@ -22,19 +22,25 @@ function responseStatus(src: string): number | null {// Describes what the frame loaded in place of the shell document, so a report can tell a network// error page, an HTTP error, and a redirect apart.-export function getPlayerFrameLoadDiagnostics(iframe: HTMLIFrameElement | null): PlayerFrameLoadDiagnostics {+export function getPlayerFrameLoadDiagnostics(iframe: HTMLIFrameElement | null): Partial<PlayerFrameLoadDiagnostics> {// A browser error page or a redirect to another origin makes the frame cross-origin, which hides its document.const frameDocument = iframe?.contentDocument ?? null- return {- frameDocumentReadable: frameDocument !== null,- // The path alone, because a query string can carry a token.- frameUrlPath: frameDocument?.location.pathname ?? null,- frameDocumentTitle: frameDocument ? frameDocument.title.slice(0, MAX_TITLE_LENGTH) : null,- frameContentType: frameDocument?.contentType ?? null,- frameReadyState: frameDocument?.readyState ?? null,- frameResponseStatus: iframe ? responseStatus(iframe.src) : null,- browserOnline: navigator.onLine,- pageVisibility: document.visibilityState,- msSincePageLoad: Math.round(performance.now()),+ try {+ return {+ frameDocumentReadable: frameDocument !== null,+ // The path alone, because a query string can carry a token. A document with no browsing+ // context has a null location.+ frameUrlPath: frameDocument?.location?.pathname ?? null,+ frameDocumentTitle: frameDocument ? frameDocument.title.slice(0, MAX_TITLE_LENGTH) : null,+ frameContentType: frameDocument?.contentType ?? null,+ frameReadyState: frameDocument?.readyState ?? null,+ frameResponseStatus: iframe ? responseStatus(iframe.src) : null,+ browserOnline: navigator.onLine,+ pageVisibility: document.visibilityState,+ msSincePageLoad: Math.round(performance.now()),+ }+ } catch {+ // The retry runs after this report, so a read that throws must not stop it.+ return { frameDocumentReadable: frameDocument !== null }}}