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(desktop): mobile watch replay evidence in a modal player (#96467)

Tom Owersbba0e9b2396e
diff --git a/products/desktop/apps/mobile/package.json b/products/desktop/apps/mobile/package.json
index 3408ade4f959..5a2e6f4734a9 100644
--- a/products/desktop/apps/mobile/package.json
+++ b/products/desktop/apps/mobile/package.json
@@ -77,6 +77,7 @@
"expo-splash-screen": "~57.0.5",
"expo-status-bar": "~57.0.1",
"expo-system-ui": "~57.0.1",
+ "expo-video": "~57.0.3",
"expo-web-browser": "^57.0.2",
"highlight.js": "^11.11.1",
"nativewind": "^4.2.1",
diff --git a/products/desktop/apps/mobile/src/features/inbox/components/SignalCard.tsx b/products/desktop/apps/mobile/src/features/inbox/components/SignalCard.tsx
index 62e6df2de3be..fa78c6e217e4 100644
--- a/products/desktop/apps/mobile/src/features/inbox/components/SignalCard.tsx
+++ b/products/desktop/apps/mobile/src/features/inbox/components/SignalCard.tsx
@@ -1,4 +1,5 @@
import { Text } from "@components/text";
+import type { RecordingExport } from "@posthog/api-client/posthog-client";
import {
EXTERNAL_INBOX_SOURCE_BY_PRODUCT,
type SourceProduct,
@@ -7,6 +8,7 @@ import type {
Signal,
SignalFindingContent,
} from "@posthog/shared/domain-types";
+import { useQuery } from "@tanstack/react-query";
import {
ArrowSquareOut,
Bug,
@@ -19,18 +21,26 @@ import {
FirstAid,
GithubLogo,
LinkSimple,
+ Play,
Plug,
Question,
Robot,
WarningCircle,
} from "phosphor-react-native";
-import { useState } from "react";
+import { type ReactNode, useState } from "react";
import { Pressable, View } from "react-native";
+import { useAuthStore } from "@/features/auth";
import { MarkdownText } from "@/features/chat/components/MarkdownText";
import { formatRelativeTime } from "@/lib/format";
import { openExternalUrl } from "@/lib/openExternalUrl";
+import { getPostHogApiClient } from "@/lib/posthogApiClient";
import { useThemeColors } from "@/lib/theme";
+import {
+ colonOffsetFromSeconds,
+ colonOffsetToSeconds,
+} from "../recordingOffset";
import { sourceLine } from "../utils";
+import { WatchRecordingSheet } from "./WatchRecordingSheet";
const COLLAPSE_THRESHOLD = 280;
@@ -178,6 +188,152 @@ function VerifiedBadge({ verified }: { verified: boolean }) {
);
}
+interface RecordingEvidence {
+ sessionId: string;
+ exportedAssetId: number | null;
+ seekSeconds: number | null;
+}
+
+function extractRecordingEvidence(signal: Signal): RecordingEvidence | null {
+ const extra = signal.extra ?? {};
+ const sessionId =
+ typeof extra.session_id === "string" ? extra.session_id : null;
+ if (!sessionId) return null;
+
+ const isSessionProblem =
+ signal.source_product === "session_replay" && "segment_title" in extra;
+ const isScannerFinding =
+ signal.source_product === "replay_vision" && "scanner_name" in extra;
+ if (!isSessionProblem && !isScannerFinding) return null;
+
+ const exportedAssetId =
+ typeof extra.exported_asset_id === "number"
+ ? extra.exported_asset_id
+ : null;
+
+ let seekSeconds: number | null = null;
+ const startTime = extra.start_time;
+ if (typeof startTime === "number") {
+ seekSeconds = startTime;
+ } else if (typeof startTime === "string") {
+ seekSeconds = colonOffsetToSeconds(startTime);
+ }
+
+ return { sessionId, exportedAssetId, seekSeconds };
+}
+
+function EvidenceActionPill({
+ glyph,
+ label,
+ onPress,
+}: {
+ glyph: ReactNode;
+ label: string;
+ onPress: () => void;
+}) {
+ return (
+ <Pressable
+ onPress={onPress}
+ hitSlop={6}
+ className="mt-2 flex-row items-center gap-1.5 self-start rounded-full border border-gray-5 bg-gray-2 py-1 pr-2.5 pl-1.5 active:opacity-70"
+ >
+ <View className="size-4 items-center justify-center rounded-full bg-accent-9">
+ {glyph}
+ </View>
+ <Text className="font-medium text-[12px] text-gray-11">{label}</Text>
+ </Pressable>
+ );
+}
+
+function WatchRecordingAction({ evidence }: { evidence: RecordingEvidence }) {
+ const themeColors = useThemeColors();
+ const [open, setOpen] = useState(false);
+ const { sessionId, exportedAssetId, seekSeconds } = evidence;
+ const { projectId, oauthAccessToken, cloudRegion, getCloudUrlFromRegion } =
+ useAuthStore();
+
+ const playerUrl =
+ cloudRegion && projectId
+ ? `${getCloudUrlFromRegion(cloudRegion)}/project/${projectId}/replay/${encodeURIComponent(sessionId)}${seekSeconds != null ? `?t=${seekSeconds}` : ""}`
+ : null;
+
+ const exportQuery = useQuery<RecordingExport | null>({
+ queryKey: ["recording-export", projectId, exportedAssetId, sessionId],
+ queryFn: async () => {
+ if (!projectId) return null;
+ const client = getPostHogApiClient();
+ return exportedAssetId != null
+ ? await client.getRecordingExport(projectId, exportedAssetId)
+ : await client.findRecordingExport(projectId, sessionId);
+ },
+ enabled: !!projectId && !!oauthAccessToken,
+ staleTime: Infinity,
+ });
+ const clip = exportQuery.data ?? null;
+
+ const contentQuery = useQuery<string | null>({
+ queryKey: ["recording-clip-url", projectId, clip?.id],
+ queryFn: async () => {
+ if (!projectId || clip == null) return null;
+ return await getPostHogApiClient().getExportContentUrl(
+ projectId,
+ clip.id,
+ );
+ },
+ enabled: open && !!projectId && clip != null,
+ staleTime: Infinity,
+ });
+
+ const momentLabel =
+ seekSeconds != null ? colonOffsetFromSeconds(seekSeconds) : null;
+ const pillLabel = momentLabel
+ ? `Watch at ${momentLabel}`
+ : "Watch the recording";
+
+ const hasNoClip = exportQuery.isFetched && clip == null;
+ const clipUnavailable = contentQuery.isError || contentQuery.data === null;
+ const clipPending = !clipUnavailable && contentQuery.data == null;
+
+ if (exportQuery.isError || hasNoClip) {
+ if (!playerUrl) return null;
+ return (
+ <EvidenceActionPill
+ glyph={<ArrowSquareOut size={9} color="#ffffff" weight="bold" />}
+ label={pillLabel}
+ onPress={() => openExternalUrl(playerUrl)}
+ />
+ );
+ }
+
+ return (
+ <>
+ <EvidenceActionPill
+ glyph={
+ <Play
+ size={9}
+ color={themeColors.gray[1]}
+ weight="fill"
+ style={{ marginLeft: 0.5 }}
+ />
+ }
+ label={pillLabel}
+ onPress={() => setOpen(true)}
+ />
+
+ <WatchRecordingSheet
+ visible={open}
+ clip={clip}
+ contentUrl={contentQuery.data ?? null}
+ contentPending={clipPending}
+ contentUnavailable={clipUnavailable}
+ seekSeconds={seekSeconds ?? null}
+ playerUrl={playerUrl}
+ onClose={() => setOpen(false)}
+ />
+ </>
+ );
+}
+
interface SignalCardProps {
signal: Signal;
finding?: SignalFindingContent;
@@ -197,6 +353,7 @@ export function SignalCard({ signal, finding }: SignalCardProps) {
typeof extra.url === "string" ? (extra.url as string) : null;
const externalUrl = issueUrl ?? ticketUrl ?? null;
+ const recordingEvidence = extractRecordingEvidence(signal);
const timestampMs = signal.timestamp ? Date.parse(signal.timestamp) : NaN;
const hasTimestamp = !Number.isNaN(timestampMs) && timestampMs <= Date.now();
@@ -227,6 +384,10 @@ export function SignalCard({ signal, finding }: SignalCardProps) {
{/* Body */}
<CollapsibleBody body={signal.content} />
+ {recordingEvidence && (
+ <WatchRecordingAction evidence={recordingEvidence} />
+ )}
+
{/* Footer meta (lightweight, no source-specific extras for v1) */}
{(issueNumber !== null || externalUrl) && (
<View className="mt-2 flex-row items-center gap-3">
diff --git a/products/desktop/apps/mobile/src/features/inbox/components/WatchRecordingSheet.tsx b/products/desktop/apps/mobile/src/features/inbox/components/WatchRecordingSheet.tsx
new file mode 100644
index 000000000000..71c1343c9c13
--- /dev/null
+++ b/products/desktop/apps/mobile/src/features/inbox/components/WatchRecordingSheet.tsx
@@ -0,0 +1,161 @@
+import { Text } from "@components/text";
+import type { RecordingExport } from "@posthog/api-client/posthog-client";
+import { useVideoPlayer, VideoView } from "expo-video";
+import { ArrowSquareOut, X } from "phosphor-react-native";
+import { useMemo } from "react";
+import {
+ ActivityIndicator,
+ Modal,
+ Pressable,
+ useWindowDimensions,
+ View,
+} from "react-native";
+import { openExternalUrl } from "@/lib/openExternalUrl";
+import { clipTimeForMoment } from "../recordingClipTime";
+import { colonOffsetFromSeconds } from "../recordingOffset";
+
+interface WatchRecordingSheetProps {
+ visible: boolean;
+ clip: RecordingExport | null;
+ contentUrl: string | null;
+ contentPending: boolean;
+ contentUnavailable: boolean;
+ seekSeconds?: number | null;
+ playerUrl?: string | null;
+ onClose: () => void;
+}
+
+export function WatchRecordingSheet({
+ visible,
+ clip,
+ contentUrl,
+ contentPending,
+ contentUnavailable,
+ seekSeconds,
+ playerUrl,
+ onClose,
+}: WatchRecordingSheetProps) {
+ const { width, height } = useWindowDimensions();
+
+ const targetClipTime = useMemo(() => {
+ if (clip == null || seekSeconds == null) return null;
+ return clipTimeForMoment(clip, seekSeconds);
+ }, [clip, seekSeconds]);
+ const momentReachable = seekSeconds == null ? null : targetClipTime != null;
+ const momentLabel =
+ seekSeconds != null ? colonOffsetFromSeconds(seekSeconds) : null;
+
+ const player = useVideoPlayer(contentUrl, (p) => {
+ p.muted = true;
+ if (targetClipTime != null) p.currentTime = targetClipTime;
+ p.play();
+ });
+
+ const seekToMoment = () => {
+ if (targetClipTime == null) return;
+ const duration = player.duration;
+ player.currentTime =
+ duration > 0 ? Math.min(targetClipTime, duration) : targetClipTime;
+ player.play();
+ };
+
+ const videoWidth = Math.min(width - 32, 720);
+ const videoHeight = Math.min(videoWidth * (9 / 16), height * 0.6);
+
+ return (
+ <Modal
+ visible={visible}
+ transparent
+ animationType="fade"
+ onRequestClose={onClose}
+ statusBarTranslucent
+ >
+ <Pressable
+ className="flex-1 items-center justify-center bg-black/80 px-4"
+ onPress={onClose}
+ >
+ <Pressable onPress={() => {}} className="w-full max-w-[720px] gap-3">
+ <View className="flex-row items-center justify-between">
+ <View className="flex-1 pr-3">
+ <Text className="font-semibold text-[16px] text-white">
+ Session recording
+ </Text>
+ <Text
+ className="mt-0.5 text-[12px] text-white/70"
+ numberOfLines={2}
+ >
+ {describeClipStatus(momentLabel, momentReachable)}
+ </Text>
+ </View>
+ <Pressable
+ onPress={onClose}
+ hitSlop={12}
+ className="rounded-full bg-white/10 p-2 active:opacity-70"
+ accessibilityLabel="Close"
+ >
+ <X size={16} color="#ffffff" weight="bold" />
+ </Pressable>
+ </View>
+
+ <View
+ className="items-center justify-center overflow-hidden rounded-xl bg-black"
+ style={{ width: videoWidth, height: videoHeight }}
+ >
+ {contentUnavailable ? (
+ <Text className="px-6 text-center text-[13px] text-white/70">
+ This clip is no longer available.
+ </Text>
+ ) : contentPending || contentUrl == null ? (
+ <ActivityIndicator color="#ffffff" />
+ ) : (
+ <VideoView
+ player={player}
+ style={{ width: videoWidth, height: videoHeight }}
+ nativeControls
+ contentFit="contain"
+ />
+ )}
+ </View>
+
+ <View className="flex-row items-center justify-between">
+ {momentLabel && momentReachable === true ? (
+ <Pressable
+ onPress={seekToMoment}
+ hitSlop={6}
+ className="rounded-full bg-white/10 px-3 py-2 active:opacity-70"
+ >
+ <Text className="text-[12px] text-white">
+ Back to {momentLabel}
+ </Text>
+ </Pressable>
+ ) : (
+ <View />
+ )}
+ {playerUrl && (
+ <Pressable
+ onPress={() => openExternalUrl(playerUrl)}
+ hitSlop={6}
+ className="flex-row items-center gap-1 active:opacity-70"
+ >
+ <Text className="text-[12px] text-white/80">
+ Open in PostHog
+ </Text>
+ <ArrowSquareOut size={12} color="#ffffff" />
+ </Pressable>
+ )}
+ </View>
+ </Pressable>
+ </Pressable>
+ </Modal>
+ );
+}
+
+function describeClipStatus(
+ momentLabel: string | null,
+ momentReachable: boolean | null,
+): string {
+ if (momentLabel == null) return "The rendered clip from this session.";
+ if (momentReachable === false)
+ return `The clip stops before ${momentLabel}. Open the session in PostHog to reach that moment.`;
+ return `The rendered clip, at ${momentLabel} in the session.`;
+}
diff --git a/products/desktop/apps/mobile/src/features/inbox/recordingClipTime.test.ts b/products/desktop/apps/mobile/src/features/inbox/recordingClipTime.test.ts
new file mode 100644
index 000000000000..6418c103513b
--- /dev/null
+++ b/products/desktop/apps/mobile/src/features/inbox/recordingClipTime.test.ts
@@ -0,0 +1,95 @@
+import type {
+ RecordingClipSegment,
+ RecordingExport,
+} from "@posthog/api-client/posthog-client";
+import { describe, expect, it } from "vitest";
+import { clipTimeForMoment } from "./recordingClipTime";
+
+function makeClip(overrides: Partial<RecordingExport> = {}): RecordingExport {
+ return {
+ id: 1,
+ startOffsetSeconds: 0,
+ endOffsetSeconds: null,
+ clipDurationSeconds: null,
+ truncated: false,
+ segments: [],
+ ...overrides,
+ };
+}
+
+function segment(
+ sessionFrom: number,
+ sessionTo: number,
+ clipFrom: number,
+ clipTo: number,
+ active = true,
+): RecordingClipSegment {
+ return {
+ sessionFromSeconds: sessionFrom,
+ sessionToSeconds: sessionTo,
+ clipFromSeconds: clipFrom,
+ clipToSeconds: clipTo,
+ active,
+ };
+}
+
+describe("clipTimeForMoment", () => {
+ describe("a render that kept every stretch", () => {
+ it.each([
+ ["a whole-session clip", 0, 120, 120],
+ ["a clip whose window opens late", 100, 160, 60],
+ ])("maps %s", (_label, startOffset, sessionOffset, expected) => {
+ const clip = makeClip({
+ startOffsetSeconds: startOffset,
+ clipDurationSeconds: 300,
+ });
+ expect(clipTimeForMoment(clip, sessionOffset)).toBe(expected);
+ });
+
+ it.each([
+ ["the moment sits before the window", 100, 40],
+ ["the moment sits past the clip's end", 0, 400],
+ ])("returns null when %s", (_label, startOffset, sessionOffset) => {
+ const clip = makeClip({
+ startOffsetSeconds: startOffset,
+ clipDurationSeconds: 300,
+ });
+ expect(clipTimeForMoment(clip, sessionOffset)).toBeNull();
+ });
+ });
+
+ describe("a render that dropped idle stretches", () => {
+ const clip = makeClip({
+ clipDurationSeconds: 120,
+ segments: [
+ segment(0, 60, 0, 60),
+ segment(60, 300, 60, 60, false),
+ segment(300, 360, 60, 120),
+ ],
+ });
+
+ it.each([
+ ["inside the first active stretch", 30, 30],
+ ["at the boundary into the dropped stretch", 60, 60],
+ ["inside the second active stretch", 330, 90],
+ ["at the very end of the clip", 360, 120],
+ ])("maps a moment %s", (_label, sessionOffset, expected) => {
+ expect(clipTimeForMoment(clip, sessionOffset)).toBe(expected);
+ });
+
+ it("resolves a moment inside a dropped stretch to the next frame", () => {
+ expect(clipTimeForMoment(clip, 200)).toBe(60);
+ });
+
+ it("returns null for a moment the render never reached", () => {
+ expect(clipTimeForMoment(clip, 420)).toBeNull();
+ });
+
+ it("returns the clip start for a moment before the first stretch", () => {
+ const late = makeClip({
+ segments: [segment(100, 160, 0, 60)],
+ });
+ expect(clipTimeForMoment(late, 40)).toBe(0);
+ });
+ });
+});
diff --git a/products/desktop/apps/mobile/src/features/inbox/recordingClipTime.ts b/products/desktop/apps/mobile/src/features/inbox/recordingClipTime.ts
new file mode 100644
index 000000000000..965d3b7771de
--- /dev/null
+++ b/products/desktop/apps/mobile/src/features/inbox/recordingClipTime.ts
@@ -0,0 +1,34 @@
+import type { RecordingExport } from "@posthog/api-client/posthog-client";
+
+export function clipTimeForMoment(
+ clip: RecordingExport,
+ sessionOffsetSeconds: number,
+): number | null {
+ if (clip.segments.length === 0) {
+ const clipTime = sessionOffsetSeconds - clip.startOffsetSeconds;
+ if (clipTime < 0) return null;
+ if (
+ clip.clipDurationSeconds != null &&
+ clipTime > clip.clipDurationSeconds
+ ) {
+ return null;
+ }
+ return clipTime;
+ }
+
+ for (const segment of clip.segments) {
+ if (sessionOffsetSeconds < segment.sessionFromSeconds) {
+ return segment.clipFromSeconds;
+ }
+ const sessionTo = segment.sessionToSeconds ?? segment.sessionFromSeconds;
+ if (sessionOffsetSeconds <= sessionTo) {
+ if (!segment.active) return segment.clipFromSeconds;
+ const intoSegment = sessionOffsetSeconds - segment.sessionFromSeconds;
+ return Math.min(
+ segment.clipFromSeconds + intoSegment,
+ segment.clipToSeconds,
+ );
+ }
+ }
+ return null;
+}
diff --git a/products/desktop/apps/mobile/src/features/inbox/recordingOffset.test.ts b/products/desktop/apps/mobile/src/features/inbox/recordingOffset.test.ts
new file mode 100644
index 000000000000..c0131ac86ca2
--- /dev/null
+++ b/products/desktop/apps/mobile/src/features/inbox/recordingOffset.test.ts
@@ -0,0 +1,42 @@
+import { describe, expect, it } from "vitest";
+import {
+ colonOffsetFromSeconds,
+ colonOffsetToSeconds,
+} from "./recordingOffset";
+
+describe("colonOffsetToSeconds", () => {
+ it.each([
+ ["MM:SS", "01:47", 107],
+ ["HH:MM:SS", "1:02:03", 3723],
+ ["zero-padded minutes", "10:00", 600],
+ ])("parses %s", (_label, offset, expected) => {
+ expect(colonOffsetToSeconds(offset)).toBe(expected);
+ });
+
+ it.each([
+ ["a bare number", "47"],
+ ["too many parts", "1:2:3:4"],
+ ["a non-numeric part", "ab:cd"],
+ ["a negative part", "-1:00"],
+ ["an empty segment", "1::2"],
+ ["a hex literal", "0x10:00"],
+ ["scientific notation", "1e308:00"],
+ ["padded whitespace", " 1 : 2 "],
+ ["seconds of 60", "1:60"],
+ ["minutes of 60 in HH:MM:SS", "1:60:00"],
+ ])("returns null for %s", (_label, offset) => {
+ expect(colonOffsetToSeconds(offset)).toBeNull();
+ });
+});
+
+describe("colonOffsetFromSeconds", () => {
+ it.each([
+ ["under an hour", 107, "01:47"],
+ ["exactly zero", 0, "00:00"],
+ ["over an hour", 3723, "01:02:03"],
+ ["rounding fractional seconds", 30.4, "00:30"],
+ ["clamping negatives to zero", -5, "00:00"],
+ ])("formats %s", (_label, seconds, expected) => {
+ expect(colonOffsetFromSeconds(seconds)).toBe(expected);
+ });
+});
diff --git a/products/desktop/apps/mobile/src/features/inbox/recordingOffset.ts b/products/desktop/apps/mobile/src/features/inbox/recordingOffset.ts
new file mode 100644
index 000000000000..f7683a6bdb1e
--- /dev/null
+++ b/products/desktop/apps/mobile/src/features/inbox/recordingOffset.ts
@@ -0,0 +1,21 @@
+export function colonOffsetToSeconds(offset: string): number | null {
+ const parts = offset.split(":");
+ if (parts.length < 2 || parts.length > 3) return null;
+ if (parts.some((p) => !/^\d+$/.test(p))) return null;
+ const nums = parts.map(Number);
+ const [h, m, s] = parts.length === 3 ? nums : [0, nums[0], nums[1]];
+ if (m >= 60 || s >= 60) return null;
+ const total = h * 3600 + m * 60 + s;
+ return Number.isSafeInteger(total) ? total : null;
+}
+
+export function colonOffsetFromSeconds(seconds: number): string {
+ const total = Math.max(0, Math.round(seconds));
+ const mins = Math.floor(total / 60);
+ const secs = total % 60;
+ const hrs = Math.floor(mins / 60);
+ const pad = (n: number) => String(n).padStart(2, "0");
+ return hrs > 0
+ ? `${pad(hrs)}:${pad(mins % 60)}:${pad(secs)}`
+ : `${pad(mins)}:${pad(secs)}`;
+}
diff --git a/products/desktop/pnpm-lock.yaml b/products/desktop/pnpm-lock.yaml
index d6158801b314..dd70ad706c17 100644
--- a/products/desktop/pnpm-lock.yaml
+++ b/products/desktop/pnpm-lock.yaml
@@ -556,6 +556,9 @@ importers:
expo-system-ui:
specifier: ~57.0.1
+ expo-video:
+ specifier: ~57.0.3
expo-web-browser:
specifier: ^57.0.2
@@ -11291,6 +11294,13 @@ packages:
peerDependencies:
expo: '*'
+ resolution: {integrity: sha512-Z+rLdBSzICwoHm/HUxND5fm5nfgqiB+QPWAOKxmA8ScYwvxG1UGjZ6OaayvPc3GkT4aucsbycmFO0uUv/qnIhg==}
+ peerDependencies:
+ expo: '*'
+ react: 19.2.6
+ react-native: '*'
+
resolution: {integrity: sha512-3vl5kvd7PB48ub6PpNIJUuPxO8xVa6D8RnIgNba6SXRwqFprOfeEZgwTgtm41kz0AAtvMOztUVNEUkwrHKjqMQ==}
peerDependencies:
@@ -26453,6 +26463,12 @@ snapshots:
dependencies:
+ dependencies:
+ react: 19.2.6
+ react-native: 0.86.0(@babel/[email protected])(@react-native/[email protected](@babel/[email protected]))(@types/[email protected])([email protected])
+
dependencies: