: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): scale with transform on iOS so recordings render correctly (#94256)
Hayne Ryueb07f68b8ec7
diff --git a/frontend/src/scenes/session-recordings/player/PlayerFrame.scss b/frontend/src/scenes/session-recordings/player/PlayerFrame.scssindex d1018e8a8054..8af8c7b0eb76 100644--- a/frontend/src/scenes/session-recordings/player/PlayerFrame.scss+++ b/frontend/src/scenes/session-recordings/player/PlayerFrame.scss@@ -10,6 +10,10 @@overflow: hidden;background-color: var(--color-bg-3000-dark);+ &--ios {+ touch-action: pan-x pan-y;+ }+.PlayerFrame__content--masking-window .replayer-wrapper::before {position: absolute;inset: 0; /* Cover the entire wrapper */diff --git a/frontend/src/scenes/session-recordings/player/PlayerFrame.tsx b/frontend/src/scenes/session-recordings/player/PlayerFrame.tsxindex 24e64d16fd6a..16d6572831e0 100644--- a/frontend/src/scenes/session-recordings/player/PlayerFrame.tsx+++ b/frontend/src/scenes/session-recordings/player/PlayerFrame.tsx@@ -37,14 +37,9 @@ export const PlayerFrame = (): JSX.Element => {const parentDimensions = frameRef.current.parentElement.getBoundingClientRect()- const { scale, zoom, transform } = getPlayerFrameScale(parentDimensions, dimensions, isIOS())+ const { scale, transform } = getPlayerFrameScale(parentDimensions, dimensions)const wrapperStyle = player.replayer.wrapper.style- if (zoom === null) {- wrapperStyle.removeProperty('zoom')- } else {- wrapperStyle.setProperty('zoom', zoom)- }if (transform === null) {wrapperStyle.removeProperty('transform')} else {@@ -93,7 +88,7 @@ export const PlayerFrame = (): JSX.Element => {// Click indicator duration scales with playback speed: 1/3s at 1x, 1/6s at 2x, etc.<divref={containerRef}- className={clsx('PlayerFrame ph-no-capture PlayerFrame--llm-highlight')}+ className={clsx('PlayerFrame ph-no-capture PlayerFrame--llm-highlight', isIOS() && 'PlayerFrame--ios')}style={{'--player-frame-click-duration': `${BASE_CLICK_INDICATOR_DURATION_S / speed}s`,diff --git a/frontend/src/scenes/session-recordings/player/playerFrameScaling.test.ts b/frontend/src/scenes/session-recordings/player/playerFrameScaling.test.tsindex 60c651e6a44c..47eef9decfdf 100644--- a/frontend/src/scenes/session-recordings/player/playerFrameScaling.test.ts+++ b/frontend/src/scenes/session-recordings/player/playerFrameScaling.test.ts@@ -7,15 +7,8 @@ import {const IPHONE ='Mozilla/5.0 (iPhone; CPU iPhone OS 18_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1 Mobile/15E148 Safari/604.1'-const IPAD_LEGACY =- 'Mozilla/5.0 (iPad; CPU OS 12_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Mobile/15E148 Safari/604.1'-// iPadOS 13+ reports the same user agent as desktop Safari. Only maxTouchPoints separates them.const MAC_SAFARI ='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15'-const MAC_CHROME =- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'-const WINDOWS_CHROME =- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'const ANDROID_CHROME ='Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36'@@ -33,11 +26,8 @@ describe('isIOS', () => {it.each([['iPhone Safari', IPHONE, 5, true],- ['iPad on iPadOS 12', IPAD_LEGACY, 5, true],['iPad reporting a Macintosh user agent', MAC_SAFARI, 5, true],['macOS Safari', MAC_SAFARI, 0, false],- ['macOS Chrome', MAC_CHROME, 0, false],- ['Windows Chrome', WINDOWS_CHROME, 0, false],['Android Chrome', ANDROID_CHROME, 5, false],] as [string, string, number, boolean][])('%s', (_, userAgent, maxTouchPoints, expected) => {setNavigator(userAgent, maxTouchPoints)@@ -49,44 +39,27 @@ describe('isIOS', () => {describe('getPlayerFrameScale', () => {it.each([[- 'shrinks a desktop capture with transform off iOS',+ 'shrinks a desktop capture with transform',{ width: 855, height: 500 },{ width: 1710, height: 881 },- false,- { scale: 0.5, zoom: null, transform: 'scale(0.5)' },- ],- [- 'shrinks the same capture with zoom on iOS',- { width: 855, height: 500 },- { width: 1710, height: 881 },- true,- { scale: 0.5, zoom: '0.5', transform: null },+ { scale: 0.5, transform: 'scale(0.5)' },],['drops the transform when no shrink is needed, so Chrome does not paint outside the clip',{ width: 1920, height: 1080 },{ width: 1710, height: 881 },- false,- { scale: 1, zoom: null, transform: null },- ],- [- 'still sets zoom at full size on iOS',- { width: 1920, height: 1080 },- { width: 1710, height: 881 },- true,- { scale: 1, zoom: '1', transform: null },+ { scale: 1, transform: null },],['picks the height ratio when that axis is the tighter fit',{ width: 1710, height: 440 },{ width: 1710, height: 880 },- false,- { scale: 0.5, zoom: null, transform: 'scale(0.5)' },+ { scale: 0.5, transform: 'scale(0.5)' },],- ] as [string, PlayerFrameDimensions, PlayerFrameDimensions, boolean, PlayerFrameScale][])(+ ] as [string, PlayerFrameDimensions, PlayerFrameDimensions, PlayerFrameScale][])('%s',- (_, parent, recorded, onIOS, expected) => {- expect(getPlayerFrameScale(parent, recorded, onIOS)).toEqual(expected)+ (_, parent, recorded, expected) => {+ expect(getPlayerFrameScale(parent, recorded)).toEqual(expected)})})diff --git a/frontend/src/scenes/session-recordings/player/playerFrameScaling.ts b/frontend/src/scenes/session-recordings/player/playerFrameScaling.tsindex 0365904f5ee5..129e153602a7 100644--- a/frontend/src/scenes/session-recordings/player/playerFrameScaling.ts+++ b/frontend/src/scenes/session-recordings/player/playerFrameScaling.ts@@ -5,13 +5,10 @@ export interface PlayerFrameDimensions {export interface PlayerFrameScale {scale: number- // null clears the property on the replay wrapper.- zoom: string | nulltransform: string | null}-// A decimal `transform: scale()` crashes the tab on pinch-zoom in iOS WebKit (FB13816677).-// iPadOS 13+ reports a Mac user agent; desktop Safari reports maxTouchPoints 0.+// iPadOS 13+ reports a Mac user agent.export function isIOS(): boolean {if (typeof navigator === 'undefined') {return false@@ -20,20 +17,10 @@ export function isIOS(): boolean {return /iPad|iPhone|iPod/.test(ua) || (/Macintosh/.test(ua) && navigator.maxTouchPoints > 1)}-export function getPlayerFrameScale(- parent: PlayerFrameDimensions,- recorded: PlayerFrameDimensions,- onIOS: boolean-): PlayerFrameScale {+// Not `zoom`: WebKit propagates it into the iframe (#91417).+export function getPlayerFrameScale(parent: PlayerFrameDimensions, recorded: PlayerFrameDimensions): PlayerFrameScale {const scale = Math.min(parent.width / recorded.width, parent.height / recorded.height, 1)- if (onIOS) {- // `zoom` scales through layout, so no composited layer exists to re-rasterize.- return { scale, zoom: String(scale), transform: null }- }-- // WebKit's `zoom` shrinks the iframe's documentElement.clientWidth, firing a desktop capture's- // mobile breakpoints. `transform` is visual only, so the recorded viewport survives. Chrome- // paints the iframe outside its clip bounds under an identity transform, so drop it at scale 1.- return { scale, zoom: null, transform: scale === 1 ? null : `scale(${scale})` }+ // Chrome clips wrongly under an identity transform.+ return { scale, transform: scale === 1 ? null : `scale(${scale})` }}