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 video and embeds in replays (#114052)

Tue Haulundf9ca35e4277a
diff --git a/common/replay-headless/src/__tests__/unrecorded-content.test.ts b/common/replay-headless/src/__tests__/unrecorded-content.test.ts
index 87b55961ade0..60ffa17b632d 100644
--- a/common/replay-headless/src/__tests__/unrecorded-content.test.ts
+++ b/common/replay-headless/src/__tests__/unrecorded-content.test.ts
@@ -20,6 +20,12 @@ function replayerWith(tagName: string, attributes: Record<string, string>, eleme
function build(tagName: string, attributes: Record<string, string>, events: eventWithTime[]): string | null {
const element = document.createElement(tagName)
+ // rrweb's rebuild sets ordinary attributes on the element and keeps `rr_*` ones in the mirror only.
+ for (const [name, value] of Object.entries(attributes)) {
+ if (!name.startsWith('rr_')) {
+ element.setAttribute(name, value)
+ }
+ }
UnrecordedContentPlugin(events).onBuild?.(element, {
id: NODE_ID,
replayer: replayerWith(tagName, attributes, element),
@@ -72,10 +78,22 @@ describe('UnrecordedContentPlugin', () => {
['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'],
+ ['a video', 'video', { src: 'https://cdn.example.com/clip.mp4' }, [], 'video'],
+ ['an embedded document', 'embed', { src: 'https://cdn.example.com/file.pdf' }, [], 'document'],
+ ['an object', 'object', { data: 'https://cdn.example.com/file.pdf' }, [], 'document'],
+ ['an object holding an image', 'object', { data: 'https://cdn.example.com/logo.svg' }, [], null],
+ ['an embed typed as an image', 'embed', { src: 'https://cdn.example.com/logo', type: 'image/png' }, [], null],
])('labels %s correctly', (_label, tagName, attributes, events, expected) => {
expect(build(tagName, attributes, events)).toBe(expected)
})
+ it('drops the video poster so the label shows', () => {
+ const element = document.createElement('video')
+ element.setAttribute('poster', 'https://cdn.example.com/poster.jpg')
+ UnrecordedContentPlugin([]).onBuild?.(element, { id: NODE_ID, replayer: replayerWith('video', {}, element) })
+ expect(element.hasAttribute('poster')).toBe(false)
+ })
+
it('labels an iframe whose cross-origin src arrives later', () => {
const element = document.createElement('iframe')
const change = attributeChange({ rr_src: 'https://embed.example.com/' })
diff --git a/common/replay-headless/src/unrecorded-content.ts b/common/replay-headless/src/unrecorded-content.ts
index 22f6109b4f01..a858106874c7 100644
--- a/common/replay-headless/src/unrecorded-content.ts
+++ b/common/replay-headless/src/unrecorded-content.ts
@@ -4,11 +4,13 @@ import { EventType, IncrementalSource, type eventWithTime } from 'posthog-js/rrw
/** 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'
+type UnrecordedKind = 'embed' | 'canvas' | 'video' | 'document'
const LABELS: Record<UnrecordedKind, string> = {
embed: 'Embedded page from another site, not recorded',
canvas: 'Canvas, not recorded',
+ video: 'Video, not recorded',
+ document: 'Embedded document, not recorded',
}
function labelImage(text: string): string {
@@ -34,6 +36,10 @@ function ruleFor(selector: string, kind: UnrecordedKind): string {
export const UNRECORDED_STYLE_RULES = [
ruleFor(`iframe[${UNRECORDED_ATTRIBUTE}="embed"]`, 'embed'),
ruleFor(`canvas[${UNRECORDED_ATTRIBUTE}="canvas"]`, 'canvas'),
+ ruleFor(`video[${UNRECORDED_ATTRIBUTE}="video"]`, 'video'),
+ // Chrome forces native controls on media in a scriptless document, and their loading overlay covers the label.
+ `video[${UNRECORDED_ATTRIBUTE}="video"]::-webkit-media-controls { display: none !important; }`,
+ ruleFor(`:is(embed, object)[${UNRECORDED_ATTRIBUTE}="document"]`, 'document'),
// 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.
@@ -79,18 +85,39 @@ export function scanRecordedContent(events: eventWithTime[]): RecordedContent {
return { drawnCanvasIds, attachedIframeIds }
}
+const IMAGE_URL = /\.(svg|png|jpe?g|gif|webp|avif)([?#]|$)/i
+
+/** An image in an embed or object still loads in the replay, and a transparent one would show the label through it. */
+function isImageDocument(element: Element): boolean {
+ const url = element.getAttribute('src') ?? element.getAttribute('data') ?? ''
+ return (element.getAttribute('type') ?? '').startsWith('image/') || IMAGE_URL.test(url)
+}
+
/**
- * 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.
+ * Labels the elements a replay can only show as blank: a cross-origin iframe whose page was not recorded, a canvas
+ * the recording holds no pixels for, and every video, embed and object, whose media the rasterizer never loads.
+ * 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 }) => {
+ const element = node as Element
+ if (node.nodeName === 'VIDEO') {
+ // A poster paints over the label, and a still frame that never plays reads as a stuck player.
+ element.removeAttribute('poster')
+ element.setAttribute(UNRECORDED_ATTRIBUTE, 'video')
+ return
+ }
+ if (node.nodeName === 'EMBED' || node.nodeName === 'OBJECT') {
+ if (!isImageDocument(element)) {
+ element.setAttribute(UNRECORDED_ATTRIBUTE, 'document')
+ }
+ return
+ }
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)) {
diff --git a/products/replay_vision/backend/temporal/scanners/prompts/preamble.jinja b/products/replay_vision/backend/temporal/scanners/prompts/preamble.jinja
index d4302a0e8aa4..f177e71205a0 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. 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.
+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, embedded document, canvas, or video 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. Mention the box only when the missing content keeps you from judging the session.
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.