diff --git a/src/extensions/sessionrecording.ts b/src/extensions/sessionrecording.ts index 574b10049..e01970d54 100644 --- a/src/extensions/sessionrecording.ts +++ b/src/extensions/sessionrecording.ts @@ -101,7 +101,7 @@ export class SessionRecording { }) } - private get sessionManager() { + private getSessionManager() { if (!this.instance.sessionManager) { logger.error('Session recording started without valid sessionManager') return @@ -194,7 +194,8 @@ export class SessionRecording { } private _startCapture() { - if (!this.sessionManager) { + const sessionManager = this.getSessionManager() + if (!sessionManager) { return } if (typeof Object.assign === 'undefined') { @@ -215,7 +216,7 @@ export class SessionRecording { this.captureStarted = true // We want to ensure the sessionManager is reset if necessary on load of the recorder - this.sessionManager.checkAndGetSessionAndWindowId() + sessionManager.checkAndGetSessionAndWindowId() const recorderJS = this.getRecordingVersion() === 'v2' ? 'recorder-v2.js' : 'recorder.js' @@ -243,7 +244,8 @@ export class SessionRecording { } private _updateWindowAndSessionIds(event: eventWithTime) { - if (!this.sessionManager) { + const sessionManager = this.getSessionManager() + if (!sessionManager) { return } // Some recording events are triggered by non-user events (e.g. "X minutes ago" text updating on the screen). @@ -273,7 +275,7 @@ export class SessionRecording { } // We only want to extend the session if it is an interactive event. - const { windowId, sessionId } = this.sessionManager.checkAndGetSessionAndWindowId( + const { windowId, sessionId } = sessionManager.checkAndGetSessionAndWindowId( !isUserInteraction, event.timestamp ) diff --git a/src/posthog-core.ts b/src/posthog-core.ts index b9daa9859..11e0ee627 100644 --- a/src/posthog-core.ts +++ b/src/posthog-core.ts @@ -265,9 +265,6 @@ export class PostHog { featureFlags: PostHogFeatureFlags surveys: PostHogSurveys toolbar: Toolbar - sessionRecording: SessionRecording | undefined - webPerformance: WebPerformanceObserver | undefined - exceptionAutocapture: ExceptionObserver | undefined // These are instance-specific state created after initialisation persistence?: PostHogPersistence @@ -275,6 +272,9 @@ export class PostHog { sessionManager?: SessionIdManager _requestQueue?: RequestQueue _retryQueue?: RetryQueue + sessionRecording?: SessionRecording + webPerformance?: WebPerformanceObserver + exceptionAutocapture?: ExceptionObserver _triggered_notifs: any compression: Partial>