posthog-js 1.77.3 → 1.78.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "posthog-js",
3
- "version": "1.77.3",
3
+ "version": "1.78.1",
4
4
  "description": "Posthog-js allows you to automatically capture usage and send events to PostHog.",
5
5
  "repository": "https://github.com/PostHog/posthog-js",
6
6
  "author": "hey@posthog.com",
package/lib/src/decide.js CHANGED
@@ -40,6 +40,8 @@ var Decide = /** @class */ (function () {
40
40
  var e_1, _a, e_2, _b;
41
41
  var _this = this;
42
42
  var _c, _d, _e;
43
+ this.instance.featureFlags.resetRequestQueue();
44
+ this.instance.featureFlags.setReloadingPaused(false);
43
45
  if ((response === null || response === void 0 ? void 0 : response.status) === 0) {
44
46
  console.error('Failed to fetch feature flags from PostHog.');
45
47
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"decide.js","sourceRoot":"","sources":["../../src/decide.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAGnD,OAAO,EAAE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAEvF;IAGI,gBAAY,QAAiB;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,qFAAqF;QACrF,IAAI,CAAC,QAAQ,CAAC,oBAAoB,GAAG,IAAI,CAAC,QAAQ,CAAC,4BAA4B,EAAE,CAAA;IACrF,CAAC;IAED,qBAAI,GAAJ;QAAA,iBAuBC;QAtBG;;UAEE;QACF,IAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;YAC7B,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC;YACxC,WAAW,EAAE,IAAI,CAAC,QAAQ,CA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OAAO;wBACP,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;qBACjF,CAAC,IAAI,CAAC,EAAE,CAAC,CAET;oBAAC,MAAc,CAAC,0BAAmB,EAAE,CAAE,CAAC,GAAG,OAAK,QAAQ,CAAA;oBAEzD,UAAU,CAAC,SAAS,EAAE,UAAC,GAAG;wBACtB,IAAI,GAAG,EAAE;4BACL,OAAO,CAAC,KAAK,CAAC,8DAAuD,EAAE,CAAE,EAAE,GAAG,CAAC,CAAA;yBAClF;oBACL,CAAC,CAAC,CAAA;;;;oBAZN,KAA0B,IAAA,KAAA,SAAA,QAAQ,CAAC,UAAU,CAAC,CAAA,gBAAA;wBAAnC,IAAA,aAAW,EAAT,EAAE,QAAA,EAAE,GAAG,SAAA;gCAAP,EAAE,EAAE,GAAG;qBAanB;;;;;;;;;aACJ;iBAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;gBACxC,OAAO,CAAC,KAAK,CAAC,kFAAkF,CAAC,CAAA;aACpG;SACJ;IACL,CAAC;IACL,aAAC;AAAD,CAAC,AAxFD,IAwFC","sourcesContent":["import { autocapture } from './autocapture'\nimport { _base64Encode, loadScript } from './utils'\nimport { PostHog } from './posthog-core'\nimport { Compression, DecideResponse } from './types'\nimport { STORED_GROUP_PROPERTIES_KEY, STORED_PERSON_PROPERTIES_KEY } from './constants'\n\nexport class Decide {\n instance: PostHog\n\n constructor(instance: PostHog) {\n this.instance = instance\n // don't need to wait for `decide` to return if flags were provided on initialisation\n this.instance.decideEndpointWasHit = this.instance._hasBootstrappedFeatureFlags()\n }\n\n call(): void {\n /*\n Calls /decide endpoint to fetch options for autocapture, session recording, feature flags & compression.\n */\n const json_data = JSON.stringify({\n token: this.instance.get_config('token'),\n distinct_id: this.instance.get_distinct_id(),\n groups: this.instance.getGroups(),\n person_properties: this.instance.get_property(STORED_PERSON_PROPERTIES_KEY),\n group_properties: this.instance.get_property(STORED_GROUP_PROPERTIES_KEY),\n disable_flags:\n this.instance.get_config('advanced_disable_feature_flags') ||\n this.instance.get_config('advanced_disable_feature_flags_on_first_load') ||\n undefined,\n })\n\n const encoded_data = _base64Encode(json_data)\n this.instance._send_request(\n `${this.instance.get_config('api_host')}/decide/?v=3`,\n { data: encoded_data, verbose: true },\n { method: 'POST' },\n (response) => this.parseDecideResponse(response as DecideResponse)\n )\n }\n\n parseDecideResponse(response: DecideResponse): void {\n if (response?.status === 0) {\n console.error('Failed to fetch feature flags from PostHog.')\n return\n }\n if (!(document && document.body)) {\n console.log('document not ready yet, trying again in 500 milliseconds...')\n setTimeout(() => {\n this.parseDecideResponse(response)\n }, 500)\n return\n }\n\n this.instance.toolbar.afterDecideResponse(response)\n this.instance.sessionRecording?.afterDecideResponse(response)\n autocapture.afterDecideResponse(response, this.instance)\n this.instance.webPerformance?.afterDecideResponse(response)\n this.instance.exceptionAutocapture?.afterDecideResponse(response)\n\n if (!this.instance.get_config('advanced_disable_feature_flags_on_first_load')) {\n this.instance.featureFlags.receivedFeatureFlags(response)\n }\n\n this.instance['compression'] = {}\n if (response['supportedCompression'] && !this.instance.get_config('disable_compression')) {\n const compression: Partial<Record<Compression, boolean>> = {}\n for (const method of response['supportedCompression']) {\n compression[method] = true\n }\n this.instance['compression'] = compression\n }\n\n if (response['siteApps']) {\n if (this.instance.get_config('opt_in_site_apps')) {\n const apiHost = this.instance.get_config('api_host')\n for (const { id, url } of response['siteApps']) {\n const scriptUrl = [\n apiHost,\n apiHost[apiHost.length - 1] === '/' && url[0] === '/' ? url.substring(1) : url,\n ].join('')\n\n ;(window as any)[`__$$ph_site_app_${id}`] = this.instance\n\n loadScript(scriptUrl, (err) => {\n if (err) {\n console.error(`Error while initializing PostHog app with config id ${id}`, err)\n }\n })\n }\n } else if (response['siteApps'].length > 0) {\n console.error('PostHog site apps are disabled. Enable the \"opt_in_site_apps\" config to proceed.')\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"decide.js","sourceRoot":"","sources":["../../src/decide.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAGnD,OAAO,EAAE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAEvF;IAGI,gBAAY,QAAiB;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,qFAAqF;QACrF,IAAI,CAAC,QAAQ,CAAC,oBAAoB,GAAG,IAAI,CAAC,QAAQ,CAAC,4BAA4B,EAAE,CAAA;IACrF,CAAC;IAED,qBAAI,GAAJ;QAAA,iBAuBC;QAtBG;;UAEE;QACF,IAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;YAC7B,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC;YACxC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE;YAC5C,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE;YACjC,iBAAiB,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,4BAA4B,CAAC;YAC3E,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,2BAA2B,CAAC;YACzE,aAAa,EACT,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,gCAAgC,CAAC;gBAC1D,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,8CAA8C,CAAC;gBACxE,SAAS;SAChB,CAAC,CAAA;QAEF,IAAM,YAAY,GAAG,aAAa,CAAC,SAAS,CAAC,CAAA;QAC7C,IAAI,CAAC,QAAQ,CAAC,aAAa,CACvB,UAAG,IAAI,CA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G;wBACtB,IAAI,GAAG,EAAE;4BACL,OAAO,CAAC,KAAK,CAAC,8DAAuD,EAAE,CAAE,EAAE,GAAG,CAAC,CAAA;yBAClF;oBACL,CAAC,CAAC,CAAA;;;;oBAZN,KAA0B,IAAA,KAAA,SAAA,QAAQ,CAAC,UAAU,CAAC,CAAA,gBAAA;wBAAnC,IAAA,aAAW,EAAT,EAAE,QAAA,EAAE,GAAG,SAAA;gCAAP,EAAE,EAAE,GAAG;qBAanB;;;;;;;;;aACJ;iBAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;gBACxC,OAAO,CAAC,KAAK,CAAC,kFAAkF,CAAC,CAAA;aACpG;SACJ;IACL,CAAC;IACL,aAAC;AAAD,CAAC,AA3FD,IA2FC","sourcesContent":["import { autocapture } from './autocapture'\nimport { _base64Encode, loadScript } from './utils'\nimport { PostHog } from './posthog-core'\nimport { Compression, DecideResponse } from './types'\nimport { STORED_GROUP_PROPERTIES_KEY, STORED_PERSON_PROPERTIES_KEY } from './constants'\n\nexport class Decide {\n instance: PostHog\n\n constructor(instance: PostHog) {\n this.instance = instance\n // don't need to wait for `decide` to return if flags were provided on initialisation\n this.instance.decideEndpointWasHit = this.instance._hasBootstrappedFeatureFlags()\n }\n\n call(): void {\n /*\n Calls /decide endpoint to fetch options for autocapture, session recording, feature flags & compression.\n */\n const json_data = JSON.stringify({\n token: this.instance.get_config('token'),\n distinct_id: this.instance.get_distinct_id(),\n groups: this.instance.getGroups(),\n person_properties: this.instance.get_property(STORED_PERSON_PROPERTIES_KEY),\n group_properties: this.instance.get_property(STORED_GROUP_PROPERTIES_KEY),\n disable_flags:\n this.instance.get_config('advanced_disable_feature_flags') ||\n this.instance.get_config('advanced_disable_feature_flags_on_first_load') ||\n undefined,\n })\n\n const encoded_data = _base64Encode(json_data)\n this.instance._send_request(\n `${this.instance.get_config('api_host')}/decide/?v=3`,\n { data: encoded_data, verbose: true },\n { method: 'POST' },\n (response) => this.parseDecideResponse(response as DecideResponse)\n )\n }\n\n parseDecideResponse(response: DecideResponse): void {\n this.instance.featureFlags.resetRequestQueue()\n this.instance.featureFlags.setReloadingPaused(false)\n\n if (response?.status === 0) {\n console.error('Failed to fetch feature flags from PostHog.')\n return\n }\n if (!(document && document.body)) {\n console.log('document not ready yet, trying again in 500 milliseconds...')\n setTimeout(() => {\n this.parseDecideResponse(response)\n }, 500)\n return\n }\n\n this.instance.toolbar.afterDecideResponse(response)\n this.instance.sessionRecording?.afterDecideResponse(response)\n autocapture.afterDecideResponse(response, this.instance)\n this.instance.webPerformance?.afterDecideResponse(response)\n this.instance.exceptionAutocapture?.afterDecideResponse(response)\n\n if (!this.instance.get_config('advanced_disable_feature_flags_on_first_load')) {\n this.instance.featureFlags.receivedFeatureFlags(response)\n }\n\n this.instance['compression'] = {}\n if (response['supportedCompression'] && !this.instance.get_config('disable_compression')) {\n const compression: Partial<Record<Compression, boolean>> = {}\n for (const method of response['supportedCompression']) {\n compression[method] = true\n }\n this.instance['compression'] = compression\n }\n\n if (response['siteApps']) {\n if (this.instance.get_config('opt_in_site_apps')) {\n const apiHost = this.instance.get_config('api_host')\n for (const { id, url } of response['siteApps']) {\n const scriptUrl = [\n apiHost,\n apiHost[apiHost.length - 1] === '/' && url[0] === '/' ? url.substring(1) : url,\n ].join('')\n\n ;(window as any)[`__$$ph_site_app_${id}`] = this.instance\n\n loadScript(scriptUrl, (err) => {\n if (err) {\n console.error(`Error while initializing PostHog app with config id ${id}`, err)\n }\n })\n }\n } else if (response['siteApps'].length > 0) {\n console.error('PostHog site apps are disabled. Enable the \"opt_in_site_apps\" config to proceed.')\n }\n }\n }\n}\n"]}
@@ -24,6 +24,7 @@ export declare class SessionRecording {
24
24
  recorderVersion?: string;
25
25
  isIdle: boolean;
26
26
  constructor(instance: PostHog);
27
+ private getSessionManager;
27
28
  startRecordingIfEnabled(): void;
28
29
  started(): boolean;
29
30
  stopRecording(): void;
@@ -96,6 +96,13 @@ var SessionRecording = /** @class */ (function () {
96
96
  _this._flushBuffer();
97
97
  });
98
98
  }
99
+ SessionRecording.prototype.getSessionManager = function () {
100
+ if (!this.instance.sessionManager) {
101
+ logger.error('Session recording started without valid sessionManager');
102
+ return;
103
+ }
104
+ return this.instance.sessionManager;
105
+ };
99
106
  SessionRecording.prototype.startRecordingIfEnabled = function () {
100
107
  if (this.isRecordingEnabled()) {
101
108
  this.startCaptureAndTrySendingQueuedSnapshots();
@@ -178,14 +185,18 @@ var SessionRecording = /** @class */ (function () {
178
185
  };
179
186
  SessionRecording.prototype._startCapture = function () {
180
187
  var _this = this;
181
- // According to the rrweb docs, rrweb is not supported on IE11 and below:
182
- // "rrweb does not support IE11 and below because it uses the MutationObserver API which was supported by these browsers."
183
- // https://github.com/rrweb-io/rrweb/blob/master/guide.md#compatibility-note
184
- //
185
- // However, MutationObserver does exist on IE11, it just doesn't work well and does not detect all changes.
186
- // Instead, when we load "recorder.js", the first JS error is about "Object.assign" being undefined.
187
- // Thus instead of MutationObserver, we look for this function and block recording if it's undefined.
188
+ var sessionManager = this.getSessionManager();
189
+ if (!sessionManager) {
190
+ return;
191
+ }
188
192
  if (typeof Object.assign === 'undefined') {
193
+ // According to the rrweb docs, rrweb is not supported on IE11 and below:
194
+ // "rrweb does not support IE11 and below because it uses the MutationObserver API which was supported by these browsers."
195
+ // https://github.com/rrweb-io/rrweb/blob/master/guide.md#compatibility-note
196
+ //
197
+ // However, MutationObserver does exist on IE11, it just doesn't work well and does not detect all changes.
198
+ // Instead, when we load "recorder.js", the first JS error is about "Object.assign" being undefined.
199
+ // Thus instead of MutationObserver, we look for this function and block recording if it's undefined.
189
200
  return;
190
201
  }
191
202
  // We do not switch recorder versions midway through a recording.
@@ -194,7 +205,7 @@ var SessionRecording = /** @class */ (function () {
194
205
  }
195
206
  this.captureStarted = true;
196
207
  // We want to ensure the sessionManager is reset if necessary on load of the recorder
197
- this.instance.sessionManager.checkAndGetSessionAndWindowId();
208
+ sessionManager.checkAndGetSessionAndWindowId();
198
209
  var recorderJS = this.getRecordingVersion() === 'v2' ? 'recorder-v2.js' : 'recorder.js';
199
210
  // If recorder.js is already loaded (if array.full.js snippet is used or posthog-js/dist/recorder is
200
211
  // imported) or matches the requested recorder version, don't load script. Otherwise, remotely import
@@ -216,6 +227,10 @@ var SessionRecording = /** @class */ (function () {
216
227
  return event.type === INCREMENTAL_SNAPSHOT_EVENT_TYPE && ACTIVE_SOURCES.indexOf((_a = event.data) === null || _a === void 0 ? void 0 : _a.source) !== -1;
217
228
  };
218
229
  SessionRecording.prototype._updateWindowAndSessionIds = function (event) {
230
+ var sessionManager = this.getSessionManager();
231
+ if (!sessionManager) {
232
+ return;
233
+ }
219
234
  // Some recording events are triggered by non-user events (e.g. "X minutes ago" text updating on the screen).
220
235
  // We don't want to extend the session or trigger a new session in these cases. These events are designated by event
221
236
  // type -> incremental update, and source -> mutation.
@@ -238,7 +253,7 @@ var SessionRecording = /** @class */ (function () {
238
253
  return;
239
254
  }
240
255
  // We only want to extend the session if it is an interactive event.
241
- var _a = this.instance.sessionManager.checkAndGetSessionAndWindowId(!isUserInteraction, event.timestamp), windowId = _a.windowId, sessionId = _a.sessionId;
256
+ var _a = sessionManager.checkAndGetSessionAndWindowId(!isUserInteraction, event.timestamp), windowId = _a.windowId, sessionId = _a.sessionId;
242
257
  if ([FULL_SNAPSHOT_EVENT_TYPE, META_EVENT_TYPE].indexOf(event.type) === -1 &&
243
258
  (this.windowId !== windowId || this.sessionId !== sessionId)) {
244
259
  this._tryTakeFullSnapshot();
@@ -1 +1 @@
1
- {"version":3,"file":"sessionrecording.js","sourceRoot":"","sources":["../../../src/extensions/sessionrecording.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EACH,yCAAyC,EACzC,qCAAqC,EACrC,8CAA8C,GACjD,MAAM,cAAc,CAAA;AACrB,OAAO,EACH,oBAAoB,EACpB,wBAAwB,EACxB,+BAA+B,EAC/B,eAAe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MAAM,EAAE,MAAM;YACd,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,WAAW,EAAE,IAAI;YACjB,SAAS,EAAE,2BAA2B;YACtC,QAAQ,EAAE;gBACN,mBAAmB,EAAE,UAAU,CAAC,cAAc,CAAC,IAAI,KAAK,wBAAwB;aACnF;SACJ,CAAC,CAAA;IACN,CAAC;IACL,uBAAC;AAAD,CAAC,AApZD,IAoZC","sourcesContent":["import {\n CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE,\n SESSION_RECORDING_ENABLED_SERVER_SIDE,\n SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE,\n} from '../constants'\nimport {\n ensureMaxMessageSize,\n FULL_SNAPSHOT_EVENT_TYPE,\n INCREMENTAL_SNAPSHOT_EVENT_TYPE,\n META_EVENT_TYPE,\n MutationRateLimiter,\n recordOptions,\n rrwebRecord,\n truncateLargeConsoleLogs,\n} from './sessionrecording-utils'\nimport { PostHog } from '../posthog-core'\nimport { DecideResponse, Properties } from '../types'\nimport type { eventWithTime, listenerHandler } from '@rrweb/types'\nimport Config from '../config'\nimport { logger, loadScript, _timestamp } from '../utils'\n\nconst BASE_ENDPOINT = '/s/'\n\nexport const RECORDING_IDLE_ACTIVITY_TIMEOUT_MS = 5 * 60 * 1000 // 5 minutes\nexport const RECORDING_MAX_EVENT_SIZE = 1024 * 1024 * 0.9 // ~1mb (with some wiggle room)\nexport const RECORDING_BUFFER_TIMEOUT = 2000 // 2 seconds\nexport const SESSION_RECORDING_BATCH_KEY = 'sessionRecording'\n\n// NOTE: Importing this type is problematic as we can't safely bundle it to a TS definition so, instead we redefine.\n// import type { record } from 'rrweb2/typings'\n// import type { recordOptions } from 'rrweb/typings/types'\n\n// Copied from rrweb typings to avoid import\nenum IncrementalSource {\n Mutation = 0,\n MouseMove = 1,\n MouseInteraction = 2,\n Scroll = 3,\n ViewportResize = 4,\n Input = 5,\n TouchMove = 6,\n MediaInteraction = 7,\n StyleSheetRule = 8,\n CanvasMutation = 9,\n Font = 10,\n Log = 11,\n Drag = 12,\n StyleDeclaration = 13,\n Selection = 14,\n AdoptedStyleSheet = 15,\n}\n\nconst ACTIVE_SOURCES = [\n IncrementalSource.MouseMove,\n IncrementalSource.MouseInteraction,\n IncrementalSource.Scroll,\n IncrementalSource.ViewportResize,\n IncrementalSource.Input,\n IncrementalSource.TouchMove,\n IncrementalSource.MediaInteraction,\n IncrementalSource.Drag,\n]\n\nexport class SessionRecording {\n private instance: PostHog\n private emit: boolean\n private endpoint: string\n private windowId: string | null\n private sessionId: string | null\n private lastActivityTimestamp: number = Date.now()\n private flushBufferTimer?: any\n private buffer?: {\n size: number\n data: any[]\n sessionId: string | null\n windowId: string | null\n }\n private mutationRateLimiter?: MutationRateLimiter\n\n captureStarted: boolean\n snapshots: any[]\n stopRrweb: listenerHandler | undefined\n receivedDecide: boolean\n rrwebRecord: rrwebRecord | undefined\n recorderVersion?: string\n isIdle = false\n\n constructor(instance: PostHog) {\n this.instance = instance\n this.captureStarted = false\n this.snapshots = []\n this.emit = false // Controls whether data is sent to the server or not\n this.endpoint = BASE_ENDPOINT\n this.stopRrweb = undefined\n this.windowId = null\n this.sessionId = null\n this.receivedDecide = false\n\n window.addEventListener('beforeunload', () => {\n this._flushBuffer()\n })\n }\n\n startRecordingIfEnabled() {\n if (this.isRecordingEnabled()) {\n this.startCaptureAndTrySendingQueuedSnapshots()\n } else {\n this.stopRecording()\n }\n }\n\n started() {\n return this.captureStarted\n }\n\n stopRecording() {\n if (this.captureStarted && this.stopRrweb) {\n this.stopRrweb()\n this.stopRrweb = undefined\n this.captureStarted = false\n }\n }\n\n isRecordingEnabled() {\n const enabled_server_side = !!this.instance.get_property(SESSION_RECORDING_ENABLED_SERVER_SIDE)\n const enabled_client_side = !this.instance.get_config('disable_session_recording')\n return enabled_server_side && enabled_client_side\n }\n\n isConsoleLogCaptureEnabled() {\n const enabled_server_side = !!this.instance.get_property(CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE)\n const enabled_client_side = this.instance.get_config('enable_recording_console_log')\n return enabled_client_side ?? enabled_server_side\n }\n\n getRecordingVersion() {\n const recordingVersion_server_side = this.instance.get_property(SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE)\n const recordingVersion_client_side = this.instance.get_config('session_recording')?.recorderVersion\n return recordingVersion_client_side || recordingVersion_server_side || 'v1'\n }\n\n afterDecideResponse(response: DecideResponse) {\n this.receivedDecide = true\n if (this.instance.persistence) {\n this.instance.persistence.register({\n [SESSION_RECORDING_ENABLED_SERVER_SIDE]: !!response['sessionRecording'],\n [CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE]: response.sessionRecording?.consoleLogRecordingEnabled,\n [SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE]: response.sessionRecording?.recorderVersion,\n })\n }\n if (response.sessionRecording?.endpoint) {\n this.endpoint = response.sessionRecording?.endpoint\n }\n\n if (response.sessionRecording?.recorderVersion) {\n this.recorderVersion = response.sessionRecording.recorderVersion\n }\n this.startRecordingIfEnabled()\n }\n\n log(message: string, level: 'log' | 'warn' | 'error' = 'log') {\n this.instance.sessionRecording?.onRRwebEmit({\n type: 6,\n data: {\n plugin: 'rrweb/console@1',\n payload: {\n level,\n trace: [],\n // Even though it is a string we stringify it as thats what rrweb expects\n payload: [JSON.stringify(message)],\n },\n },\n timestamp: _timestamp(),\n })\n }\n\n private startCaptureAndTrySendingQueuedSnapshots() {\n // Only submit data after we've received a decide response to account for\n // changing endpoints and the feature being disabled on the server side.\n if (this.receivedDecide) {\n this.emit = true\n this.snapshots.forEach((properties) => this._captureSnapshotBuffered(properties))\n }\n this._startCapture()\n }\n\n private _startCapture() {\n // According to the rrweb docs, rrweb is not supported on IE11 and below:\n // \"rrweb does not support IE11 and below because it uses the MutationObserver API which was supported by these browsers.\"\n // https://github.com/rrweb-io/rrweb/blob/master/guide.md#compatibility-note\n //\n // However, MutationObserver does exist on IE11, it just doesn't work well and does not detect all changes.\n // Instead, when we load \"recorder.js\", the first JS error is about \"Object.assign\" being undefined.\n // Thus instead of MutationObserver, we look for this function and block recording if it's undefined.\n if (typeof Object.assign === 'undefined') {\n return\n }\n\n // We do not switch recorder versions midway through a recording.\n if (this.captureStarted || this.instance.get_config('disable_session_recording')) {\n return\n }\n\n this.captureStarted = true\n // We want to ensure the sessionManager is reset if necessary on load of the recorder\n this.instance.sessionManager.checkAndGetSessionAndWindowId()\n\n const recorderJS = this.getRecordingVersion() === 'v2' ? 'recorder-v2.js' : 'recorder.js'\n\n // If recorder.js is already loaded (if array.full.js snippet is used or posthog-js/dist/recorder is\n // imported) or matches the requested recorder version, don't load script. Otherwise, remotely import\n // recorder.js from cdn since it hasn't been loaded.\n if (this.instance.__loaded_recorder_version !== this.getRecordingVersion()) {\n loadScript(\n this.instance.get_config('api_host') + `/static/${recorderJS}?v=${Config.LIB_VERSION}`,\n (err) => {\n if (err) {\n return logger.error(`Could not load ${recorderJS}`, err)\n }\n\n this._onScriptLoaded()\n }\n )\n } else {\n this._onScriptLoaded()\n }\n }\n\n private _isInteractiveEvent(event: eventWithTime) {\n return event.type === INCREMENTAL_SNAPSHOT_EVENT_TYPE && ACTIVE_SOURCES.indexOf(event.data?.source) !== -1\n }\n\n private _updateWindowAndSessionIds(event: eventWithTime) {\n // Some recording events are triggered by non-user events (e.g. \"X minutes ago\" text updating on the screen).\n // We don't want to extend the session or trigger a new session in these cases. These events are designated by event\n // type -> incremental update, and source -> mutation.\n\n const isUserInteraction = this._isInteractiveEvent(event)\n\n if (!isUserInteraction && !this.isIdle) {\n // We check if the lastActivityTimestamp is old enough to go idle\n if (event.timestamp - this.lastActivityTimestamp > RECORDING_IDLE_ACTIVITY_TIMEOUT_MS) {\n this.isIdle = true\n }\n }\n\n if (isUserInteraction) {\n this.lastActivityTimestamp = event.timestamp\n if (this.isIdle) {\n // Remove the idle state if set and trigger a full snapshot as we will have ingored previous mutations\n this.isIdle = false\n this._tryTakeFullSnapshot()\n }\n }\n\n if (this.isIdle) {\n return\n }\n\n // We only want to extend the session if it is an interactive event.\n const { windowId, sessionId } = this.instance.sessionManager.checkAndGetSessionAndWindowId(\n !isUserInteraction,\n event.timestamp\n )\n\n if (\n [FULL_SNAPSHOT_EVENT_TYPE, META_EVENT_TYPE].indexOf(event.type) === -1 &&\n (this.windowId !== windowId || this.sessionId !== sessionId)\n ) {\n this._tryTakeFullSnapshot()\n }\n this.windowId = windowId\n this.sessionId = sessionId\n }\n\n private _tryTakeFullSnapshot(): boolean {\n if (!this.captureStarted) {\n return false\n }\n try {\n this.rrwebRecord?.takeFullSnapshot()\n return true\n } catch (e) {\n // Sometimes a race can occur where the recorder is not fully started yet, so we can't take a full snapshot.\n logger.error('Error taking full snapshot.', e)\n return false\n }\n }\n\n private _onScriptLoaded() {\n // rrweb config info: https://github.com/rrweb-io/rrweb/blob/7d5d0033258d6c29599fb08412202d9a2c7b9413/src/record/index.ts#L28\n const sessionRecordingOptions: recordOptions<eventWithTime> = {\n // select set of rrweb config options we expose to our users\n // see https://github.com/rrweb-io/rrweb/blob/master/guide.md\n blockClass: 'ph-no-capture',\n blockSelector: undefined,\n ignoreClass: 'ph-ignore-input',\n maskTextClass: 'ph-mask',\n maskTextSelector: undefined,\n maskTextFn: undefined,\n maskAllInputs: true,\n maskInputOptions: {},\n maskInputFn: undefined,\n slimDOMOptions: {},\n collectFonts: false,\n inlineStylesheet: true,\n recordCrossOriginIframes: false,\n }\n // We switched from loading all of rrweb to just the record part, but\n // keep backwards compatibility if someone hasn't upgraded PostHog\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.rrwebRecord = window.rrweb ? window.rrweb.record : window.rrwebRecord\n\n // only allows user to set our 'allowlisted' options\n const userSessionRecordingOptions = this.instance.get_config('session_recording')\n for (const [key, value] of Object.entries(userSessionRecordingOptions || {})) {\n if (key in sessionRecordingOptions) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n sessionRecordingOptions[key] = value\n }\n }\n\n if (!this.rrwebRecord) {\n logger.error(\n 'onScriptLoaded was called but rrwebRecord is not available. This indicates something has gone wrong.'\n )\n return\n }\n\n this.mutationRateLimiter =\n this.mutationRateLimiter ??\n new MutationRateLimiter(this.rrwebRecord!, {\n onBlockedNode: (id, node) => {\n const message = `Too many mutations on node '${id}'. Rate limiting. This could be due to SVG animations or something similar`\n logger.log(message, {\n node: node,\n })\n\n this.log('[PostHog Recorder] ' + message, 'warn')\n },\n })\n\n this.stopRrweb = this.rrwebRecord({\n emit: (event) => {\n this.onRRwebEmit(event)\n },\n plugins:\n (window as any).rrwebConsoleRecord && this.isConsoleLogCaptureEnabled()\n ? [(window as any).rrwebConsoleRecord.getRecordConsolePlugin()]\n : [],\n ...sessionRecordingOptions,\n })\n\n // :TRICKY: rrweb does not capture navigation within SPA-s, so hook into our $pageview events to get access to all events.\n // Dropping the initial event is fine (it's always captured by rrweb).\n this.instance._addCaptureHook((eventName) => {\n // If anything could go wrong here it has the potential to block the main loop so we catch all errors.\n try {\n if (eventName === '$pageview') {\n this.rrwebRecord?.addCustomEvent('$pageview', { href: window.location.href })\n }\n } catch (e) {\n logger.error('Could not add $pageview to rrweb session', e)\n }\n })\n\n // We reset the last activity timestamp, resetting the idle timer\n this.lastActivityTimestamp = Date.now()\n this.isIdle = false\n }\n\n onRRwebEmit(rawEvent: eventWithTime) {\n if (!rawEvent || typeof rawEvent !== 'object') {\n return\n }\n\n const throttledEvent = this.mutationRateLimiter\n ? this.mutationRateLimiter.throttleMutations(rawEvent)\n : rawEvent\n\n if (!throttledEvent) {\n return\n }\n\n const { event, size } = ensureMaxMessageSize(truncateLargeConsoleLogs(throttledEvent))\n\n this._updateWindowAndSessionIds(event)\n\n if (this.isIdle) {\n // When in an idle state we keep recording, but don't capture the events\n return\n }\n\n const properties = {\n $snapshot_bytes: size,\n $snapshot_data: event,\n $session_id: this.sessionId,\n $window_id: this.windowId,\n }\n\n if (this.emit) {\n this._captureSnapshotBuffered(properties)\n } else {\n this.snapshots.push(properties)\n }\n }\n\n private _flushBuffer() {\n if (this.flushBufferTimer) {\n clearTimeout(this.flushBufferTimer)\n this.flushBufferTimer = undefined\n }\n\n if (this.buffer && this.buffer.data.length !== 0) {\n this._captureSnapshot({\n $snapshot_bytes: this.buffer.size,\n $snapshot_data: this.buffer.data,\n $session_id: this.buffer.sessionId,\n $window_id: this.buffer.windowId,\n })\n }\n\n this.buffer = undefined\n\n return {\n size: 0,\n data: [],\n sessionId: this.sessionId,\n windowId: this.windowId,\n }\n }\n\n private _captureSnapshotBuffered(properties: Properties) {\n const additionalBytes = 2 + (this.buffer?.data.length || 0) // 2 bytes for the array brackets and 1 byte for each comma\n if (\n !this.buffer ||\n this.buffer.size + properties.$snapshot_bytes + additionalBytes > RECORDING_MAX_EVENT_SIZE ||\n this.buffer.sessionId !== this.sessionId\n ) {\n this.buffer = this._flushBuffer()\n }\n\n this.buffer.size += properties.$snapshot_bytes\n this.buffer.data.push(properties.$snapshot_data)\n\n if (!this.flushBufferTimer) {\n this.flushBufferTimer = setTimeout(() => {\n this._flushBuffer()\n }, RECORDING_BUFFER_TIMEOUT)\n }\n }\n\n private _captureSnapshot(properties: Properties) {\n // :TRICKY: Make sure we batch these requests, use a custom endpoint and don't truncate the strings.\n this.instance.capture('$snapshot', properties, {\n transport: 'XHR',\n method: 'POST',\n endpoint: this.endpoint,\n _noTruncate: true,\n _batchKey: SESSION_RECORDING_BATCH_KEY,\n _metrics: {\n rrweb_full_snapshot: properties.$snapshot_data.type === FULL_SNAPSHOT_EVENT_TYPE,\n },\n })\n }\n}\n"]}
1
+ {"version":3,"file":"sessionrecording.js","sourceRoot":"","sources":["../../../src/extensions/sessionrecording.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EACH,yCAAyC,EACzC,qCAAqC,EACrC,8CAA8C,GACjD,MAAM,cAAc,CAAA;AACrB,OAAO,EACH,oBAAoB,EACpB,wBAAwB,EACxB,+BAA+B,EAC/B,eAA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U,CAAC,cAAc,CAAC,CAAA;QAEhD,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;YACxB,IAAI,CAAC,gBAAgB,GAAG,UAAU,CAAC;gBAC/B,KAAI,CAAC,YAAY,EAAE,CAAA;YACvB,CAAC,EAAE,wBAAwB,CAAC,CAAA;SAC/B;IACL,CAAC;IAEO,2CAAgB,GAAxB,UAAyB,UAAsB;QAC3C,oGAAoG;QACpG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,EAAE;YAC3C,SAAS,EAAE,KAAK;YAChB,MAAM,EAAE,MAAM;YACd,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,WAAW,EAAE,IAAI;YACjB,SAAS,EAAE,2BAA2B;YACtC,QAAQ,EAAE;gBACN,mBAAmB,EAAE,UAAU,CAAC,cAAc,CAAC,IAAI,KAAK,wBAAwB;aACnF;SACJ,CAAC,CAAA;IACN,CAAC;IACL,uBAAC;AAAD,CAAC,AAraD,IAqaC","sourcesContent":["import {\n CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE,\n SESSION_RECORDING_ENABLED_SERVER_SIDE,\n SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE,\n} from '../constants'\nimport {\n ensureMaxMessageSize,\n FULL_SNAPSHOT_EVENT_TYPE,\n INCREMENTAL_SNAPSHOT_EVENT_TYPE,\n META_EVENT_TYPE,\n MutationRateLimiter,\n recordOptions,\n rrwebRecord,\n truncateLargeConsoleLogs,\n} from './sessionrecording-utils'\nimport { PostHog } from '../posthog-core'\nimport { DecideResponse, Properties } from '../types'\nimport type { eventWithTime, listenerHandler } from '@rrweb/types'\nimport Config from '../config'\nimport { logger, loadScript, _timestamp } from '../utils'\n\nconst BASE_ENDPOINT = '/s/'\n\nexport const RECORDING_IDLE_ACTIVITY_TIMEOUT_MS = 5 * 60 * 1000 // 5 minutes\nexport const RECORDING_MAX_EVENT_SIZE = 1024 * 1024 * 0.9 // ~1mb (with some wiggle room)\nexport const RECORDING_BUFFER_TIMEOUT = 2000 // 2 seconds\nexport const SESSION_RECORDING_BATCH_KEY = 'sessionRecording'\n\n// NOTE: Importing this type is problematic as we can't safely bundle it to a TS definition so, instead we redefine.\n// import type { record } from 'rrweb2/typings'\n// import type { recordOptions } from 'rrweb/typings/types'\n\n// Copied from rrweb typings to avoid import\nenum IncrementalSource {\n Mutation = 0,\n MouseMove = 1,\n MouseInteraction = 2,\n Scroll = 3,\n ViewportResize = 4,\n Input = 5,\n TouchMove = 6,\n MediaInteraction = 7,\n StyleSheetRule = 8,\n CanvasMutation = 9,\n Font = 10,\n Log = 11,\n Drag = 12,\n StyleDeclaration = 13,\n Selection = 14,\n AdoptedStyleSheet = 15,\n}\n\nconst ACTIVE_SOURCES = [\n IncrementalSource.MouseMove,\n IncrementalSource.MouseInteraction,\n IncrementalSource.Scroll,\n IncrementalSource.ViewportResize,\n IncrementalSource.Input,\n IncrementalSource.TouchMove,\n IncrementalSource.MediaInteraction,\n IncrementalSource.Drag,\n]\n\nexport class SessionRecording {\n private instance: PostHog\n private emit: boolean\n private endpoint: string\n private windowId: string | null\n private sessionId: string | null\n private lastActivityTimestamp: number = Date.now()\n private flushBufferTimer?: any\n private buffer?: {\n size: number\n data: any[]\n sessionId: string | null\n windowId: string | null\n }\n private mutationRateLimiter?: MutationRateLimiter\n\n captureStarted: boolean\n snapshots: any[]\n stopRrweb: listenerHandler | undefined\n receivedDecide: boolean\n rrwebRecord: rrwebRecord | undefined\n recorderVersion?: string\n isIdle = false\n\n constructor(instance: PostHog) {\n this.instance = instance\n this.captureStarted = false\n this.snapshots = []\n this.emit = false // Controls whether data is sent to the server or not\n this.endpoint = BASE_ENDPOINT\n this.stopRrweb = undefined\n this.windowId = null\n this.sessionId = null\n this.receivedDecide = false\n\n window.addEventListener('beforeunload', () => {\n this._flushBuffer()\n })\n }\n\n private getSessionManager() {\n if (!this.instance.sessionManager) {\n logger.error('Session recording started without valid sessionManager')\n return\n }\n\n return this.instance.sessionManager\n }\n\n startRecordingIfEnabled() {\n if (this.isRecordingEnabled()) {\n this.startCaptureAndTrySendingQueuedSnapshots()\n } else {\n this.stopRecording()\n }\n }\n\n started() {\n return this.captureStarted\n }\n\n stopRecording() {\n if (this.captureStarted && this.stopRrweb) {\n this.stopRrweb()\n this.stopRrweb = undefined\n this.captureStarted = false\n }\n }\n\n isRecordingEnabled() {\n const enabled_server_side = !!this.instance.get_property(SESSION_RECORDING_ENABLED_SERVER_SIDE)\n const enabled_client_side = !this.instance.get_config('disable_session_recording')\n return enabled_server_side && enabled_client_side\n }\n\n isConsoleLogCaptureEnabled() {\n const enabled_server_side = !!this.instance.get_property(CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE)\n const enabled_client_side = this.instance.get_config('enable_recording_console_log')\n return enabled_client_side ?? enabled_server_side\n }\n\n getRecordingVersion() {\n const recordingVersion_server_side = this.instance.get_property(SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE)\n const recordingVersion_client_side = this.instance.get_config('session_recording')?.recorderVersion\n return recordingVersion_client_side || recordingVersion_server_side || 'v1'\n }\n\n afterDecideResponse(response: DecideResponse) {\n this.receivedDecide = true\n if (this.instance.persistence) {\n this.instance.persistence.register({\n [SESSION_RECORDING_ENABLED_SERVER_SIDE]: !!response['sessionRecording'],\n [CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE]: response.sessionRecording?.consoleLogRecordingEnabled,\n [SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE]: response.sessionRecording?.recorderVersion,\n })\n }\n if (response.sessionRecording?.endpoint) {\n this.endpoint = response.sessionRecording?.endpoint\n }\n\n if (response.sessionRecording?.recorderVersion) {\n this.recorderVersion = response.sessionRecording.recorderVersion\n }\n this.startRecordingIfEnabled()\n }\n\n log(message: string, level: 'log' | 'warn' | 'error' = 'log') {\n this.instance.sessionRecording?.onRRwebEmit({\n type: 6,\n data: {\n plugin: 'rrweb/console@1',\n payload: {\n level,\n trace: [],\n // Even though it is a string we stringify it as thats what rrweb expects\n payload: [JSON.stringify(message)],\n },\n },\n timestamp: _timestamp(),\n })\n }\n\n private startCaptureAndTrySendingQueuedSnapshots() {\n // Only submit data after we've received a decide response to account for\n // changing endpoints and the feature being disabled on the server side.\n if (this.receivedDecide) {\n this.emit = true\n this.snapshots.forEach((properties) => this._captureSnapshotBuffered(properties))\n }\n this._startCapture()\n }\n\n private _startCapture() {\n const sessionManager = this.getSessionManager()\n if (!sessionManager) {\n return\n }\n if (typeof Object.assign === 'undefined') {\n // According to the rrweb docs, rrweb is not supported on IE11 and below:\n // \"rrweb does not support IE11 and below because it uses the MutationObserver API which was supported by these browsers.\"\n // https://github.com/rrweb-io/rrweb/blob/master/guide.md#compatibility-note\n //\n // However, MutationObserver does exist on IE11, it just doesn't work well and does not detect all changes.\n // Instead, when we load \"recorder.js\", the first JS error is about \"Object.assign\" being undefined.\n // Thus instead of MutationObserver, we look for this function and block recording if it's undefined.\n return\n }\n\n // We do not switch recorder versions midway through a recording.\n if (this.captureStarted || this.instance.get_config('disable_session_recording')) {\n return\n }\n\n this.captureStarted = true\n // We want to ensure the sessionManager is reset if necessary on load of the recorder\n sessionManager.checkAndGetSessionAndWindowId()\n\n const recorderJS = this.getRecordingVersion() === 'v2' ? 'recorder-v2.js' : 'recorder.js'\n\n // If recorder.js is already loaded (if array.full.js snippet is used or posthog-js/dist/recorder is\n // imported) or matches the requested recorder version, don't load script. Otherwise, remotely import\n // recorder.js from cdn since it hasn't been loaded.\n if (this.instance.__loaded_recorder_version !== this.getRecordingVersion()) {\n loadScript(\n this.instance.get_config('api_host') + `/static/${recorderJS}?v=${Config.LIB_VERSION}`,\n (err) => {\n if (err) {\n return logger.error(`Could not load ${recorderJS}`, err)\n }\n\n this._onScriptLoaded()\n }\n )\n } else {\n this._onScriptLoaded()\n }\n }\n\n private _isInteractiveEvent(event: eventWithTime) {\n return event.type === INCREMENTAL_SNAPSHOT_EVENT_TYPE && ACTIVE_SOURCES.indexOf(event.data?.source) !== -1\n }\n\n private _updateWindowAndSessionIds(event: eventWithTime) {\n const sessionManager = this.getSessionManager()\n if (!sessionManager) {\n return\n }\n // Some recording events are triggered by non-user events (e.g. \"X minutes ago\" text updating on the screen).\n // We don't want to extend the session or trigger a new session in these cases. These events are designated by event\n // type -> incremental update, and source -> mutation.\n\n const isUserInteraction = this._isInteractiveEvent(event)\n\n if (!isUserInteraction && !this.isIdle) {\n // We check if the lastActivityTimestamp is old enough to go idle\n if (event.timestamp - this.lastActivityTimestamp > RECORDING_IDLE_ACTIVITY_TIMEOUT_MS) {\n this.isIdle = true\n }\n }\n\n if (isUserInteraction) {\n this.lastActivityTimestamp = event.timestamp\n if (this.isIdle) {\n // Remove the idle state if set and trigger a full snapshot as we will have ingored previous mutations\n this.isIdle = false\n this._tryTakeFullSnapshot()\n }\n }\n\n if (this.isIdle) {\n return\n }\n\n // We only want to extend the session if it is an interactive event.\n const { windowId, sessionId } = sessionManager.checkAndGetSessionAndWindowId(\n !isUserInteraction,\n event.timestamp\n )\n\n if (\n [FULL_SNAPSHOT_EVENT_TYPE, META_EVENT_TYPE].indexOf(event.type) === -1 &&\n (this.windowId !== windowId || this.sessionId !== sessionId)\n ) {\n this._tryTakeFullSnapshot()\n }\n this.windowId = windowId\n this.sessionId = sessionId\n }\n\n private _tryTakeFullSnapshot(): boolean {\n if (!this.captureStarted) {\n return false\n }\n try {\n this.rrwebRecord?.takeFullSnapshot()\n return true\n } catch (e) {\n // Sometimes a race can occur where the recorder is not fully started yet, so we can't take a full snapshot.\n logger.error('Error taking full snapshot.', e)\n return false\n }\n }\n\n private _onScriptLoaded() {\n // rrweb config info: https://github.com/rrweb-io/rrweb/blob/7d5d0033258d6c29599fb08412202d9a2c7b9413/src/record/index.ts#L28\n const sessionRecordingOptions: recordOptions<eventWithTime> = {\n // select set of rrweb config options we expose to our users\n // see https://github.com/rrweb-io/rrweb/blob/master/guide.md\n blockClass: 'ph-no-capture',\n blockSelector: undefined,\n ignoreClass: 'ph-ignore-input',\n maskTextClass: 'ph-mask',\n maskTextSelector: undefined,\n maskTextFn: undefined,\n maskAllInputs: true,\n maskInputOptions: {},\n maskInputFn: undefined,\n slimDOMOptions: {},\n collectFonts: false,\n inlineStylesheet: true,\n recordCrossOriginIframes: false,\n }\n // We switched from loading all of rrweb to just the record part, but\n // keep backwards compatibility if someone hasn't upgraded PostHog\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.rrwebRecord = window.rrweb ? window.rrweb.record : window.rrwebRecord\n\n // only allows user to set our 'allowlisted' options\n const userSessionRecordingOptions = this.instance.get_config('session_recording')\n for (const [key, value] of Object.entries(userSessionRecordingOptions || {})) {\n if (key in sessionRecordingOptions) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n sessionRecordingOptions[key] = value\n }\n }\n\n if (!this.rrwebRecord) {\n logger.error(\n 'onScriptLoaded was called but rrwebRecord is not available. This indicates something has gone wrong.'\n )\n return\n }\n\n this.mutationRateLimiter =\n this.mutationRateLimiter ??\n new MutationRateLimiter(this.rrwebRecord!, {\n onBlockedNode: (id, node) => {\n const message = `Too many mutations on node '${id}'. Rate limiting. This could be due to SVG animations or something similar`\n logger.log(message, {\n node: node,\n })\n\n this.log('[PostHog Recorder] ' + message, 'warn')\n },\n })\n\n this.stopRrweb = this.rrwebRecord({\n emit: (event) => {\n this.onRRwebEmit(event)\n },\n plugins:\n (window as any).rrwebConsoleRecord && this.isConsoleLogCaptureEnabled()\n ? [(window as any).rrwebConsoleRecord.getRecordConsolePlugin()]\n : [],\n ...sessionRecordingOptions,\n })\n\n // :TRICKY: rrweb does not capture navigation within SPA-s, so hook into our $pageview events to get access to all events.\n // Dropping the initial event is fine (it's always captured by rrweb).\n this.instance._addCaptureHook((eventName) => {\n // If anything could go wrong here it has the potential to block the main loop so we catch all errors.\n try {\n if (eventName === '$pageview') {\n this.rrwebRecord?.addCustomEvent('$pageview', { href: window.location.href })\n }\n } catch (e) {\n logger.error('Could not add $pageview to rrweb session', e)\n }\n })\n\n // We reset the last activity timestamp, resetting the idle timer\n this.lastActivityTimestamp = Date.now()\n this.isIdle = false\n }\n\n onRRwebEmit(rawEvent: eventWithTime) {\n if (!rawEvent || typeof rawEvent !== 'object') {\n return\n }\n\n const throttledEvent = this.mutationRateLimiter\n ? this.mutationRateLimiter.throttleMutations(rawEvent)\n : rawEvent\n\n if (!throttledEvent) {\n return\n }\n\n const { event, size } = ensureMaxMessageSize(truncateLargeConsoleLogs(throttledEvent))\n\n this._updateWindowAndSessionIds(event)\n\n if (this.isIdle) {\n // When in an idle state we keep recording, but don't capture the events\n return\n }\n\n const properties = {\n $snapshot_bytes: size,\n $snapshot_data: event,\n $session_id: this.sessionId,\n $window_id: this.windowId,\n }\n\n if (this.emit) {\n this._captureSnapshotBuffered(properties)\n } else {\n this.snapshots.push(properties)\n }\n }\n\n private _flushBuffer() {\n if (this.flushBufferTimer) {\n clearTimeout(this.flushBufferTimer)\n this.flushBufferTimer = undefined\n }\n\n if (this.buffer && this.buffer.data.length !== 0) {\n this._captureSnapshot({\n $snapshot_bytes: this.buffer.size,\n $snapshot_data: this.buffer.data,\n $session_id: this.buffer.sessionId,\n $window_id: this.buffer.windowId,\n })\n }\n\n this.buffer = undefined\n\n return {\n size: 0,\n data: [],\n sessionId: this.sessionId,\n windowId: this.windowId,\n }\n }\n\n private _captureSnapshotBuffered(properties: Properties) {\n const additionalBytes = 2 + (this.buffer?.data.length || 0) // 2 bytes for the array brackets and 1 byte for each comma\n if (\n !this.buffer ||\n this.buffer.size + properties.$snapshot_bytes + additionalBytes > RECORDING_MAX_EVENT_SIZE ||\n this.buffer.sessionId !== this.sessionId\n ) {\n this.buffer = this._flushBuffer()\n }\n\n this.buffer.size += properties.$snapshot_bytes\n this.buffer.data.push(properties.$snapshot_data)\n\n if (!this.flushBufferTimer) {\n this.flushBufferTimer = setTimeout(() => {\n this._flushBuffer()\n }, RECORDING_BUFFER_TIMEOUT)\n }\n }\n\n private _captureSnapshot(properties: Properties) {\n // :TRICKY: Make sure we batch these requests, use a custom endpoint and don't truncate the strings.\n this.instance.capture('$snapshot', properties, {\n transport: 'XHR',\n method: 'POST',\n endpoint: this.endpoint,\n _noTruncate: true,\n _batchKey: SESSION_RECORDING_BATCH_KEY,\n _metrics: {\n rrweb_full_snapshot: properties.$snapshot_data.type === FULL_SNAPSHOT_EVENT_TYPE,\n },\n })\n }\n}\n"]}
@@ -20,19 +20,19 @@ export declare class PostHog {
20
20
  __loaded: boolean;
21
21
  __loaded_recorder_version: 'v1' | 'v2' | undefined;
22
22
  config: PostHogConfig;
23
- persistence: PostHogPersistence;
24
23
  rateLimiter: RateLimiter;
25
- sessionPersistence: PostHogPersistence;
26
- sessionManager: SessionIdManager;
27
24
  pageViewManager: PageViewManager;
28
25
  featureFlags: PostHogFeatureFlags;
29
26
  surveys: PostHogSurveys;
30
27
  toolbar: Toolbar;
31
- sessionRecording: SessionRecording | undefined;
32
- webPerformance: WebPerformanceObserver | undefined;
33
- exceptionAutocapture: ExceptionObserver | undefined;
34
- _requestQueue: RequestQueue;
35
- _retryQueue: RetryQueue;
28
+ persistence?: PostHogPersistence;
29
+ sessionPersistence?: PostHogPersistence;
30
+ sessionManager?: SessionIdManager;
31
+ _requestQueue?: RequestQueue;
32
+ _retryQueue?: RetryQueue;
33
+ sessionRecording?: SessionRecording;
34
+ webPerformance?: WebPerformanceObserver;
35
+ exceptionAutocapture?: ExceptionObserver;
36
36
  _triggered_notifs: any;
37
37
  compression: Partial<Record<Compression, boolean>>;
38
38
  _jsc: JSC;
@@ -257,12 +257,6 @@ var PostHog = /** @class */ (function () {
257
257
  this.pageViewManager = new PageViewManager();
258
258
  this.surveys = new PostHogSurveys(this);
259
259
  this.rateLimiter = new RateLimiter();
260
- // these are created in _init() after we have the config
261
- this._requestQueue = undefined;
262
- this._retryQueue = undefined;
263
- this.persistence = undefined;
264
- this.sessionPersistence = undefined;
265
- this.sessionManager = undefined;
266
260
  // NOTE: See the property definition for deprecation notice
267
261
  this.people = {
268
262
  set: function (prop, to, callback) {
@@ -441,7 +435,10 @@ var PostHog = /** @class */ (function () {
441
435
  // Pause `reloadFeatureFlags` calls in config.loaded callback.
442
436
  // These feature flags are loaded in the decide call made right
443
437
  // afterwards
444
- this.featureFlags.setReloadingPaused(true);
438
+ var disableDecide = this.get_config('advanced_disable_decide');
439
+ if (!disableDecide) {
440
+ this.featureFlags.setReloadingPaused(true);
441
+ }
445
442
  try {
446
443
  this.get_config('loaded')(this);
447
444
  }
@@ -457,16 +454,15 @@ var PostHog = /** @class */ (function () {
457
454
  // Call decide to get what features are enabled and other settings.
458
455
  // As a reminder, if the /decide endpoint is disabled, feature flags, toolbar, session recording, autocapture,
459
456
  // and compression will not be available.
460
- if (!this.get_config('advanced_disable_decide')) {
457
+ if (!disableDecide) {
461
458
  new Decide(this).call();
462
459
  }
463
- this.featureFlags.resetRequestQueue();
464
- this.featureFlags.setReloadingPaused(false);
465
460
  };
466
461
  PostHog.prototype._start_queue_if_opted_in = function () {
462
+ var _a;
467
463
  if (!this.has_opted_out_capturing()) {
468
464
  if (this.get_config('request_batching')) {
469
- this._requestQueue.poll();
465
+ (_a = this._requestQueue) === null || _a === void 0 ? void 0 : _a.poll();
470
466
  }
471
467
  }
472
468
  };
@@ -514,6 +510,7 @@ var PostHog = /** @class */ (function () {
514
510
  }
515
511
  };
516
512
  PostHog.prototype._handle_unload = function () {
513
+ var _a, _b;
517
514
  if (!this.get_config('request_batching')) {
518
515
  if (this.get_config('capture_pageview') && this.get_config('capture_pageleave')) {
519
516
  this.capture('$pageleave', null, { transport: 'sendBeacon' });
@@ -523,8 +520,8 @@ var PostHog = /** @class */ (function () {
523
520
  if (this.get_config('capture_pageview') && this.get_config('capture_pageleave')) {
524
521
  this.capture('$pageleave');
525
522
  }
526
- this._requestQueue.unload();
527
- this._retryQueue.unload();
523
+ (_a = this._requestQueue) === null || _a === void 0 ? void 0 : _a.unload();
524
+ (_b = this._retryQueue) === null || _b === void 0 ? void 0 : _b.unload();
528
525
  };
529
526
  PostHog.prototype._handle_queued_event = function (url, data, options) {
530
527
  var jsonData = JSON.stringify(data);
@@ -536,6 +533,9 @@ var PostHog = /** @class */ (function () {
536
533
  };
537
534
  PostHog.prototype._send_request = function (url, data, options, callback) {
538
535
  var _a;
536
+ if (!this.__loaded || !this._retryQueue) {
537
+ return;
538
+ }
539
539
  if (this.rateLimiter.isRateLimited(options._batchKey)) {
540
540
  if (this.get_config('debug')) {
541
541
  console.warn('[PostHog SendRequest] is quota limited. Dropping request.');
@@ -715,8 +715,8 @@ var PostHog = /** @class */ (function () {
715
715
  if (options === void 0) { options = __NOOPTIONS; }
716
716
  // While developing, a developer might purposefully _not_ call init(),
717
717
  // in this case, we would like capture to be a noop.
718
- if (!this.__loaded) {
719
- return;
718
+ if (!this.__loaded || !this.sessionPersistence || !this._requestQueue) {
719
+ return logger.unintializedWarning('posthog.capture');
720
720
  }
721
721
  if (userOptedOut(this, false)) {
722
722
  return;
@@ -778,6 +778,9 @@ var PostHog = /** @class */ (function () {
778
778
  _each(this.__captureHooks, function (callback) { return callback(eventName); });
779
779
  };
780
780
  PostHog.prototype._calculate_event_properties = function (event_name, event_properties) {
781
+ if (!this.persistence || !this.sessionPersistence) {
782
+ return event_properties;
783
+ }
781
784
  // set defaults
782
785
  var start_timestamp = this.persistence.remove_event_timer(event_name);
783
786
  var properties = __assign({}, event_properties);
@@ -861,7 +864,8 @@ var PostHog = /** @class */ (function () {
861
864
  * @param {Number} [days] How many days since the user's last visit to store the super properties
862
865
  */
863
866
  PostHog.prototype.register = function (properties, days) {
864
- this.persistence.register(properties, days);
867
+ var _a;
868
+ (_a = this.persistence) === null || _a === void 0 ? void 0 : _a.register(properties, days);
865
869
  };
866
870
  /**
867
871
  * Register a set of super properties only once. These will not
@@ -887,7 +891,8 @@ var PostHog = /** @class */ (function () {
887
891
  * @param {Number} [days] How many days since the users last visit to store the super properties
888
892
  */
889
893
  PostHog.prototype.register_once = function (properties, default_value, days) {
890
- this.persistence.register_once(properties, default_value, days);
894
+ var _a;
895
+ (_a = this.persistence) === null || _a === void 0 ? void 0 : _a.register_once(properties, default_value, days);
891
896
  };
892
897
  /**
893
898
  * Register a set of super properties, which are included with all events, but only
@@ -913,7 +918,8 @@ var PostHog = /** @class */ (function () {
913
918
  * @param {Object} properties An associative array of properties to store about the user
914
919
  */
915
920
  PostHog.prototype.register_for_session = function (properties) {
916
- this.sessionPersistence.register(properties);
921
+ var _a;
922
+ (_a = this.sessionPersistence) === null || _a === void 0 ? void 0 : _a.register(properties);
917
923
  };
918
924
  /**
919
925
  * Delete a super property stored with the current user.
@@ -921,7 +927,8 @@ var PostHog = /** @class */ (function () {
921
927
  * @param {String} property The name of the super property to remove
922
928
  */
923
929
  PostHog.prototype.unregister = function (property) {
924
- this.persistence.unregister(property);
930
+ var _a;
931
+ (_a = this.persistence) === null || _a === void 0 ? void 0 : _a.unregister(property);
925
932
  };
926
933
  /**
927
934
  * Delete a session super property stored with the current user.
@@ -929,7 +936,8 @@ var PostHog = /** @class */ (function () {
929
936
  * @param {String} property The name of the session super property to remove
930
937
  */
931
938
  PostHog.prototype.unregister_for_session = function (property) {
932
- this.sessionPersistence.unregister(property);
939
+ var _a;
940
+ (_a = this.sessionPersistence) === null || _a === void 0 ? void 0 : _a.unregister(property);
933
941
  };
934
942
  PostHog.prototype._register_single = function (prop, value) {
935
943
  var _a;
@@ -1023,7 +1031,8 @@ var PostHog = /** @class */ (function () {
1023
1031
  * @returns {Function} A function that can be called to unsubscribe the listener. E.g. Used by useEffect when the component unmounts.
1024
1032
  */
1025
1033
  PostHog.prototype.onSessionId = function (callback) {
1026
- return this.sessionManager.onSessionId(callback);
1034
+ var _a, _b;
1035
+ return (_b = (_a = this.sessionManager) === null || _a === void 0 ? void 0 : _a.onSessionId(callback)) !== null && _b !== void 0 ? _b : (function () { });
1027
1036
  };
1028
1037
  /** Get list of all surveys. */
1029
1038
  PostHog.prototype.getSurveys = function (callback, forceReload) {
@@ -1082,6 +1091,9 @@ var PostHog = /** @class */ (function () {
1082
1091
  * @param {Object} [userPropertiesToSetOnce] Optional: An associative array of properties to store about the user. If property is previously set, this does not override that value.
1083
1092
  */
1084
1093
  PostHog.prototype.identify = function (new_distinct_id, userPropertiesToSet, userPropertiesToSetOnce) {
1094
+ if (!this.__loaded || !this.persistence) {
1095
+ return logger.unintializedWarning('posthog.identify');
1096
+ }
1085
1097
  //if the new_distinct_id has not been set ignore the identify event
1086
1098
  if (!new_distinct_id) {
1087
1099
  console.error('Unique user id has not been set in posthog.identify');
@@ -1221,11 +1233,15 @@ var PostHog = /** @class */ (function () {
1221
1233
  * Useful for clearing data when a user logs out.
1222
1234
  */
1223
1235
  PostHog.prototype.reset = function (reset_device_id) {
1236
+ var _a, _b, _c, _d;
1237
+ if (!this.__loaded) {
1238
+ return logger.unintializedWarning('posthog.reset');
1239
+ }
1224
1240
  var device_id = this.get_property('$device_id');
1225
- this.persistence.clear();
1226
- this.sessionPersistence.clear();
1227
- this.persistence.set_user_state('anonymous');
1228
- this.sessionManager.resetSessionId();
1241
+ (_a = this.persistence) === null || _a === void 0 ? void 0 : _a.clear();
1242
+ (_b = this.sessionPersistence) === null || _b === void 0 ? void 0 : _b.clear();
1243
+ (_c = this.persistence) === null || _c === void 0 ? void 0 : _c.set_user_state('anonymous');
1244
+ (_d = this.sessionManager) === null || _d === void 0 ? void 0 : _d.resetSessionId();
1229
1245
  var uuid = this.get_config('get_device_id')(uuidv7());
1230
1246
  this.register_once({
1231
1247
  distinct_id: uuid,
@@ -1261,7 +1277,8 @@ var PostHog = /** @class */ (function () {
1261
1277
  * Any actual internal use case for the session_id should be handled by the sessionManager.
1262
1278
  */
1263
1279
  PostHog.prototype.get_session_id = function () {
1264
- return this.sessionManager.checkAndGetSessionAndWindowId(true).sessionId;
1280
+ var _a, _b;
1281
+ return (_b = (_a = this.sessionManager) === null || _a === void 0 ? void 0 : _a.checkAndGetSessionAndWindowId(true).sessionId) !== null && _b !== void 0 ? _b : '';
1265
1282
  };
1266
1283
  /**
1267
1284
  * Returns the Replay url for the current session.
@@ -1272,6 +1289,9 @@ var PostHog = /** @class */ (function () {
1272
1289
  */
1273
1290
  PostHog.prototype.get_session_replay_url = function (options) {
1274
1291
  var _a;
1292
+ if (!this.sessionManager) {
1293
+ return '';
1294
+ }
1275
1295
  var host = this.config.ui_host || this.config.api_host;
1276
1296
  var _b = this.sessionManager.checkAndGetSessionAndWindowId(true), sessionId = _b.sessionId, sessionStartTimestamp = _b.sessionStartTimestamp;
1277
1297
  var url = host + '/replay/' + sessionId;
@@ -1460,6 +1480,7 @@ var PostHog = /** @class */ (function () {
1460
1480
  * @param {Object} config A dictionary of new configuration values to update
1461
1481
  */
1462
1482
  PostHog.prototype.set_config = function (config) {
1483
+ var _a, _b;
1463
1484
  var oldConfig = __assign({}, this.config);
1464
1485
  if (_isObject(config)) {
1465
1486
  _extend(this.config, config);
@@ -1469,12 +1490,8 @@ var PostHog = /** @class */ (function () {
1469
1490
  if (!this.get_config('disable_persistence')) {
1470
1491
  this.config.disable_persistence = this.config.disable_cookie;
1471
1492
  }
1472
- if (this.persistence) {
1473
- this.persistence.update_config(this.config);
1474
- }
1475
- if (this.sessionPersistence) {
1476
- this.sessionPersistence.update_config(this.config);
1477
- }
1493
+ (_a = this.persistence) === null || _a === void 0 ? void 0 : _a.update_config(this.config);
1494
+ (_b = this.sessionPersistence) === null || _b === void 0 ? void 0 : _b.update_config(this.config);
1478
1495
  if (localStore.is_supported() && localStore.get('ph_debug') === 'true') {
1479
1496
  this.config.debug = true;
1480
1497
  }
@@ -1548,7 +1565,8 @@ var PostHog = /** @class */ (function () {
1548
1565
  * @param {String} property_name The name of the super property you want to retrieve
1549
1566
  */
1550
1567
  PostHog.prototype.get_property = function (property_name) {
1551
- return this.persistence['props'][property_name];
1568
+ var _a;
1569
+ return (_a = this.persistence) === null || _a === void 0 ? void 0 : _a['props'][property_name];
1552
1570
  };
1553
1571
  /**
1554
1572
  * Returns the value of the session super property named property_name. If no such
@@ -1570,7 +1588,8 @@ var PostHog = /** @class */ (function () {
1570
1588
  * @param {String} property_name The name of the session super property you want to retrieve
1571
1589
  */
1572
1590
  PostHog.prototype.getSessionProperty = function (property_name) {
1573
- return this.sessionPersistence['props'][property_name];
1591
+ var _a;
1592
+ return (_a = this.sessionPersistence) === null || _a === void 0 ? void 0 : _a['props'][property_name];
1574
1593
  };
1575
1594
  PostHog.prototype.toString = function () {
1576
1595
  var _a;
@@ -1618,6 +1637,7 @@ var PostHog = /** @class */ (function () {
1618
1637
  * @param {boolean} [options.enable_persistence] If true, will re-enable sdk persistence
1619
1638
  */
1620
1639
  PostHog.prototype._gdpr_update_persistence = function (options) {
1640
+ var _a, _b, _c, _d;
1621
1641
  var disabled;
1622
1642
  if (options && options['clear_persistence']) {
1623
1643
  disabled = true;
@@ -1628,11 +1648,11 @@ var PostHog = /** @class */ (function () {
1628
1648
  else {
1629
1649
  return;
1630
1650
  }
1631
- if (!this.get_config('disable_persistence') && this.persistence.disabled !== disabled) {
1632
- this.persistence.set_disabled(disabled);
1651
+ if (!this.get_config('disable_persistence') && ((_a = this.persistence) === null || _a === void 0 ? void 0 : _a.disabled) !== disabled) {
1652
+ (_b = this.persistence) === null || _b === void 0 ? void 0 : _b.set_disabled(disabled);
1633
1653
  }
1634
- if (!this.get_config('disable_persistence') && this.sessionPersistence.disabled !== disabled) {
1635
- this.sessionPersistence.set_disabled(disabled);
1654
+ if (!this.get_config('disable_persistence') && ((_c = this.sessionPersistence) === null || _c === void 0 ? void 0 : _c.disabled) !== disabled) {
1655
+ (_d = this.sessionPersistence) === null || _d === void 0 ? void 0 : _d.set_disabled(disabled);
1636
1656
  }
1637
1657
  };
1638
1658
  // call a base gdpr function after constructing the appropriate token and options args