: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): stop file:// page URLs ejecting the player to a 404 (#80280)
posthog[bot]c20c9ac98191
diff --git a/frontend/src/scenes/session-recordings/player/player-meta/PlayerMeta.test.tsx b/frontend/src/scenes/session-recordings/player/player-meta/PlayerMeta.test.tsxindex 6d71f2b4df6e..f6107ef85144 100644--- a/frontend/src/scenes/session-recordings/player/player-meta/PlayerMeta.test.tsx+++ b/frontend/src/scenes/session-recordings/player/player-meta/PlayerMeta.test.tsx@@ -5,52 +5,62 @@ describe('parseUrl', () => {{name: 'valid URL string',input: 'https://example.com',- expected: { urlToUse: 'https://example.com', isValidUrl: true },+ expected: { urlToUse: 'https://example.com', isValidUrl: true, isWebUrl: true },},{name: 'location object',input: { href: 'https://example.com/path' },- expected: { urlToUse: 'https://example.com/path', isValidUrl: true },+ expected: { urlToUse: 'https://example.com/path', isValidUrl: true, isWebUrl: true },+ },+ {+ name: 'http URL string',+ input: 'http://example.com',+ expected: { urlToUse: 'http://example.com', isValidUrl: true, isWebUrl: true },+ },+ {+ name: 'file URL is valid but not a web URL',+ input: 'file:///Users/someone/index.html',+ expected: { urlToUse: 'file:///Users/someone/index.html', isValidUrl: true, isWebUrl: false },},{name: 'empty object',input: {},- expected: { urlToUse: undefined, isValidUrl: false },+ expected: { urlToUse: undefined, isValidUrl: false, isWebUrl: false },},{name: 'undefined',input: undefined,- expected: { urlToUse: undefined, isValidUrl: false },+ expected: { urlToUse: undefined, isValidUrl: false, isWebUrl: false },},{name: 'null',input: null,- expected: { urlToUse: undefined, isValidUrl: false },+ expected: { urlToUse: undefined, isValidUrl: false, isWebUrl: false },},{name: 'empty string',input: '',- expected: { urlToUse: undefined, isValidUrl: false },+ expected: { urlToUse: undefined, isValidUrl: false, isWebUrl: false },},{name: 'whitespace string',input: ' ',- expected: { urlToUse: undefined, isValidUrl: false },+ expected: { urlToUse: undefined, isValidUrl: false, isWebUrl: false },},{name: 'invalid URL',input: 'not-a-url',- expected: { urlToUse: 'not-a-url', isValidUrl: false },+ expected: { urlToUse: 'not-a-url', isValidUrl: false, isWebUrl: false },},{name: 'URL with path and query',input: 'https://example.com/path?query=value',- expected: { urlToUse: 'https://example.com/path?query=value', isValidUrl: true },+ expected: { urlToUse: 'https://example.com/path?query=value', isValidUrl: true, isWebUrl: true },},{name: 'location object with invalid URL',input: { href: 'not-a-url' },- expected: { urlToUse: 'not-a-url', isValidUrl: false },+ expected: { urlToUse: 'not-a-url', isValidUrl: false, isWebUrl: false },},])('handles $name', ({ input, expected }) => {expect(parseUrl(input)).toEqual(expected)diff --git a/frontend/src/scenes/session-recordings/player/player-meta/PlayerMeta.tsx b/frontend/src/scenes/session-recordings/player/player-meta/PlayerMeta.tsxindex b49fff22bf0f..a186d20c77c0 100644--- a/frontend/src/scenes/session-recordings/player/player-meta/PlayerMeta.tsx+++ b/frontend/src/scenes/session-recordings/player/player-meta/PlayerMeta.tsx@@ -26,7 +26,7 @@ import { PlayerMetaExperimentTags } from './PlayerMetaExperimentTags'import { playerMetaLogic } from './playerMetaLogic'import { PlayerPersonMeta } from './PlayerPersonMeta'-export function parseUrl(lastUrl: unknown): { urlToUse: string | undefined; isValidUrl: boolean } {+export function parseUrl(lastUrl: unknown): { urlToUse: string | undefined; isValidUrl: boolean; isWebUrl: boolean } {let urlToUse: string | undefined = typeof lastUrl === 'string' ? lastUrl : undefinedif (isObject(lastUrl)) {// regression protection, we saw a user whose site was sometimes sending the string-ified location object@@ -39,22 +39,26 @@ export function parseUrl(lastUrl: unknown): { urlToUse: string | undefined; isVa}if (!urlToUse || urlToUse.trim() === '') {- return { urlToUse: undefined, isValidUrl: false }+ return { urlToUse: undefined, isValidUrl: false, isWebUrl: false }}let isValidUrl = false+ let isWebUrl = falsetry {- new URL(urlToUse)+ const parsed = new URL(urlToUse)isValidUrl = true+ // Only http/https can be opened from an https page. A file:// or other scheme+ // would render a dead link that ejects the user onto a 404, so treat it as plain text.+ isWebUrl = parsed.protocol === 'http:' || parsed.protocol === 'https:'} catch {// no valid url}- return { urlToUse, isValidUrl }+ return { urlToUse, isValidUrl, isWebUrl }}function URLOrScreen({ url }: { url: unknown }): JSX.Element | null {- const { urlToUse, isValidUrl } = parseUrl(url)+ const { urlToUse, isWebUrl } = parseUrl(url)if (!urlToUse) {return null@@ -72,14 +76,14 @@ function URLOrScreen({ url }: { url: unknown }): JSX.Element | null {data-attr="player-meta-copy-url"/></span>- {isValidUrl ? (+ {isWebUrl ? (<Tooltip title={`Click to open url: ${urlToUse}`}><Link to={urlToUse} target="_blank" className="truncate">{urlToUse}</Link></Tooltip>) : (- urlToUse+ <span className="truncate">{urlToUse}</span>)}</span></span>