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): stop treating mobile image wireframes as screenshots (#103703)

Ioannis Jfcea037d5ebc
diff --git a/common/replay-shared/src/mobile/mobile.types.ts b/common/replay-shared/src/mobile/mobile.types.ts
index 8841de8fae19..b3e4b288c419 100644
--- a/common/replay-shared/src/mobile/mobile.types.ts
+++ b/common/replay-shared/src/mobile/mobile.types.ts
@@ -262,7 +262,7 @@ export type wireframeImage = wireframeBase & {
/**
* @description a screenshot behaves exactly like an image, but it is expected to be a screenshot of the screen at the time of the event, when sent as a mutation it must always attached to the root of the playback, when sent as an initial snapshot it must be sent as the first or only snapshot so that it attaches to the body of the playback
*/
-export type wireframeScreenshot = wireframeImage & {
+export type wireframeScreenshot = Omit<wireframeImage, 'type'> & {
type: 'screenshot'
}
diff --git a/common/replay-shared/src/mobile/transformer/transformers.ts b/common/replay-shared/src/mobile/transformer/transformers.ts
index 872bc9b842c6..0dc2390259c1 100644
--- a/common/replay-shared/src/mobile/transformer/transformers.ts
+++ b/common/replay-shared/src/mobile/transformer/transformers.ts
@@ -91,6 +91,8 @@ const BODY_ID = 5
const NAVIGATION_BAR_PARENT_ID = 7
const KEYBOARD_PARENT_ID = 9
export const STATUS_BAR_PARENT_ID = 11
+// icons are <img> too, so extractImgNodeFromMobileIncremental keys off this instead of tag or size
+export const SCREENSHOT_ATTRIBUTE = 'data-posthog-screenshot'
// upper bound on rendered rating stars, guards against absurd `max` values in wireframe data
const MAX_RATING_STARS = 100
@@ -275,6 +277,7 @@ function makeImageElement(
height: wireframe.height,
style: makeStylesString(wireframe),
'data-rrweb-id': wireframe.id,
+ ...(wireframe.type === 'screenshot' ? { [SCREENSHOT_ATTRIBUTE]: 'true' } : {}),
},
id: wireframe.id,
childNodes: children,
diff --git a/common/replay-shared/src/snapshot-processing/patch-meta-event.ts b/common/replay-shared/src/snapshot-processing/patch-meta-event.ts
index 23cfcc445653..4e13cbb15c48 100644
--- a/common/replay-shared/src/snapshot-processing/patch-meta-event.ts
+++ b/common/replay-shared/src/snapshot-processing/patch-meta-event.ts
@@ -1,5 +1,6 @@
import { EventType } from 'posthog-js/rrweb-types'
+import { SCREENSHOT_ATTRIBUTE } from '../mobile/transformer/transformers'
import { RecordingSnapshot } from '../types'
import { isObject } from '../utils'
@@ -56,9 +57,9 @@ export const extractDimensionsFromMobileSnapshot = (snapshot: RecordingSnapshot)
if (
child.type === 2 &&
child.tagName === 'img' &&
- child.attributes?.['data-rrweb-id'] &&
- child.attributes?.width &&
- child.attributes?.height
+ child.attributes?.[SCREENSHOT_ATTRIBUTE] &&
+ child.attributes.width &&
+ child.attributes.height
) {
return {
width: String(child.attributes.width),
diff --git a/common/replay-shared/src/snapshot-processing/process-all-snapshots.ts b/common/replay-shared/src/snapshot-processing/process-all-snapshots.ts
index 2cf65836df38..280a2342a8d3 100644
--- a/common/replay-shared/src/snapshot-processing/process-all-snapshots.ts
+++ b/common/replay-shared/src/snapshot-processing/process-all-snapshots.ts
@@ -1,6 +1,7 @@
import { EventType, eventWithTime, fullSnapshotEvent, IncrementalSource } from 'posthog-js/rrweb-types'
import { transformEventToWeb } from '../mobile'
+import { SCREENSHOT_ATTRIBUTE } from '../mobile/transformer/transformers'
import { noOpTelemetry, ReplayTelemetry } from '../telemetry'
import {
EncodedRecordingSnapshot,
@@ -50,14 +51,7 @@ function extractImgNodeFromMobileIncremental(snapshot: RecordingSnapshot): any |
const checksLimit = Math.min(data.adds.length, 3)
for (let i = 0; i < checksLimit; i++) {
const node = data.adds[i]?.node
- if (
- node &&
- node.type === 2 &&
- node.tagName === 'img' &&
- node.attributes?.['data-rrweb-id'] &&
- node.attributes?.width &&
- node.attributes?.height
- ) {
+ if (node && node.type === 2 && node.tagName === 'img' && node.attributes?.[SCREENSHOT_ATTRIBUTE]) {
return node
}
}
diff --git a/frontend/src/scenes/session-recordings/mobile-replay/__snapshots__/transform.test.ts.snap b/frontend/src/scenes/session-recordings/mobile-replay/__snapshots__/transform.test.ts.snap
index e530be9a39b0..e7ffea002d47 100644
--- a/frontend/src/scenes/session-recordings/mobile-replay/__snapshots__/transform.test.ts.snap
+++ b/frontend/src/scenes/session-recordings/mobile-replay/__snapshots__/transform.test.ts.snap
@@ -957,6 +957,7 @@ exports[`replay/transform transform can process screenshot mutation 1`] = `
"nextId": null,
"node": {
"attributes": {
+ "data-posthog-screenshot": "true",
"data-rrweb-id": 151700670,
"height": 914,
"src": "data:image/png;base64,mutated-image-content",
diff --git a/frontend/src/scenes/session-recordings/mobile-replay/schema/mobile/rr-mobile-schema.json b/frontend/src/scenes/session-recordings/mobile-replay/schema/mobile/rr-mobile-schema.json
index 55ce111b3ab3..ccd2506d21f9 100644
--- a/frontend/src/scenes/session-recordings/mobile-replay/schema/mobile/rr-mobile-schema.json
+++ b/frontend/src/scenes/session-recordings/mobile-replay/schema/mobile/rr-mobile-schema.json
@@ -1014,7 +1014,8 @@
"$ref": "#/definitions/MobileStyles"
},
"type": {
- "$ref": "#/definitions/MobileNodeType"
+ "const": "screenshot",
+ "type": "string"
},
"width": {
"anyOf": [
diff --git a/frontend/src/scenes/session-recordings/player/snapshot-processing/process-all-snapshots.test.ts b/frontend/src/scenes/session-recordings/player/snapshot-processing/process-all-snapshots.test.ts
index 4b43e8b79610..12baf2b07328 100644
--- a/frontend/src/scenes/session-recordings/player/snapshot-processing/process-all-snapshots.test.ts
+++ b/frontend/src/scenes/session-recordings/player/snapshot-processing/process-all-snapshots.test.ts
@@ -802,6 +802,157 @@ describe('process all snapshots', () => {
expect(incrementalSnapshots[1].timestamp).toBe(2000)
})
+ it('does not synthesize a full snapshot when a mutation adds an image wireframe', async () => {
+ const sessionId = 'test-mobile-session'
+
+ const snapshotJson = JSON.stringify({
+ window_id: '1',
+ data: [
+ {
+ type: 2,
+ timestamp: 1000,
+ data: {
+ wireframes: [
+ {
+ id: 1,
+ type: 'text',
+ text: 'hello',
+ width: 400,
+ height: 800,
+ x: 0,
+ y: 0,
+ },
+ ],
+ initialOffset: { top: 0, left: 0 },
+ },
+ },
+ {
+ type: 3,
+ timestamp: 2000,
+ data: {
+ source: 0,
+ adds: [
+ {
+ parentId: 1,
+ wireframe: {
+ id: 2,
+ type: 'image',
+ base64: 'data:image/png;base64,icon',
+ width: 32,
+ height: 32,
+ x: 0,
+ y: 0,
+ },
+ },
+ ],
+ },
+ },
+ ],
+ })
+
+ const parsed = await parseEncodedSnapshots([snapshotJson], sessionId)
+
+ const key = keyForSource({ source: 'blob_v2', blob_key: '0' } as any)
+ const results = await processAllSnapshots(
+ [{ source: 'blob_v2', blob_key: '0' } as any],
+ { [key]: { snapshots: parsed } } as any,
+ { snapshots: {} },
+ () => ({ width: '400', height: '800', href: 'https://example.com' }),
+ sessionId
+ )
+
+ const fullSnapshots = results.filter((r) => r.type === 2)
+ expect(fullSnapshots).toHaveLength(1)
+ expect(fullSnapshots[0].timestamp).toBe(1000)
+ expect(JSON.stringify(fullSnapshots[0].data)).toContain('hello')
+
+ const incrementalSnapshots = results.filter((r) => r.type === 3)
+ expect(incrementalSnapshots).toHaveLength(1)
+ expect(incrementalSnapshots[0].timestamp).toBe(2000)
+ })
+
+ it('does not patch meta from an image wireframe at the root of a full snapshot', async () => {
+ const sessionId = 'test-mobile-session'
+
+ const snapshotJson = JSON.stringify({
+ window_id: '1',
+ data: [
+ {
+ type: 2,
+ timestamp: 1000,
+ data: {
+ wireframes: [
+ {
+ id: 2,
+ type: 'image',
+ base64: 'data:image/png;base64,icon',
+ width: 32,
+ height: 32,
+ x: 0,
+ y: 0,
+ },
+ ],
+ initialOffset: { top: 0, left: 0 },
+ },
+ },
+ ],
+ })
+
+ const parsed = await parseEncodedSnapshots([snapshotJson], sessionId)
+
+ const key = keyForSource({ source: 'blob_v2', blob_key: '0' } as any)
+ const results = await processAllSnapshots(
+ [{ source: 'blob_v2', blob_key: '0' } as any],
+ { [key]: { snapshots: parsed } } as any,
+ { snapshots: {} },
+ () => ({ width: '400', height: '800', href: 'https://example.com' }),
+ sessionId
+ )
+
+ const meta = results.find((r) => r.type === 4)
+ expect(meta?.data).toEqual({ width: 400, height: 800, href: 'https://example.com' })
+ })
+
+ it('does not patch meta from a screenshot wireframe without dimensions', async () => {
+ const sessionId = 'test-mobile-session'
+
+ const snapshotJson = JSON.stringify({
+ window_id: '1',
+ data: [
+ {
+ type: 2,
+ timestamp: 1000,
+ data: {
+ wireframes: [
+ {
+ id: 2,
+ type: 'screenshot',
+ base64: 'data:image/webp;base64,test',
+ x: 0,
+ y: 0,
+ },
+ ],
+ initialOffset: { top: 0, left: 0 },
+ },
+ },
+ ],
+ })
+
+ const parsed = await parseEncodedSnapshots([snapshotJson], sessionId)
+
+ const key = keyForSource({ source: 'blob_v2', blob_key: '0' } as any)
+ const results = await processAllSnapshots(
+ [{ source: 'blob_v2', blob_key: '0' } as any],
+ { [key]: { snapshots: parsed } } as any,
+ { snapshots: {} },
+ () => ({ width: '400', height: '800', href: 'https://example.com' }),
+ sessionId
+ )
+
+ const meta = results.find((r) => r.type === 4)
+ expect(meta?.data).toEqual({ width: 400, height: 800, href: 'https://example.com' })
+ })
+
it('transforms mobile event data during parsing', async () => {
const sessionId = 'test-mobile-session'