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-vision): label unrecorded iframes and canvases in rendered replays (#113885)

Tue Haulundbee4d3be2771
diff --git a/common/replay-headless/src/__tests__/unrecorded-content.test.ts b/common/replay-headless/src/__tests__/unrecorded-content.test.ts
new file mode 100644
index 000000000000..87b55961ade0
--- /dev/null
+++ b/common/replay-headless/src/__tests__/unrecorded-content.test.ts
@@ -0,0 +1,85 @@
+import type { Replayer } from 'posthog-js/rrweb'
+import type { eventWithTime } from 'posthog-js/rrweb-types'
+
+import { UNRECORDED_ATTRIBUTE, UnrecordedContentPlugin } from '../unrecorded-content'
+
+// posthog-js/* ships ESM the test transform can't load; these mirror rrweb's enum values.
+jest.mock('posthog-js/rrweb-types', () => ({
+ EventType: { IncrementalSnapshot: 3 },
+ IncrementalSource: { Mutation: 0, CanvasMutation: 9 },
+}))
+
+const NODE_ID = 7
+
+function replayerWith(tagName: string, attributes: Record<string, string>, element: Element): Replayer {
+ const meta = { type: 2, tagName, attributes, childNodes: [], id: NODE_ID }
+ return {
+ getMirror: () => ({ getMeta: () => meta, getNode: (id: number) => (id === NODE_ID ? element : null) }),
+ } as unknown as Replayer
+}
+
+function build(tagName: string, attributes: Record<string, string>, events: eventWithTime[]): string | null {
+ const element = document.createElement(tagName)
+ UnrecordedContentPlugin(events).onBuild?.(element, {
+ id: NODE_ID,
+ replayer: replayerWith(tagName, attributes, element),
+ })
+ return element.getAttribute(UNRECORDED_ATTRIBUTE)
+}
+
+function attributeChange(attributes: Record<string, string | null>): eventWithTime {
+ return {
+ type: 3,
+ timestamp: 2000,
+ data: { source: 0, texts: [], removes: [], adds: [], attributes: [{ id: NODE_ID, attributes }] },
+ } as unknown as eventWithTime
+}
+
+const drawn = {
+ type: 3,
+ timestamp: 2000,
+ data: { source: 9, id: NODE_ID, type: 0, commands: [] },
+} as unknown as eventWithTime
+
+const imageSetLater = attributeChange({ rr_dataURL: 'data:image/png;base64,AA==' })
+
+const iframePageRecorded = {
+ type: 3,
+ timestamp: 2000,
+ data: {
+ source: 0,
+ texts: [],
+ removes: [],
+ attributes: [],
+ adds: [{ parentId: NODE_ID, nextId: null, node: { type: 0, childNodes: [], id: 99 } }],
+ isAttachIframe: true,
+ },
+} as unknown as eventWithTime
+
+describe('UnrecordedContentPlugin', () => {
+ it.each([
+ ['a cross-origin iframe', 'iframe', { rr_src: 'https://embed.example.com/' }, [], 'embed'],
+ ['a recorded iframe', 'iframe', {}, [], null],
+ [
+ 'a cross-origin iframe whose page was recorded',
+ 'iframe',
+ { rr_src: 'https://embed.example.com/' },
+ [iframePageRecorded],
+ null,
+ ],
+ ['a canvas with no pixels recorded', 'canvas', {}, [], 'canvas'],
+ ['a canvas with recorded drawing', 'canvas', {}, [drawn], null],
+ ['a canvas with a snapshot image', 'canvas', { rr_dataURL: 'data:image/png;base64,AA==' }, [], null],
+ ['a canvas whose image arrives later', 'canvas', {}, [imageSetLater], null],
+ ['a canvas whose image is removed', 'canvas', {}, [attributeChange({ rr_dataURL: null })], 'canvas'],
+ ])('labels %s correctly', (_label, tagName, attributes, events, expected) => {
+ expect(build(tagName, attributes, events)).toBe(expected)
+ })
+
+ it('labels an iframe whose cross-origin src arrives later', () => {
+ const element = document.createElement('iframe')
+ const change = attributeChange({ rr_src: 'https://embed.example.com/' })
+ UnrecordedContentPlugin([change]).handler?.(change, false, { replayer: replayerWith('iframe', {}, element) })
+ expect(element.getAttribute(UNRECORDED_ATTRIBUTE)).toBe('embed')
+ })
+})
diff --git a/common/replay-headless/src/replayer-factory.ts b/common/replay-headless/src/replayer-factory.ts
index b71c0b35b89c..22a46e36de9d 100644
--- a/common/replay-headless/src/replayer-factory.ts
+++ b/common/replay-headless/src/replayer-factory.ts
@@ -23,6 +23,7 @@ import { loadAllSources } from './data-loader'
import type { HostBridge } from './host-bridge'
import type { PlaybackWindow } from './playback-controller'
import type { PlayerConfig, ViewportEvent } from './types'
+import { UNRECORDED_STYLE_RULES, UnrecordedContentPlugin } from './unrecorded-content'
export interface ReplayerWindow extends PlaybackWindow {
/** The element the window's replayer renders into, shown only while the window is on screen. */
@@ -161,10 +162,17 @@ export async function createReplayers(
insertStyleRules: [
...(COMMON_REPLAYER_CONFIG.insertStyleRules || []),
...speedDependentStyleRules(config.playbackSpeed),
+ ...UNRECORDED_STYLE_RULES,
],
mouseTail: config.mouseTail,
useVirtualDom: false,
- plugins: [CorsPlugin, HLSPlayerPlugin, AudioMuteReplayerPlugin(true), CanvasReplayerPlugin(windowEvents)],
+ plugins: [
+ CorsPlugin,
+ HLSPlayerPlugin,
+ AudioMuteReplayerPlugin(true),
+ CanvasReplayerPlugin(windowEvents),
+ UnrecordedContentPlugin(windowEvents),
+ ],
speed: config.playbackSpeed,
})
windows.push({
diff --git a/common/replay-headless/src/unrecorded-content.ts b/common/replay-headless/src/unrecorded-content.ts
new file mode 100644
index 000000000000..22f6109b4f01
--- /dev/null
+++ b/common/replay-headless/src/unrecorded-content.ts
@@ -0,0 +1,118 @@
+import type { ReplayPlugin } from 'posthog-js/rrweb'
+import { EventType, IncrementalSource, type eventWithTime } from 'posthog-js/rrweb-types'
+
+/** Marks a replayed element the recording holds no content for, so the style rule can label it. */
+export const UNRECORDED_ATTRIBUTE = 'data-ph-unrecorded'
+
+type UnrecordedKind = 'embed' | 'canvas'
+
+const LABELS: Record<UnrecordedKind, string> = {
+ embed: 'Embedded page from another site, not recorded',
+ canvas: 'Canvas, not recorded',
+}
+
+function labelImage(text: string): string {
+ const svg =
+ `<svg xmlns="http://www.w3.org/2000/svg" width="440" height="44">` +
+ `<rect width="440" height="44" rx="6" fill="#ffffff" stroke="#6b7280"/>` +
+ `<text x="220" y="28" text-anchor="middle" font-family="sans-serif" font-size="17" fill="#374151">${text}</text>` +
+ `</svg>`
+ return `url("data:image/svg+xml,${encodeURIComponent(svg)}")`
+}
+
+function ruleFor(selector: string, kind: UnrecordedKind): string {
+ // Drawn as the element's own background, behind anything the replay paints into it. A light
+ // color-scheme keeps an empty iframe document transparent even when the page uses a dark one.
+ return `${selector} {
+ background: ${labelImage(LABELS[kind])} center / min(440px, 100%) auto no-repeat, repeating-linear-gradient(135deg, #f3f4f6 0 12px, #e5e7eb 12px 24px) !important;
+ outline: 2px dashed #6b7280 !important;
+ outline-offset: -2px !important;
+ color-scheme: light !important;
+ }`
+}
+
+export const UNRECORDED_STYLE_RULES = [
+ ruleFor(`iframe[${UNRECORDED_ATTRIBUTE}="embed"]`, 'embed'),
+ ruleFor(`canvas[${UNRECORDED_ATTRIBUTE}="canvas"]`, 'canvas'),
+ // The replay document runs no scripts, so a canvas renders as its empty fallback content and collapses to
+ // nothing. A box sized from the canvas's own attributes gives the label room. The layer lets any page rule
+ // win, so a canvas the page hides stays hidden.
+ `@layer ph-unrecorded {
+ canvas[${UNRECORDED_ATTRIBUTE}="canvas"]:not([hidden]) {
+ display: inline-block;
+ width: attr(width px, 300px);
+ height: attr(height px, 150px);
+ }
+ }`,
+]
+
+interface RecordedContent {
+ /** Canvases the recording has pixels for: a drawing command or a snapshot image set by a mutation. */
+ drawnCanvasIds: Set<number>
+ /** Cross-origin iframes whose page was recorded too, because the customer enabled cross-origin iframe recording. */
+ attachedIframeIds: Set<number>
+}
+
+export function scanRecordedContent(events: eventWithTime[]): RecordedContent {
+ const drawnCanvasIds = new Set<number>()
+ const attachedIframeIds = new Set<number>()
+ for (const event of events) {
+ if (event.type !== EventType.IncrementalSnapshot) {
+ continue
+ }
+ const data = event.data
+ if (data.source === IncrementalSource.CanvasMutation) {
+ drawnCanvasIds.add(data.id)
+ } else if (data.source === IncrementalSource.Mutation) {
+ if (data.isAttachIframe) {
+ for (const add of data.adds) {
+ attachedIframeIds.add(add.parentId)
+ }
+ }
+ for (const change of data.attributes) {
+ if (typeof change.attributes?.rr_dataURL === 'string') {
+ drawnCanvasIds.add(change.id)
+ }
+ }
+ }
+ }
+ return { drawnCanvasIds, attachedIframeIds }
+}
+
+/**
+ * Labels the elements a replay can only show as blank: a cross-origin iframe whose page was not recorded, and a
+ * canvas the recording holds no pixels for. Without a label the blank area reads as content that failed to load.
+ */
+export function UnrecordedContentPlugin(events: eventWithTime[]): ReplayPlugin {
+ const { drawnCanvasIds, attachedIframeIds } = scanRecordedContent(events)
+ return {
+ onBuild: (node, { id, replayer }) => {
+ if (node.nodeName !== 'IFRAME' && node.nodeName !== 'CANVAS') {
+ return
+ }
+ const element = node as Element
+ const meta = replayer.getMirror().getMeta(element as Node)
+ const attributes = meta && 'attributes' in meta ? meta.attributes : {}
+ if (element.nodeName === 'IFRAME' && attributes.rr_src && !attachedIframeIds.has(id)) {
+ element.setAttribute(UNRECORDED_ATTRIBUTE, 'embed')
+ } else if (element.nodeName === 'CANVAS' && !attributes.rr_dataURL && !drawnCanvasIds.has(id)) {
+ element.setAttribute(UNRECORDED_ATTRIBUTE, 'canvas')
+ }
+ },
+ // An iframe can get its cross-origin `src` after it was built, as a recorded attribute change.
+ handler: (event, _isSync, { replayer }) => {
+ if (event.type !== EventType.IncrementalSnapshot || event.data.source !== IncrementalSource.Mutation) {
+ return
+ }
+ for (const change of event.data.attributes) {
+ if (typeof change.attributes?.rr_src !== 'string' || attachedIframeIds.has(change.id)) {
+ continue
+ }
+ const node = replayer.getMirror().getNode(change.id)
+ if (node?.nodeName === 'IFRAME') {
+ ;(node as Element).setAttribute(UNRECORDED_ATTRIBUTE, 'embed')
+ }
+ }
+ },
+ }
+}
diff --git a/products/replay_vision/backend/temporal/scanners/prompts/preamble.jinja b/products/replay_vision/backend/temporal/scanners/prompts/preamble.jinja
index 0088c7922305..d4302a0e8aa4 100644
--- a/products/replay_vision/backend/temporal/scanners/prompts/preamble.jinja
+++ b/products/replay_vision/backend/temporal/scanners/prompts/preamble.jinja
@@ -19,7 +19,7 @@ The recording is not exactly what the user saw. Before you call anything on scre
Privacy masking. Masked elements render as solid or striped black or grey boxes, and masked input text shows as asterisks (`*`). The customer configured this on purpose: it is not a bug, missing content, or a failed load, and the masked characters carry no meaning. A whole image, video, or embedded player can be one masked box for as long as the user looks at it, and that alone does not mean it failed. Masking can also hide a real failure, so decide from what is still recorded: a scrubber or loading overlay outside the box, the events, and the requests. An error or failed request for that media, a loading state that never clears, or a user who retries, reloads, or rage-clicks the area points to a real failure; an advancing scrubber or a cleared overlay points to success. When the signs do not decide it, say the content is masked, not that it failed.
-Unrecorded content. Anything drawn on a canvas (maps, charts, editors, document viewers), pages from another site embedded in an iframe (payment forms, sign-in popups, embedded forms), and video playback are often not recorded at all. They replay as blank, black, or grey areas even when the user saw them working. Judge them as you judge masked content: from the events, the requests, and what the user does next.
+Unrecorded content. Anything drawn on a canvas (maps, charts, editors, document viewers), pages from another site embedded in an iframe (payment forms, sign-in popups, embedded forms), and video playback are often not recorded at all. They replay as blank, black, or grey areas even when the user saw them working. An embedded page or canvas the recording holds nothing for replays as a striped box labeled "not recorded". It shows nothing about whether that content loaded. Judge all of these as you judge masked content: from the events, the requests, and what the user does next.
Reconstruction. The replay rebuilds each page from DOM snapshots, so validation or error text hidden in the page's HTML can render visible, layouts can look broken while the user saw a normal page, and hover-only UI may not replay. Before treating an on-screen error as something the user experienced, corroborate it: an input, click, or submit around that moment that it plausibly answers, or a failed request or an exception event. Never infer that the user typed or submitted from an error message alone, and treat an error that nothing corroborates as likely pre-rendered markup, not user-facing friction.