posthog-js 1.29.0 → 1.29.3

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/dist/module.d.ts CHANGED
@@ -1,8 +1,95 @@
1
- import { MaskInputOptions, SlimDOMOptions } from 'rrweb-snapshot';
2
- import { record } from 'rrweb';
3
- import { listenerHandler, eventWithTime } from 'rrweb/typings/types';
4
1
  import { Integration, EventProcessor, Hub } from '@sentry/types';
5
2
 
3
+ declare enum NodeType {
4
+ Document = 0,
5
+ DocumentType = 1,
6
+ Element = 2,
7
+ Text = 3,
8
+ CDATA = 4,
9
+ Comment = 5
10
+ }
11
+ declare type documentNode = {
12
+ type: NodeType.Document;
13
+ childNodes: serializedNodeWithId[];
14
+ compatMode?: string;
15
+ };
16
+ declare type documentTypeNode = {
17
+ type: NodeType.DocumentType;
18
+ name: string;
19
+ publicId: string;
20
+ systemId: string;
21
+ };
22
+ declare type attributes = {
23
+ [key: string]: string | number | boolean;
24
+ };
25
+ declare type elementNode = {
26
+ type: NodeType.Element;
27
+ tagName: string;
28
+ attributes: attributes;
29
+ childNodes: serializedNodeWithId[];
30
+ isSVG?: true;
31
+ needBlock?: boolean;
32
+ };
33
+ declare type textNode = {
34
+ type: NodeType.Text;
35
+ textContent: string;
36
+ isStyle?: true;
37
+ };
38
+ declare type cdataNode = {
39
+ type: NodeType.CDATA;
40
+ textContent: '';
41
+ };
42
+ declare type commentNode = {
43
+ type: NodeType.Comment;
44
+ textContent: string;
45
+ };
46
+ declare type serializedNode = (documentNode | documentTypeNode | elementNode | textNode | cdataNode | commentNode) & {
47
+ rootId?: number;
48
+ isShadowHost?: boolean;
49
+ isShadow?: boolean;
50
+ };
51
+ declare type serializedNodeWithId = serializedNode & {
52
+ id: number;
53
+ };
54
+ interface INode extends Node {
55
+ __sn: serializedNodeWithId;
56
+ }
57
+ declare type idNodeMap = {
58
+ [key: number]: INode;
59
+ };
60
+ declare type MaskInputOptions = Partial<{
61
+ color: boolean;
62
+ date: boolean;
63
+ 'datetime-local': boolean;
64
+ email: boolean;
65
+ month: boolean;
66
+ number: boolean;
67
+ range: boolean;
68
+ search: boolean;
69
+ tel: boolean;
70
+ text: boolean;
71
+ time: boolean;
72
+ url: boolean;
73
+ week: boolean;
74
+ textarea: boolean;
75
+ select: boolean;
76
+ password: boolean;
77
+ }>;
78
+ declare type SlimDOMOptions = Partial<{
79
+ script: boolean;
80
+ comment: boolean;
81
+ headFavicon: boolean;
82
+ headWhitespace: boolean;
83
+ headMetaDescKeywords: boolean;
84
+ headMetaSocial: boolean;
85
+ headMetaRobots: boolean;
86
+ headMetaHttpEquiv: boolean;
87
+ headMetaAuthorship: boolean;
88
+ headMetaVerification: boolean;
89
+ }>;
90
+ declare type MaskTextFn = (text: string) => string;
91
+ declare type MaskInputFn = (text: string) => string;
92
+
6
93
  declare class CaptureMetrics {
7
94
  enabled: boolean;
8
95
  metrics: Record<string, number>;
@@ -336,6 +423,343 @@ declare class PostHogFeatureFlags {
336
423
  onFeatureFlags(callback: FeatureFlagsCallback): void;
337
424
  }
338
425
 
426
+ declare type PackFn = (event: eventWithTime) => string;
427
+
428
+ declare enum EventType {
429
+ DomContentLoaded = 0,
430
+ Load = 1,
431
+ FullSnapshot = 2,
432
+ IncrementalSnapshot = 3,
433
+ Meta = 4,
434
+ Custom = 5,
435
+ Plugin = 6
436
+ }
437
+ declare type domContentLoadedEvent = {
438
+ type: EventType.DomContentLoaded;
439
+ data: {};
440
+ };
441
+ declare type loadedEvent = {
442
+ type: EventType.Load;
443
+ data: {};
444
+ };
445
+ declare type fullSnapshotEvent = {
446
+ type: EventType.FullSnapshot;
447
+ data: {
448
+ node: serializedNodeWithId;
449
+ initialOffset: {
450
+ top: number;
451
+ left: number;
452
+ };
453
+ };
454
+ };
455
+ declare type incrementalSnapshotEvent = {
456
+ type: EventType.IncrementalSnapshot;
457
+ data: incrementalData;
458
+ };
459
+ declare type metaEvent = {
460
+ type: EventType.Meta;
461
+ data: {
462
+ href: string;
463
+ width: number;
464
+ height: number;
465
+ };
466
+ };
467
+ declare type customEvent<T = unknown> = {
468
+ type: EventType.Custom;
469
+ data: {
470
+ tag: string;
471
+ payload: T;
472
+ };
473
+ };
474
+ declare type pluginEvent<T = unknown> = {
475
+ type: EventType.Plugin;
476
+ data: {
477
+ plugin: string;
478
+ payload: T;
479
+ };
480
+ };
481
+ declare enum IncrementalSource {
482
+ Mutation = 0,
483
+ MouseMove = 1,
484
+ MouseInteraction = 2,
485
+ Scroll = 3,
486
+ ViewportResize = 4,
487
+ Input = 5,
488
+ TouchMove = 6,
489
+ MediaInteraction = 7,
490
+ StyleSheetRule = 8,
491
+ CanvasMutation = 9,
492
+ Font = 10,
493
+ Log = 11,
494
+ Drag = 12,
495
+ StyleDeclaration = 13
496
+ }
497
+ declare type mutationData = {
498
+ source: IncrementalSource.Mutation;
499
+ } & mutationCallbackParam;
500
+ declare type mousemoveData = {
501
+ source: IncrementalSource.MouseMove | IncrementalSource.TouchMove | IncrementalSource.Drag;
502
+ positions: mousePosition[];
503
+ };
504
+ declare type mouseInteractionData = {
505
+ source: IncrementalSource.MouseInteraction;
506
+ } & mouseInteractionParam;
507
+ declare type scrollData = {
508
+ source: IncrementalSource.Scroll;
509
+ } & scrollPosition;
510
+ declare type viewportResizeData = {
511
+ source: IncrementalSource.ViewportResize;
512
+ } & viewportResizeDimension;
513
+ declare type inputData = {
514
+ source: IncrementalSource.Input;
515
+ id: number;
516
+ } & inputValue;
517
+ declare type mediaInteractionData = {
518
+ source: IncrementalSource.MediaInteraction;
519
+ } & mediaInteractionParam;
520
+ declare type styleSheetRuleData = {
521
+ source: IncrementalSource.StyleSheetRule;
522
+ } & styleSheetRuleParam;
523
+ declare type styleDeclarationData = {
524
+ source: IncrementalSource.StyleDeclaration;
525
+ } & styleDeclarationParam;
526
+ declare type canvasMutationData = {
527
+ source: IncrementalSource.CanvasMutation;
528
+ } & canvasMutationParam;
529
+ declare type fontData = {
530
+ source: IncrementalSource.Font;
531
+ } & fontParam;
532
+ declare type incrementalData = mutationData | mousemoveData | mouseInteractionData | scrollData | viewportResizeData | inputData | mediaInteractionData | styleSheetRuleData | canvasMutationData | fontData | styleDeclarationData;
533
+ declare type event = domContentLoadedEvent | loadedEvent | fullSnapshotEvent | incrementalSnapshotEvent | metaEvent | customEvent | pluginEvent;
534
+ declare type eventWithTime = event & {
535
+ timestamp: number;
536
+ delay?: number;
537
+ };
538
+ declare type blockClass = string | RegExp;
539
+ declare type maskTextClass = string | RegExp;
540
+ declare type SamplingStrategy = Partial<{
541
+ mousemove: boolean | number;
542
+ mousemoveCallback: number;
543
+ mouseInteraction: boolean | Record<string, boolean | undefined>;
544
+ scroll: number;
545
+ media: number;
546
+ input: 'all' | 'last';
547
+ }>;
548
+ declare type RecordPlugin<TOptions = unknown> = {
549
+ name: string;
550
+ observer?: (cb: Function, win: IWindow, options: TOptions) => listenerHandler;
551
+ eventProcessor?: <TExtend>(event: eventWithTime) => eventWithTime & TExtend;
552
+ options: TOptions;
553
+ };
554
+ declare type recordOptions<T> = {
555
+ emit?: (e: T, isCheckout?: boolean) => void;
556
+ checkoutEveryNth?: number;
557
+ checkoutEveryNms?: number;
558
+ blockClass?: blockClass;
559
+ blockSelector?: string;
560
+ ignoreClass?: string;
561
+ maskTextClass?: maskTextClass;
562
+ maskTextSelector?: string;
563
+ maskAllInputs?: boolean;
564
+ maskInputOptions?: MaskInputOptions;
565
+ maskInputFn?: MaskInputFn;
566
+ maskTextFn?: MaskTextFn;
567
+ slimDOMOptions?: SlimDOMOptions | 'all' | true;
568
+ inlineStylesheet?: boolean;
569
+ hooks?: hooksParam;
570
+ packFn?: PackFn;
571
+ sampling?: SamplingStrategy;
572
+ recordCanvas?: boolean;
573
+ userTriggeredOnInput?: boolean;
574
+ collectFonts?: boolean;
575
+ inlineImages?: boolean;
576
+ plugins?: RecordPlugin[];
577
+ mousemoveWait?: number;
578
+ keepIframeSrcFn?: KeepIframeSrcFn;
579
+ };
580
+ declare type hooksParam = {
581
+ mutation?: mutationCallBack;
582
+ mousemove?: mousemoveCallBack;
583
+ mouseInteraction?: mouseInteractionCallBack;
584
+ scroll?: scrollCallback;
585
+ viewportResize?: viewportResizeCallback;
586
+ input?: inputCallback;
587
+ mediaInteaction?: mediaInteractionCallback;
588
+ styleSheetRule?: styleSheetRuleCallback;
589
+ styleDeclaration?: styleDeclarationCallback;
590
+ canvasMutation?: canvasMutationCallback;
591
+ font?: fontCallback;
592
+ };
593
+ declare type textMutation = {
594
+ id: number;
595
+ value: string | null;
596
+ };
597
+ declare type styleAttributeValue = {
598
+ [key: string]: styleValueWithPriority | string | false;
599
+ };
600
+ declare type styleValueWithPriority = [string, string];
601
+ declare type attributeMutation = {
602
+ id: number;
603
+ attributes: {
604
+ [key: string]: string | styleAttributeValue | null;
605
+ };
606
+ };
607
+ declare type removedNodeMutation = {
608
+ parentId: number;
609
+ id: number;
610
+ isShadow?: boolean;
611
+ };
612
+ declare type addedNodeMutation = {
613
+ parentId: number;
614
+ previousId?: number | null;
615
+ nextId: number | null;
616
+ node: serializedNodeWithId;
617
+ };
618
+ declare type mutationCallbackParam = {
619
+ texts: textMutation[];
620
+ attributes: attributeMutation[];
621
+ removes: removedNodeMutation[];
622
+ adds: addedNodeMutation[];
623
+ isAttachIframe?: true;
624
+ };
625
+ declare type mutationCallBack = (m: mutationCallbackParam) => void;
626
+ declare type mousemoveCallBack = (p: mousePosition[], source: IncrementalSource.MouseMove | IncrementalSource.TouchMove | IncrementalSource.Drag) => void;
627
+ declare type mousePosition = {
628
+ x: number;
629
+ y: number;
630
+ id: number;
631
+ timeOffset: number;
632
+ };
633
+ declare enum MouseInteractions {
634
+ MouseUp = 0,
635
+ MouseDown = 1,
636
+ Click = 2,
637
+ ContextMenu = 3,
638
+ DblClick = 4,
639
+ Focus = 5,
640
+ Blur = 6,
641
+ TouchStart = 7,
642
+ TouchMove_Departed = 8,
643
+ TouchEnd = 9,
644
+ TouchCancel = 10
645
+ }
646
+ declare enum CanvasContext {
647
+ '2D' = 0,
648
+ WebGL = 1,
649
+ WebGL2 = 2
650
+ }
651
+ declare type mouseInteractionParam = {
652
+ type: MouseInteractions;
653
+ id: number;
654
+ x: number;
655
+ y: number;
656
+ };
657
+ declare type mouseInteractionCallBack = (d: mouseInteractionParam) => void;
658
+ declare type scrollPosition = {
659
+ id: number;
660
+ x: number;
661
+ y: number;
662
+ };
663
+ declare type scrollCallback = (p: scrollPosition) => void;
664
+ declare type styleSheetAddRule = {
665
+ rule: string;
666
+ index?: number | number[];
667
+ };
668
+ declare type styleSheetDeleteRule = {
669
+ index: number | number[];
670
+ };
671
+ declare type styleSheetRuleParam = {
672
+ id: number;
673
+ removes?: styleSheetDeleteRule[];
674
+ adds?: styleSheetAddRule[];
675
+ };
676
+ declare type styleSheetRuleCallback = (s: styleSheetRuleParam) => void;
677
+ declare type styleDeclarationParam = {
678
+ id: number;
679
+ index: number[];
680
+ set?: {
681
+ property: string;
682
+ value: string | null;
683
+ priority: string | undefined;
684
+ };
685
+ remove?: {
686
+ property: string;
687
+ };
688
+ };
689
+ declare type styleDeclarationCallback = (s: styleDeclarationParam) => void;
690
+ declare type canvasMutationCommand = {
691
+ property: string;
692
+ args: Array<unknown>;
693
+ setter?: true;
694
+ };
695
+ declare type canvasMutationParam = {
696
+ id: number;
697
+ type: CanvasContext;
698
+ commands: canvasMutationCommand[];
699
+ } | ({
700
+ id: number;
701
+ type: CanvasContext;
702
+ } & canvasMutationCommand);
703
+ declare type canvasMutationCallback = (p: canvasMutationParam) => void;
704
+ declare type fontParam = {
705
+ family: string;
706
+ fontSource: string;
707
+ buffer: boolean;
708
+ descriptors?: FontFaceDescriptors;
709
+ };
710
+ declare type fontCallback = (p: fontParam) => void;
711
+ declare type viewportResizeDimension = {
712
+ width: number;
713
+ height: number;
714
+ };
715
+ declare type viewportResizeCallback = (d: viewportResizeDimension) => void;
716
+ declare type inputValue = {
717
+ text: string;
718
+ isChecked: boolean;
719
+ userTriggered?: boolean;
720
+ };
721
+ declare type inputCallback = (v: inputValue & {
722
+ id: number;
723
+ }) => void;
724
+ declare const enum MediaInteractions {
725
+ Play = 0,
726
+ Pause = 1,
727
+ Seeked = 2,
728
+ VolumeChange = 3
729
+ }
730
+ declare type mediaInteractionParam = {
731
+ type: MediaInteractions;
732
+ id: number;
733
+ currentTime?: number;
734
+ volume?: number;
735
+ muted?: boolean;
736
+ };
737
+ declare type mediaInteractionCallback = (p: mediaInteractionParam) => void;
738
+ declare type Mirror = {
739
+ map: idNodeMap;
740
+ getId: (n: INode) => number;
741
+ getNode: (id: number) => INode | null;
742
+ removeNodeFromMap: (n: INode) => void;
743
+ has: (id: number) => boolean;
744
+ reset: () => void;
745
+ };
746
+ declare type listenerHandler = () => void;
747
+ declare type KeepIframeSrcFn = (src: string) => boolean;
748
+ declare global {
749
+ interface Window {
750
+ FontFace: typeof FontFace;
751
+ }
752
+ }
753
+ declare type IWindow = Window & typeof globalThis;
754
+
755
+ declare function record<T = eventWithTime>(options?: recordOptions<T>): listenerHandler | undefined;
756
+ declare namespace record {
757
+ var addCustomEvent: <T>(tag: string, payload: T) => void;
758
+ var freezePage: () => void;
759
+ var takeFullSnapshot: (isCheckout?: boolean | undefined) => void;
760
+ var mirror: Mirror;
761
+ }
762
+
339
763
  declare class SessionRecording {
340
764
  instance: PostHog;
341
765
  captureStarted: boolean;
package/dist/module.js CHANGED
@@ -885,7 +885,7 @@ var LZString = {
885
885
  }
886
886
  };
887
887
 
888
- var version = "1.29.0";
888
+ var version = "1.29.3";
889
889
 
890
890
  // e.g. Config.DEBUG = Config.DEBUG || instance.get_config('debug')
891
891
 
@@ -4130,7 +4130,9 @@ var Toolbar = /*#__PURE__*/function () {
4130
4130
  delete editorParams.userIntent;
4131
4131
  }
4132
4132
 
4133
- editorParams['apiURL'] = this.instance.get_config('api_host');
4133
+ if (!editorParams.apiURL) {
4134
+ editorParams.apiURL = this.instance.get_config('api_host');
4135
+ }
4134
4136
 
4135
4137
  if (editorParams['token'] && this.instance.get_config('token') === editorParams['token']) {
4136
4138
  this._loadEditor(editorParams);
@@ -4343,19 +4345,27 @@ var RequestQueue = /*#__PURE__*/function (_RequestQueueScaffold) {
4343
4345
  }, {
4344
4346
  key: "unload",
4345
4347
  value: function unload() {
4348
+ var _this3 = this;
4349
+
4346
4350
  clearTimeout(this._poller);
4347
4351
  var requests = this._event_queue.length > 0 ? this.formatQueue() : {};
4348
4352
  this._event_queue.length = 0;
4349
-
4350
- for (var key in requests) {
4351
- var _requests$key3 = requests[key],
4352
- _url2 = _requests$key3.url,
4353
- _data2 = _requests$key3.data,
4354
- _options = _requests$key3.options;
4355
- this.handlePollRequest(_url2, _data2, _objectSpread2(_objectSpread2({}, _options), {}, {
4353
+ var requestValues = Object.values(requests); // Always force events to be sent before recordings, as events are more important, and recordings are bigger and thus less likely to arrive
4354
+
4355
+ var sortedRequests = [].concat(_toConsumableArray(requestValues.filter(function (r) {
4356
+ return r.url.indexOf('/e') === 0;
4357
+ })), _toConsumableArray(requestValues.filter(function (r) {
4358
+ return r.url.indexOf('/e') !== 0;
4359
+ })));
4360
+ sortedRequests.map(function (_ref) {
4361
+ var url = _ref.url,
4362
+ data = _ref.data,
4363
+ options = _ref.options;
4364
+
4365
+ _this3.handlePollRequest(url, data, _objectSpread2(_objectSpread2({}, options), {}, {
4356
4366
  transport: 'sendBeacon'
4357
4367
  }));
4358
- }
4368
+ });
4359
4369
  }
4360
4370
  }, {
4361
4371
  key: "formatQueue",
@@ -6130,10 +6140,11 @@ var PostHog = /*#__PURE__*/function () {
6130
6140
  distinct_id: uuid,
6131
6141
  $device_id: uuid
6132
6142
  }, '');
6133
- } // Set up the window close event handler "unload"
6143
+ } // Set up event handler for pageleave
6144
+ // Use `onpagehide` if available, see https://calendar.perfplanet.com/2020/beaconing-in-practice/#beaconing-reliability-avoiding-abandons
6134
6145
 
6135
6146
 
6136
- win.addEventListener && win.addEventListener('unload', this._handle_unload.bind(this));
6147
+ win.addEventListener && win.addEventListener('onpagehide' in self ? 'pagehide' : 'unload', this._handle_unload.bind(this));
6137
6148
  } // Private methods
6138
6149
 
6139
6150
  }, {