@leanbase.com/js 0.2.1 → 0.2.2-alpha.0

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.
Files changed (71) hide show
  1. package/dist/extensions/replay/external/config.d.ts +9 -0
  2. package/dist/extensions/replay/external/denylist.d.ts +5 -0
  3. package/dist/extensions/replay/external/lazy-loaded-session-recorder.d.ts +153 -0
  4. package/dist/extensions/replay/external/mutation-throttler.d.ts +20 -0
  5. package/dist/extensions/replay/external/network-plugin.d.ts +15 -0
  6. package/dist/extensions/replay/external/sessionrecording-utils.d.ts +19 -0
  7. package/dist/extensions/replay/external/triggerMatching.d.ts +102 -0
  8. package/dist/extensions/replay/rrweb-plugins/patch.d.ts +3 -0
  9. package/dist/extensions/replay/session-recording.d.ts +75 -0
  10. package/dist/extensions/replay/types/rrweb-types.d.ts +439 -0
  11. package/dist/extensions/replay/types/rrweb.d.ts +82 -0
  12. package/dist/extensions/sampling.d.ts +4 -0
  13. package/dist/leanbase.d.ts +3 -0
  14. package/dist/leanbase.iife.js +1 -1
  15. package/dist/leanbase.iife.js.map +1 -1
  16. package/dist/main.js +1 -1
  17. package/dist/main.js.map +1 -1
  18. package/dist/module.d.ts +708 -0
  19. package/dist/module.js +1 -1
  20. package/dist/module.js.map +1 -1
  21. package/dist/types.d.ts +135 -0
  22. package/dist/utils/logger.d.ts +10 -0
  23. package/dist/version.d.ts +1 -1
  24. package/lib/extensions/replay/external/config.d.ts +9 -0
  25. package/lib/extensions/replay/external/config.js +221 -0
  26. package/lib/extensions/replay/external/config.js.map +1 -0
  27. package/lib/extensions/replay/external/denylist.d.ts +5 -0
  28. package/lib/extensions/replay/external/denylist.js +28 -0
  29. package/lib/extensions/replay/external/denylist.js.map +1 -0
  30. package/lib/extensions/replay/external/lazy-loaded-session-recorder.d.ts +153 -0
  31. package/lib/extensions/replay/external/lazy-loaded-session-recorder.js +1042 -0
  32. package/lib/extensions/replay/external/lazy-loaded-session-recorder.js.map +1 -0
  33. package/lib/extensions/replay/external/mutation-throttler.d.ts +20 -0
  34. package/lib/extensions/replay/external/mutation-throttler.js +77 -0
  35. package/lib/extensions/replay/external/mutation-throttler.js.map +1 -0
  36. package/lib/extensions/replay/external/network-plugin.d.ts +15 -0
  37. package/lib/extensions/replay/external/network-plugin.js +503 -0
  38. package/lib/extensions/replay/external/network-plugin.js.map +1 -0
  39. package/lib/extensions/replay/external/sessionrecording-utils.d.ts +19 -0
  40. package/lib/extensions/replay/external/sessionrecording-utils.js +125 -0
  41. package/lib/extensions/replay/external/sessionrecording-utils.js.map +1 -0
  42. package/lib/extensions/replay/external/triggerMatching.d.ts +102 -0
  43. package/lib/extensions/replay/external/triggerMatching.js +342 -0
  44. package/lib/extensions/replay/external/triggerMatching.js.map +1 -0
  45. package/lib/extensions/replay/rrweb-plugins/patch.d.ts +3 -0
  46. package/lib/extensions/replay/rrweb-plugins/patch.js +32 -0
  47. package/lib/extensions/replay/rrweb-plugins/patch.js.map +1 -0
  48. package/lib/extensions/replay/session-recording.d.ts +75 -0
  49. package/lib/extensions/replay/session-recording.js +279 -0
  50. package/lib/extensions/replay/session-recording.js.map +1 -0
  51. package/lib/extensions/replay/types/rrweb-types.d.ts +439 -0
  52. package/lib/extensions/replay/types/rrweb-types.js +83 -0
  53. package/lib/extensions/replay/types/rrweb-types.js.map +1 -0
  54. package/lib/extensions/replay/types/rrweb.d.ts +82 -0
  55. package/lib/extensions/replay/types/rrweb.js +9 -0
  56. package/lib/extensions/replay/types/rrweb.js.map +1 -0
  57. package/lib/extensions/sampling.d.ts +4 -0
  58. package/lib/extensions/sampling.js +23 -0
  59. package/lib/extensions/sampling.js.map +1 -0
  60. package/lib/leanbase.d.ts +3 -0
  61. package/lib/leanbase.js +25 -0
  62. package/lib/leanbase.js.map +1 -1
  63. package/lib/types.d.ts +135 -0
  64. package/lib/types.js.map +1 -1
  65. package/lib/utils/logger.d.ts +10 -0
  66. package/lib/utils/logger.js +15 -0
  67. package/lib/utils/logger.js.map +1 -0
  68. package/lib/version.d.ts +1 -1
  69. package/lib/version.js +1 -1
  70. package/lib/version.js.map +1 -1
  71. package/package.json +5 -21
package/dist/module.d.ts CHANGED
@@ -1,5 +1,508 @@
1
1
  import { PostHogCoreOptions, FeatureFlagValue, JsonType, PostHogCore, PostHogFetchOptions, PostHogFetchResponse, PostHogPersistedProperty, PostHogEventProperties } from '@posthog/core';
2
2
 
3
+ interface IMirror<TNode> {
4
+ getId(n: TNode | undefined | null): number;
5
+ getNode(id: number): TNode | null;
6
+ getIds(): number[];
7
+ getMeta(n: TNode): serializedNodeWithId | null;
8
+ removeNodeFromMap(n: TNode): void;
9
+ has(id: number): boolean;
10
+ hasNode(node: TNode): boolean;
11
+ add(n: TNode, meta: serializedNodeWithId): void;
12
+ replace(id: number, n: TNode): void;
13
+ reset(): void;
14
+ }
15
+ declare class Mirror implements IMirror<Node> {
16
+ private idNodeMap;
17
+ private nodeMetaMap;
18
+ getId(n: Node | undefined | null): number;
19
+ getNode(id: number): Node | null;
20
+ getIds(): number[];
21
+ getMeta(n: Node): serializedNodeWithId | null;
22
+ removeNodeFromMap(n: Node): void;
23
+ has(id: number): boolean;
24
+ hasNode(node: Node): boolean;
25
+ add(n: Node, meta: serializedNodeWithId): void;
26
+ replace(id: number, n: Node): void;
27
+ reset(): void;
28
+ }
29
+ type attributes = {
30
+ [key: string]: string | number | true | null;
31
+ };
32
+ declare enum NodeType {
33
+ Document = 0,
34
+ DocumentType = 1,
35
+ Element = 2,
36
+ Text = 3,
37
+ CDATA = 4,
38
+ Comment = 5
39
+ }
40
+ type documentNode = {
41
+ type: NodeType.Document;
42
+ childNodes: serializedNodeWithId[];
43
+ compatMode?: string;
44
+ };
45
+ type documentTypeNode = {
46
+ type: NodeType.DocumentType;
47
+ name: string;
48
+ publicId: string;
49
+ systemId: string;
50
+ };
51
+ type elementNode = {
52
+ type: NodeType.Element;
53
+ tagName: string;
54
+ attributes: attributes;
55
+ childNodes: serializedNodeWithId[];
56
+ isSVG?: true;
57
+ needBlock?: boolean;
58
+ isCustom?: true;
59
+ };
60
+ type textNode = {
61
+ type: NodeType.Text;
62
+ textContent: string;
63
+ isStyle?: true;
64
+ };
65
+ type cdataNode = {
66
+ type: NodeType.CDATA;
67
+ textContent: '';
68
+ };
69
+ type commentNode = {
70
+ type: NodeType.Comment;
71
+ textContent: string;
72
+ };
73
+ type serializedNode = (documentNode | documentTypeNode | elementNode | textNode | cdataNode | commentNode) & {
74
+ rootId?: number;
75
+ isShadowHost?: boolean;
76
+ isShadow?: boolean;
77
+ };
78
+ type serializedNodeWithId = serializedNode & {
79
+ id: number;
80
+ };
81
+ type blockClass = string | RegExp;
82
+ type maskTextClass = string | RegExp;
83
+ type IWindow = Window & typeof globalThis;
84
+ type listenerHandler = () => void;
85
+ type KeepIframeSrcFn = (src: string) => boolean;
86
+ type PackFn = (event: eventWithTime) => string;
87
+ declare enum EventType {
88
+ DomContentLoaded = 0,
89
+ Load = 1,
90
+ FullSnapshot = 2,
91
+ IncrementalSnapshot = 3,
92
+ Meta = 4,
93
+ Custom = 5,
94
+ Plugin = 6
95
+ }
96
+ declare enum IncrementalSource {
97
+ Mutation = 0,
98
+ MouseMove = 1,
99
+ MouseInteraction = 2,
100
+ Scroll = 3,
101
+ ViewportResize = 4,
102
+ Input = 5,
103
+ TouchMove = 6,
104
+ MediaInteraction = 7,
105
+ StyleSheetRule = 8,
106
+ CanvasMutation = 9,
107
+ Font = 10,
108
+ Log = 11,
109
+ Drag = 12,
110
+ StyleDeclaration = 13,
111
+ Selection = 14,
112
+ AdoptedStyleSheet = 15,
113
+ CustomElement = 16
114
+ }
115
+ type domContentLoadedEvent = {
116
+ type: EventType.DomContentLoaded;
117
+ data: unknown;
118
+ };
119
+ type loadedEvent = {
120
+ type: EventType.Load;
121
+ data: unknown;
122
+ };
123
+ type fullSnapshotEvent = {
124
+ type: EventType.FullSnapshot;
125
+ data: {
126
+ node: serializedNodeWithId;
127
+ initialOffset: {
128
+ top: number;
129
+ left: number;
130
+ };
131
+ };
132
+ };
133
+ type metaEvent = {
134
+ type: EventType.Meta;
135
+ data: {
136
+ href: string;
137
+ width: number;
138
+ height: number;
139
+ };
140
+ };
141
+ type customEvent<T = unknown> = {
142
+ type: EventType.Custom;
143
+ data: {
144
+ tag: string;
145
+ payload: T;
146
+ };
147
+ };
148
+ type pluginEvent<T = unknown> = {
149
+ type: EventType.Plugin;
150
+ data: {
151
+ plugin: string;
152
+ payload: T;
153
+ };
154
+ };
155
+ type styleOMValue = {
156
+ [key: string]: styleValueWithPriority | string | false;
157
+ };
158
+ type styleValueWithPriority = [string, string];
159
+ type textMutation = {
160
+ id: number;
161
+ value: string | null;
162
+ };
163
+ type attributeMutation = {
164
+ id: number;
165
+ attributes: {
166
+ [key: string]: string | styleOMValue | null;
167
+ };
168
+ };
169
+ type removedNodeMutation = {
170
+ parentId: number;
171
+ id: number;
172
+ isShadow?: boolean;
173
+ };
174
+ type addedNodeMutation = {
175
+ parentId: number;
176
+ previousId?: number | null;
177
+ nextId: number | null;
178
+ node: serializedNodeWithId;
179
+ };
180
+ type mutationCallbackParam = {
181
+ texts: textMutation[];
182
+ attributes: attributeMutation[];
183
+ removes: removedNodeMutation[];
184
+ adds: addedNodeMutation[];
185
+ isAttachIframe?: true;
186
+ };
187
+ type mutationData = {
188
+ source: IncrementalSource.Mutation;
189
+ } & mutationCallbackParam;
190
+ type mousePosition = {
191
+ x: number;
192
+ y: number;
193
+ id: number;
194
+ timeOffset: number;
195
+ };
196
+ declare enum MouseInteractions {
197
+ MouseUp = 0,
198
+ MouseDown = 1,
199
+ Click = 2,
200
+ ContextMenu = 3,
201
+ DblClick = 4,
202
+ Focus = 5,
203
+ Blur = 6,
204
+ TouchStart = 7,
205
+ TouchMove_Departed = 8,
206
+ TouchEnd = 9,
207
+ TouchCancel = 10
208
+ }
209
+ declare enum PointerTypes {
210
+ Mouse = 0,
211
+ Pen = 1,
212
+ Touch = 2
213
+ }
214
+ type mouseInteractionParam = {
215
+ type: MouseInteractions;
216
+ id: number;
217
+ x?: number;
218
+ y?: number;
219
+ pointerType?: PointerTypes;
220
+ };
221
+ type mouseInteractionData = {
222
+ source: IncrementalSource.MouseInteraction;
223
+ } & mouseInteractionParam;
224
+ type mousemoveData = {
225
+ source: IncrementalSource.MouseMove | IncrementalSource.TouchMove | IncrementalSource.Drag;
226
+ positions: mousePosition[];
227
+ };
228
+ type scrollPosition = {
229
+ id: number;
230
+ x: number;
231
+ y: number;
232
+ };
233
+ type scrollData = {
234
+ source: IncrementalSource.Scroll;
235
+ } & scrollPosition;
236
+ type viewportResizeDimension = {
237
+ width: number;
238
+ height: number;
239
+ };
240
+ type viewportResizeData = {
241
+ source: IncrementalSource.ViewportResize;
242
+ } & viewportResizeDimension;
243
+ type inputValue = {
244
+ text: string;
245
+ isChecked: boolean;
246
+ userTriggered?: boolean;
247
+ };
248
+ type inputData = {
249
+ source: IncrementalSource.Input;
250
+ id: number;
251
+ } & inputValue;
252
+ declare enum MediaInteractions {
253
+ Play = 0,
254
+ Pause = 1,
255
+ Seeked = 2,
256
+ VolumeChange = 3,
257
+ RateChange = 4
258
+ }
259
+ type mediaInteractionParam = {
260
+ type: MediaInteractions;
261
+ id: number;
262
+ currentTime?: number;
263
+ volume?: number;
264
+ muted?: boolean;
265
+ loop?: boolean;
266
+ playbackRate?: number;
267
+ };
268
+ type mediaInteractionData = {
269
+ source: IncrementalSource.MediaInteraction;
270
+ } & mediaInteractionParam;
271
+ type styleSheetAddRule = {
272
+ rule: string;
273
+ index?: number | number[];
274
+ };
275
+ type styleSheetDeleteRule = {
276
+ index: number | number[];
277
+ };
278
+ type styleSheetRuleParam = {
279
+ id?: number;
280
+ styleId?: number;
281
+ removes?: styleSheetDeleteRule[];
282
+ adds?: styleSheetAddRule[];
283
+ replace?: string;
284
+ replaceSync?: string;
285
+ };
286
+ type styleSheetRuleData = {
287
+ source: IncrementalSource.StyleSheetRule;
288
+ } & styleSheetRuleParam;
289
+ declare enum CanvasContext {
290
+ '2D' = 0,
291
+ WebGL = 1,
292
+ WebGL2 = 2
293
+ }
294
+ type canvasMutationCommand = {
295
+ property: string;
296
+ args: Array<unknown>;
297
+ setter?: true;
298
+ };
299
+ type canvasMutationParam = {
300
+ id: number;
301
+ type: CanvasContext;
302
+ commands: canvasMutationCommand[];
303
+ } | ({
304
+ id: number;
305
+ type: CanvasContext;
306
+ } & canvasMutationCommand);
307
+ type canvasMutationData = {
308
+ source: IncrementalSource.CanvasMutation;
309
+ } & canvasMutationParam;
310
+ type fontParam = {
311
+ family: string;
312
+ fontSource: string;
313
+ buffer: boolean;
314
+ descriptors?: FontFaceDescriptors;
315
+ };
316
+ type fontData = {
317
+ source: IncrementalSource.Font;
318
+ } & fontParam;
319
+ type SelectionRange = {
320
+ start: number;
321
+ startOffset: number;
322
+ end: number;
323
+ endOffset: number;
324
+ };
325
+ type selectionParam = {
326
+ ranges: Array<SelectionRange>;
327
+ };
328
+ type selectionData = {
329
+ source: IncrementalSource.Selection;
330
+ } & selectionParam;
331
+ type styleDeclarationParam = {
332
+ id?: number;
333
+ styleId?: number;
334
+ index: number[];
335
+ set?: {
336
+ property: string;
337
+ value: string | null;
338
+ priority: string | undefined;
339
+ };
340
+ remove?: {
341
+ property: string;
342
+ };
343
+ };
344
+ type styleDeclarationData = {
345
+ source: IncrementalSource.StyleDeclaration;
346
+ } & styleDeclarationParam;
347
+ type adoptedStyleSheetParam = {
348
+ id: number;
349
+ styles?: {
350
+ styleId: number;
351
+ rules: styleSheetAddRule[];
352
+ }[];
353
+ styleIds: number[];
354
+ };
355
+ type adoptedStyleSheetData = {
356
+ source: IncrementalSource.AdoptedStyleSheet;
357
+ } & adoptedStyleSheetParam;
358
+ type customElementParam = {
359
+ define?: {
360
+ name: string;
361
+ };
362
+ };
363
+ type customElementData = {
364
+ source: IncrementalSource.CustomElement;
365
+ } & customElementParam;
366
+ type incrementalData = mutationData | mousemoveData | mouseInteractionData | scrollData | viewportResizeData | inputData | mediaInteractionData | styleSheetRuleData | canvasMutationData | fontData | selectionData | styleDeclarationData | adoptedStyleSheetData | customElementData;
367
+ type incrementalSnapshotEvent = {
368
+ type: EventType.IncrementalSnapshot;
369
+ data: incrementalData;
370
+ };
371
+ type eventWithoutTime = domContentLoadedEvent | loadedEvent | fullSnapshotEvent | incrementalSnapshotEvent | metaEvent | customEvent | pluginEvent;
372
+ type eventWithTime = eventWithoutTime & {
373
+ timestamp: number;
374
+ delay?: number;
375
+ };
376
+ type mutationCallBack = (m: mutationCallbackParam) => void;
377
+ type mousemoveCallBack = (p: mousePosition[], source: IncrementalSource.MouseMove | IncrementalSource.TouchMove | IncrementalSource.Drag) => void;
378
+ type mouseInteractionCallBack = (d: mouseInteractionParam) => void;
379
+ type scrollCallback = (p: scrollPosition) => void;
380
+ type viewportResizeCallback = (d: viewportResizeDimension) => void;
381
+ type inputCallback = (v: inputValue & {
382
+ id: number;
383
+ }) => void;
384
+ type mediaInteractionCallback = (p: mediaInteractionParam) => void;
385
+ type styleSheetRuleCallback = (s: styleSheetRuleParam) => void;
386
+ type styleDeclarationCallback = (s: styleDeclarationParam) => void;
387
+ type canvasMutationCallback = (p: canvasMutationParam) => void;
388
+ type fontCallback = (p: fontParam) => void;
389
+ type selectionCallback = (p: selectionParam) => void;
390
+ type customElementCallback = (c: customElementParam) => void;
391
+ type hooksParam = {
392
+ mutation?: mutationCallBack;
393
+ mousemove?: mousemoveCallBack;
394
+ mouseInteraction?: mouseInteractionCallBack;
395
+ scroll?: scrollCallback;
396
+ viewportResize?: viewportResizeCallback;
397
+ input?: inputCallback;
398
+ mediaInteaction?: mediaInteractionCallback;
399
+ styleSheetRule?: styleSheetRuleCallback;
400
+ styleDeclaration?: styleDeclarationCallback;
401
+ canvasMutation?: canvasMutationCallback;
402
+ font?: fontCallback;
403
+ selection?: selectionCallback;
404
+ customElement?: customElementCallback;
405
+ };
406
+ type SamplingStrategy = Partial<{
407
+ mousemove: boolean | number;
408
+ mousemoveCallback: number;
409
+ mouseInteraction: boolean | Record<string, boolean | undefined>;
410
+ scroll: number;
411
+ media: number;
412
+ input: 'all' | 'last';
413
+ canvas: 'all' | number;
414
+ }>;
415
+ interface ICrossOriginIframeMirror {
416
+ getId(iframe: HTMLIFrameElement, remoteId: number, parentToRemoteMap?: Map<number, number>, remoteToParentMap?: Map<number, number>): number;
417
+ getIds(iframe: HTMLIFrameElement, remoteId: number[]): number[];
418
+ getRemoteId(iframe: HTMLIFrameElement, parentId: number, map?: Map<number, number>): number;
419
+ getRemoteIds(iframe: HTMLIFrameElement, parentId: number[]): number[];
420
+ reset(iframe?: HTMLIFrameElement): void;
421
+ }
422
+ type RecordPlugin<TOptions = unknown> = {
423
+ name: string;
424
+ observer?: (cb: (...args: Array<unknown>) => void, win: IWindow, options: TOptions) => listenerHandler;
425
+ eventProcessor?: <TExtend>(event: eventWithTime) => eventWithTime & TExtend;
426
+ getMirror?: (mirrors: {
427
+ nodeMirror: Mirror;
428
+ crossOriginIframeMirror: ICrossOriginIframeMirror;
429
+ crossOriginIframeStyleMirror: ICrossOriginIframeMirror;
430
+ }) => void;
431
+ options: TOptions;
432
+ };
433
+
434
+ type MaskInputOptions = Partial<{
435
+ color: boolean;
436
+ date: boolean;
437
+ 'datetime-local': boolean;
438
+ email: boolean;
439
+ month: boolean;
440
+ number: boolean;
441
+ range: boolean;
442
+ search: boolean;
443
+ tel: boolean;
444
+ text: boolean;
445
+ time: boolean;
446
+ url: boolean;
447
+ week: boolean;
448
+ textarea: boolean;
449
+ select: boolean;
450
+ password: boolean;
451
+ }>;
452
+ type MaskInputFn = (text: string, element: HTMLElement) => string;
453
+ type MaskTextFn = (text: string, element: HTMLElement | null) => string;
454
+ type SlimDOMOptions = Partial<{
455
+ script: boolean;
456
+ comment: boolean;
457
+ headFavicon: boolean;
458
+ headWhitespace: boolean;
459
+ headMetaDescKeywords: boolean;
460
+ headMetaSocial: boolean;
461
+ headMetaRobots: boolean;
462
+ headMetaHttpEquiv: boolean;
463
+ headMetaAuthorship: boolean;
464
+ headMetaVerification: boolean;
465
+ headTitleMutations: boolean;
466
+ }>;
467
+ type DataURLOptions = Partial<{
468
+ type: string;
469
+ quality: number;
470
+ }>;
471
+ type ErrorHandler = (error: unknown) => void | boolean;
472
+ type recordOptions = {
473
+ emit?: (e: eventWithTime, isCheckout?: boolean) => void;
474
+ checkoutEveryNth?: number;
475
+ checkoutEveryNms?: number;
476
+ blockClass?: blockClass;
477
+ blockSelector?: string;
478
+ ignoreClass?: string;
479
+ ignoreSelector?: string;
480
+ maskTextClass?: maskTextClass;
481
+ maskTextSelector?: string;
482
+ maskAllInputs?: boolean;
483
+ maskInputOptions?: MaskInputOptions;
484
+ maskInputFn?: MaskInputFn;
485
+ maskTextFn?: MaskTextFn;
486
+ slimDOMOptions?: SlimDOMOptions | 'all' | true;
487
+ ignoreCSSAttributes?: Set<string>;
488
+ inlineStylesheet?: boolean;
489
+ hooks?: hooksParam;
490
+ packFn?: PackFn;
491
+ sampling?: SamplingStrategy;
492
+ dataURLOptions?: DataURLOptions;
493
+ recordDOM?: boolean;
494
+ recordCanvas?: boolean;
495
+ recordCrossOriginIframes?: boolean;
496
+ recordAfter?: 'DOMContentLoaded' | 'load';
497
+ userTriggeredOnInput?: boolean;
498
+ collectFonts?: boolean;
499
+ inlineImages?: boolean;
500
+ plugins?: RecordPlugin[];
501
+ mousemoveWait?: number;
502
+ keepIframeSrcFn?: KeepIframeSrcFn;
503
+ errorHandler?: ErrorHandler;
504
+ };
505
+
3
506
  type Property = any;
4
507
  type Properties = Record<string, Property>;
5
508
  type AutocaptureCompatibleElement = 'a' | 'button' | 'form' | 'input' | 'select' | 'textarea' | 'label';
@@ -102,6 +605,19 @@ interface LeanbaseConfig extends Partial<PostHogCoreOptions> {
102
605
  * @default true
103
606
  */
104
607
  autocapture: boolean | AutocaptureConfig;
608
+ /**
609
+ * Enables or disables session recording. When true, session recording is disabled on the client.
610
+ * @default false
611
+ */
612
+ disable_session_recording?: boolean;
613
+ /**
614
+ * Session recording configuration
615
+ */
616
+ session_recording?: SessionRecordingOptions;
617
+ /**
618
+ * Enable console.log recording for session replay (can be controlled remotely). Undefined defers to server.
619
+ */
620
+ enable_recording_console_log?: boolean;
105
621
  /**
106
622
  * Determines whether Leanbase should capture pageview events automatically.
107
623
  * Can be:
@@ -112,6 +628,12 @@ interface LeanbaseConfig extends Partial<PostHogCoreOptions> {
112
628
  * @default true
113
629
  */
114
630
  capture_pageview: boolean | 'history_change';
631
+ /**
632
+ * Enables performance capture. When true, network performance timing can be forwarded to replay when enabled.
633
+ */
634
+ capture_performance?: boolean | {
635
+ network_timing?: boolean;
636
+ };
115
637
  /**
116
638
  * Determines the session idle timeout in seconds.
117
639
  * Any new event that's happened after this timeout will create a new session.
@@ -336,6 +858,60 @@ interface LeanbaseConfig extends Partial<PostHogCoreOptions> {
336
858
  */
337
859
  loaded: (instance: Leanbase) => void;
338
860
  }
861
+ type SessionRecordingCanvasOptions = {
862
+ recordCanvas?: boolean | null;
863
+ canvasFps?: number | null;
864
+ canvasQuality?: string | null;
865
+ };
866
+ interface SessionRecordingOptions {
867
+ blockClass?: string | RegExp;
868
+ blockSelector?: string | null;
869
+ ignoreClass?: string | RegExp;
870
+ maskTextClass?: string | RegExp;
871
+ maskTextSelector?: string | null;
872
+ maskTextFn?: ((text: string, element?: HTMLElement) => string) | null;
873
+ maskAllInputs?: boolean;
874
+ maskInputOptions?: recordOptions['maskInputOptions'];
875
+ maskInputFn?: ((text: string, element?: HTMLElement) => string) | null;
876
+ slimDOMOptions?: recordOptions['slimDOMOptions'];
877
+ collectFonts?: boolean;
878
+ inlineStylesheet?: boolean;
879
+ recordCrossOriginIframes?: boolean;
880
+ recordHeaders?: boolean;
881
+ recordBody?: boolean;
882
+ captureCanvas?: SessionRecordingCanvasOptions;
883
+ maskCapturedNetworkRequestFn?: ((data: CapturedNetworkRequest) => CapturedNetworkRequest | null | undefined) | null;
884
+ maskNetworkRequestFn?: ((data: NetworkRequest) => NetworkRequest | null | undefined) | null;
885
+ full_snapshot_interval_millis?: number;
886
+ compress_events?: boolean;
887
+ session_idle_threshold_ms?: number;
888
+ __mutationThrottlerRefillRate?: number;
889
+ __mutationThrottlerBucketSize?: number;
890
+ /**
891
+ * Force-enable session recording locally even if remote config disables it.
892
+ * Useful for dev/testing when the backend has sessionRecording set to false.
893
+ */
894
+ forceClientRecording?: boolean;
895
+ }
896
+ type SessionRecordingRemoteConfig = SessionRecordingCanvasOptions & {
897
+ endpoint?: string;
898
+ consoleLogRecordingEnabled?: boolean;
899
+ sampleRate?: string | null;
900
+ minimumDurationMilliseconds?: number;
901
+ linkedFlag?: string | {
902
+ flag: string;
903
+ variant: string;
904
+ } | null;
905
+ networkPayloadCapture?: Pick<NetworkRecordOptions, 'recordBody' | 'recordHeaders' | 'payloadHostDenyList'>;
906
+ masking?: Pick<SessionRecordingOptions, 'maskAllInputs' | 'maskTextSelector' | 'blockSelector'>;
907
+ urlTriggers?: SessionRecordingUrlTrigger[];
908
+ scriptConfig?: {
909
+ script?: string | undefined;
910
+ };
911
+ urlBlocklist?: SessionRecordingUrlTrigger[];
912
+ eventTriggers?: string[];
913
+ triggerMatchType?: 'any' | 'all';
914
+ };
339
915
  interface RageclickConfig {
340
916
  /**
341
917
  * List of CSS selectors to ignore rageclicks on
@@ -454,6 +1030,10 @@ interface RemoteConfig {
454
1030
  autocaptureExceptions?: boolean | {
455
1031
  endpoint?: string;
456
1032
  };
1033
+ /**
1034
+ * Session recording configuration options
1035
+ */
1036
+ sessionRecording?: SessionRecordingRemoteConfig | false;
457
1037
  /**
458
1038
  * @deprecated, moved to toolbarParams
459
1039
  */
@@ -516,6 +1096,50 @@ interface RequestWithOptions {
516
1096
  next?: NextOptions;
517
1097
  };
518
1098
  }
1099
+ type InitiatorType = 'audio' | 'beacon' | 'body' | 'css' | 'early-hint' | 'early-hints' | 'embed' | 'fetch' | 'frame' | 'iframe' | 'image' | 'img' | 'input' | 'link' | 'navigation' | 'object' | 'ping' | 'script' | 'track' | 'video' | 'xmlhttprequest';
1100
+ type NetworkRecordOptions = {
1101
+ initiatorTypes?: InitiatorType[];
1102
+ maskRequestFn?: (data: CapturedNetworkRequest) => CapturedNetworkRequest | undefined;
1103
+ recordHeaders?: boolean | {
1104
+ request: boolean;
1105
+ response: boolean;
1106
+ };
1107
+ recordBody?: boolean | string[] | {
1108
+ request: boolean | string[];
1109
+ response: boolean | string[];
1110
+ };
1111
+ recordInitialRequests?: boolean;
1112
+ recordPerformance?: boolean;
1113
+ performanceEntryTypeToObserve: string[];
1114
+ payloadSizeLimitBytes: number;
1115
+ payloadHostDenyList?: string[];
1116
+ };
1117
+ type NetworkRequest = {
1118
+ url: string;
1119
+ };
1120
+ type Headers = Record<string, any>;
1121
+ type Writable<T> = {
1122
+ -readonly [P in keyof T]: T[P];
1123
+ };
1124
+ type CapturedNetworkRequest = Writable<Omit<PerformanceEntry, 'toJSON'>> & {
1125
+ method?: string;
1126
+ initiatorType?: InitiatorType;
1127
+ status?: number;
1128
+ timeOrigin?: number;
1129
+ timestamp?: number;
1130
+ startTime?: number;
1131
+ endTime?: number;
1132
+ requestHeaders?: Headers;
1133
+ requestBody?: string | null;
1134
+ responseHeaders?: Headers;
1135
+ responseBody?: string | null;
1136
+ isInitial?: boolean;
1137
+ };
1138
+ interface SessionRecordingUrlTrigger {
1139
+ url: string;
1140
+ matching: 'regex';
1141
+ }
1142
+ type SessionStartReason = 'sampling_overridden' | 'recording_initialized' | 'linked_flag_matched' | 'linked_flag_overridden' | 'sampled' | 'session_id_changed' | 'url_trigger_matched' | 'event_trigger_matched';
519
1143
  type SessionIdChangedCallback = (sessionId: string, windowId: string | null | undefined, changeReason?: {
520
1144
  noSessionId: boolean;
521
1145
  activityTimeout: boolean;
@@ -808,6 +1432,88 @@ declare class ConsentManager {
808
1432
  private _getDnt;
809
1433
  }
810
1434
 
1435
+ type TriggerType = 'url' | 'event';
1436
+ /**
1437
+ * Session recording starts in buffering mode while waiting for "flags response".
1438
+ * Once the response is received, it might be disabled, active or sampled.
1439
+ * When "sampled" that means a sample rate is set, and the last time the session ID rotated
1440
+ * the sample rate determined this session should be sent to the server.
1441
+ */
1442
+ declare const sessionRecordingStatuses: readonly ["disabled", "sampled", "active", "buffering", "paused", "lazy_loading"];
1443
+ type SessionRecordingStatus = (typeof sessionRecordingStatuses)[number];
1444
+
1445
+ declare class SessionRecording {
1446
+ private readonly _instance;
1447
+ _forceAllowLocalhostNetworkCapture: boolean;
1448
+ private _receivedFlags;
1449
+ private _bootstrapFailed;
1450
+ private _warnedMissingConsent;
1451
+ private _warnedMissingLoader;
1452
+ private _persistFlagsOnSessionListener;
1453
+ private _lazyLoadedSessionRecording;
1454
+ get started(): boolean;
1455
+ /**
1456
+ * defaults to buffering mode until a flags response is received
1457
+ * once a flags response is received status can be disabled, active or sampled
1458
+ */
1459
+ get status(): SessionRecordingStatus;
1460
+ constructor(_instance: Leanbase);
1461
+ private get _isRecordingEnabled();
1462
+ startIfEnabledOrStop(startReason?: SessionStartReason): void;
1463
+ /**
1464
+ * session recording waits until it receives remote config before loading the script
1465
+ * this is to ensure we can control the script name remotely
1466
+ * and because we wait until we have local and remote config to determine if we should start at all
1467
+ * if start is called and there is no remote config then we wait until there is
1468
+ */
1469
+ private _lazyLoadAndStart;
1470
+ stopRecording(): void;
1471
+ private _resetSampling;
1472
+ private _persistRemoteConfig;
1473
+ private _clearRemoteConfig;
1474
+ onRemoteConfig(response: RemoteConfig): void;
1475
+ log(message: string, level?: 'log' | 'warn' | 'error'): void;
1476
+ private get _scriptName();
1477
+ private _onScriptLoaded;
1478
+ /**
1479
+ * this is maintained on the public API only because it has always been on the public API
1480
+ * if you are calling this directly you are certainly doing something wrong
1481
+ * @deprecated
1482
+ */
1483
+ onRRwebEmit(rawEvent: eventWithTime): void;
1484
+ /**
1485
+ * this ignores the linked flag config and (if other conditions are met) causes capture to start
1486
+ *
1487
+ * It is not usual to call this directly,
1488
+ * instead call `posthog.startSessionRecording({linked_flag: true})`
1489
+ * */
1490
+ overrideLinkedFlag(): void;
1491
+ /**
1492
+ * this ignores the sampling config and (if other conditions are met) causes capture to start
1493
+ *
1494
+ * It is not usual to call this directly,
1495
+ * instead call `posthog.startSessionRecording({sampling: true})`
1496
+ * */
1497
+ overrideSampling(): void;
1498
+ /**
1499
+ * this ignores the URL/Event trigger config and (if other conditions are met) causes capture to start
1500
+ *
1501
+ * It is not usual to call this directly,
1502
+ * instead call `posthog.startSessionRecording({trigger: 'url' | 'event'})`
1503
+ * */
1504
+ overrideTrigger(triggerType: TriggerType): void;
1505
+ get sdkDebugProperties(): Properties;
1506
+ /**
1507
+ * This adds a custom event to the session recording
1508
+ *
1509
+ * It is not intended for arbitrary public use - playback only displays known custom events
1510
+ * And is exposed on the public interface only so that other parts of the SDK are able to use it
1511
+ *
1512
+ * if you are calling this from client code, you're probably looking for `posthog.capture('$custom_event', {...})`
1513
+ */
1514
+ tryAddCustomEvent(tag: string, payload: any): boolean;
1515
+ }
1516
+
811
1517
  declare class Leanbase extends PostHogCore {
812
1518
  config: LeanbaseConfig;
813
1519
  scrollManager: ScrollManager;
@@ -818,6 +1524,7 @@ declare class Leanbase extends PostHogCore {
818
1524
  sessionPersistence?: LeanbasePersistence;
819
1525
  sessionManager?: SessionIdManager;
820
1526
  sessionPropsManager?: SessionPropsManager;
1527
+ sessionRecording?: SessionRecording;
821
1528
  isRemoteConfigLoaded?: boolean;
822
1529
  personProcessingSetOncePropertiesSent: boolean;
823
1530
  isLoaded: boolean;
@@ -835,6 +1542,7 @@ declare class Leanbase extends PostHogCore {
835
1542
  getLibraryVersion(): string;
836
1543
  getCustomUserAgent(): void;
837
1544
  getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
1545
+ getPersistedProperty<T>(key: string): T | undefined;
838
1546
  setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
839
1547
  calculateEventProperties(eventName: string, eventProperties: PostHogEventProperties, timestamp: Date, uuid: string, readOnly?: boolean): Properties;
840
1548
  isIdentified(): boolean;