@openreplay/tracker 3.5.10 → 3.5.13-beta.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 (100) hide show
  1. package/README.md +5 -1
  2. package/cjs/app/guards.d.ts +17 -0
  3. package/cjs/app/guards.js +24 -0
  4. package/cjs/app/index.d.ts +19 -5
  5. package/cjs/app/index.js +37 -30
  6. package/cjs/app/nodes.d.ts +1 -1
  7. package/cjs/app/observer/iframe_observer.js +2 -2
  8. package/cjs/app/observer/observer.d.ts +2 -2
  9. package/cjs/app/observer/observer.js +50 -58
  10. package/cjs/app/observer/shadow_root_observer.js +2 -2
  11. package/cjs/app/observer/top_observer.js +5 -5
  12. package/cjs/app/sanitizer.js +2 -2
  13. package/cjs/app/session.js +3 -3
  14. package/{lib/messages/index.d.ts → cjs/common/messages.d.ts} +2 -3
  15. package/cjs/{messages/index.js → common/messages.js} +0 -0
  16. package/cjs/common/types.d.ts +9 -0
  17. package/cjs/{messages/message.js → common/types.js} +0 -0
  18. package/cjs/common/webworker.d.ts +19 -0
  19. package/cjs/common/webworker.js +2 -0
  20. package/cjs/index.d.ts +3 -3
  21. package/cjs/index.js +6 -6
  22. package/cjs/modules/connection.js +2 -2
  23. package/cjs/modules/console.d.ts +1 -1
  24. package/cjs/modules/console.js +4 -3
  25. package/cjs/modules/cssrules.d.ts +1 -1
  26. package/cjs/modules/cssrules.js +6 -8
  27. package/cjs/modules/exception.d.ts +2 -2
  28. package/cjs/modules/exception.js +4 -4
  29. package/cjs/modules/img.d.ts +1 -1
  30. package/cjs/modules/img.js +9 -8
  31. package/cjs/modules/input.d.ts +1 -1
  32. package/cjs/modules/input.js +18 -17
  33. package/cjs/modules/longtasks.d.ts +1 -1
  34. package/cjs/modules/longtasks.js +2 -2
  35. package/cjs/modules/mouse.d.ts +1 -1
  36. package/cjs/modules/mouse.js +6 -5
  37. package/cjs/modules/performance.d.ts +1 -1
  38. package/cjs/modules/performance.js +2 -2
  39. package/cjs/modules/scroll.d.ts +1 -1
  40. package/cjs/modules/scroll.js +8 -8
  41. package/cjs/modules/timing.d.ts +1 -1
  42. package/cjs/modules/timing.js +6 -5
  43. package/cjs/modules/viewport.d.ts +1 -1
  44. package/cjs/modules/viewport.js +4 -4
  45. package/lib/app/guards.d.ts +17 -0
  46. package/lib/app/guards.js +16 -0
  47. package/lib/app/index.d.ts +19 -5
  48. package/lib/app/index.js +33 -26
  49. package/lib/app/nodes.d.ts +1 -1
  50. package/lib/app/observer/iframe_observer.js +1 -1
  51. package/lib/app/observer/observer.d.ts +2 -2
  52. package/lib/app/observer/observer.js +35 -43
  53. package/lib/app/observer/shadow_root_observer.js +1 -1
  54. package/lib/app/observer/top_observer.js +4 -4
  55. package/lib/app/sanitizer.js +2 -2
  56. package/lib/app/session.js +1 -1
  57. package/{cjs/messages/index.d.ts → lib/common/messages.d.ts} +2 -3
  58. package/lib/{messages/index.js → common/messages.js} +0 -0
  59. package/lib/common/tsconfig.tsbuildinfo +1 -0
  60. package/lib/common/types.d.ts +9 -0
  61. package/lib/{messages/message.js → common/types.js} +0 -0
  62. package/lib/common/webworker.d.ts +19 -0
  63. package/lib/common/webworker.js +1 -0
  64. package/lib/index.d.ts +3 -3
  65. package/lib/index.js +3 -3
  66. package/lib/modules/connection.js +1 -1
  67. package/lib/modules/console.d.ts +1 -1
  68. package/lib/modules/console.js +3 -2
  69. package/lib/modules/cssrules.d.ts +1 -1
  70. package/lib/modules/cssrules.js +3 -5
  71. package/lib/modules/exception.d.ts +2 -2
  72. package/lib/modules/exception.js +1 -1
  73. package/lib/modules/img.d.ts +1 -1
  74. package/lib/modules/img.js +3 -2
  75. package/lib/modules/input.d.ts +1 -1
  76. package/lib/modules/input.js +14 -13
  77. package/lib/modules/longtasks.d.ts +1 -1
  78. package/lib/modules/longtasks.js +1 -1
  79. package/lib/modules/mouse.d.ts +1 -1
  80. package/lib/modules/mouse.js +4 -3
  81. package/lib/modules/performance.d.ts +1 -1
  82. package/lib/modules/performance.js +1 -1
  83. package/lib/modules/scroll.d.ts +1 -1
  84. package/lib/modules/scroll.js +6 -6
  85. package/lib/modules/timing.d.ts +1 -1
  86. package/lib/modules/timing.js +3 -2
  87. package/lib/modules/viewport.d.ts +1 -1
  88. package/lib/modules/viewport.js +1 -1
  89. package/package.json +1 -1
  90. package/cjs/app/context.d.ts +0 -18
  91. package/cjs/app/context.js +0 -73
  92. package/cjs/messages/message.d.ts +0 -4
  93. package/cjs/messages/writer.d.ts +0 -15
  94. package/cjs/messages/writer.js +0 -115
  95. package/lib/app/context.d.ts +0 -18
  96. package/lib/app/context.js +0 -68
  97. package/lib/messages/message.d.ts +0 -4
  98. package/lib/messages/tsconfig.tsbuildinfo +0 -1
  99. package/lib/messages/writer.d.ts +0 -15
  100. package/lib/messages/writer.js +0 -112
package/README.md CHANGED
@@ -25,7 +25,11 @@ tracker.start({
25
25
  balance: "10M",
26
26
  role: "admin",
27
27
  }
28
- });
28
+ }).then(startedSession => {
29
+ if (startedSession.success) {
30
+ console.log(startedSession)
31
+ }
32
+ })
29
33
  ```
30
34
 
31
35
  Then you can use OpenReplay JavaScript API anywhere in your code.
@@ -0,0 +1,17 @@
1
+ export declare function isSVGElement(node: Element): node is SVGElement;
2
+ export declare function isElementNode(node: Node): node is Element;
3
+ export declare function isTextNode(node: Node): node is Text;
4
+ export declare function isRootNode(node: Node): boolean;
5
+ declare type TagTypeMap = {
6
+ HTML: HTMLHtmlElement;
7
+ IMG: HTMLImageElement;
8
+ INPUT: HTMLInputElement;
9
+ TEXTAREA: HTMLTextAreaElement;
10
+ SELECT: HTMLSelectElement;
11
+ LABEL: HTMLLabelElement;
12
+ IFRAME: HTMLIFrameElement;
13
+ STYLE: HTMLStyleElement | SVGStyleElement;
14
+ LINK: HTMLLinkElement;
15
+ };
16
+ export declare function hasTag<T extends keyof TagTypeMap>(el: Node, tagName: T): el is TagTypeMap[typeof tagName];
17
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasTag = exports.isRootNode = exports.isTextNode = exports.isElementNode = exports.isSVGElement = void 0;
4
+ function isSVGElement(node) {
5
+ return node.namespaceURI === 'http://www.w3.org/2000/svg';
6
+ }
7
+ exports.isSVGElement = isSVGElement;
8
+ function isElementNode(node) {
9
+ return node.nodeType === Node.ELEMENT_NODE;
10
+ }
11
+ exports.isElementNode = isElementNode;
12
+ function isTextNode(node) {
13
+ return node.nodeType === Node.TEXT_NODE;
14
+ }
15
+ exports.isTextNode = isTextNode;
16
+ function isRootNode(node) {
17
+ return node.nodeType === Node.DOCUMENT_NODE ||
18
+ node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
19
+ }
20
+ exports.isRootNode = isRootNode;
21
+ function hasTag(el, tagName) {
22
+ return el.nodeName.toUpperCase() === tagName;
23
+ }
24
+ exports.hasTag = hasTag;
@@ -1,4 +1,4 @@
1
- import Message from "../messages/message.js";
1
+ import type Message from "../common/messages.js";
2
2
  import Nodes from "./nodes.js";
3
3
  import Sanitizer from "./sanitizer.js";
4
4
  import Ticker from "./ticker.js";
@@ -7,17 +7,28 @@ import Session from "./session.js";
7
7
  import type { Options as ObserverOptions } from "./observer/top_observer.js";
8
8
  import type { Options as SanitizerOptions } from "./sanitizer.js";
9
9
  import type { Options as LoggerOptions } from "./logger.js";
10
- import type { Options as WebworkerOptions } from "../../webworker/types.js";
10
+ import type { Options as WebworkerOptions } from "../common/webworker.js";
11
11
  export interface StartOptions {
12
12
  userID?: string;
13
13
  metadata?: Record<string, string>;
14
14
  forceNew?: boolean;
15
15
  }
16
- export interface OnStartInfo {
16
+ interface OnStartInfo {
17
17
  sessionID: string;
18
18
  sessionToken: string;
19
19
  userUUID: string;
20
20
  }
21
+ declare const CANCELED: "canceled";
22
+ declare type SuccessfulStart = OnStartInfo & {
23
+ success: true;
24
+ };
25
+ declare type UnsuccessfulStart = {
26
+ reason: typeof CANCELED | string;
27
+ success: false;
28
+ };
29
+ declare const UnsuccessfulStart: (reason: string) => UnsuccessfulStart;
30
+ declare const SuccessfulStart: (body: OnStartInfo) => SuccessfulStart;
31
+ export declare type StartPromiseReturn = SuccessfulStart | UnsuccessfulStart;
21
32
  declare type StartCallback = (i: OnStartInfo) => void;
22
33
  declare type CommitCallback = (messages: Array<Message>) => void;
23
34
  declare type AppOptions = {
@@ -33,10 +44,11 @@ declare type AppOptions = {
33
44
  __is_snippet: boolean;
34
45
  __debug_report_edp: string | null;
35
46
  __debug__?: LoggerOptions;
47
+ localStorage: Storage;
48
+ sessionStorage: Storage;
36
49
  onStart?: StartCallback;
37
50
  } & WebworkerOptions;
38
51
  export declare type Options = AppOptions & ObserverOptions & SanitizerOptions;
39
- export declare const CANCELED = "canceled";
40
52
  export declare const DEFAULT_INGEST_POINT = "https://api.openreplay.com/ingest";
41
53
  export default class App {
42
54
  readonly nodes: Nodes;
@@ -46,6 +58,8 @@ export default class App {
46
58
  readonly debug: Logger;
47
59
  readonly notify: Logger;
48
60
  readonly session: Session;
61
+ readonly localStorage: Storage;
62
+ readonly sessionStorage: Storage;
49
63
  private readonly messages;
50
64
  private readonly observer;
51
65
  private readonly startCallbacks;
@@ -88,7 +102,7 @@ export default class App {
88
102
  active(): boolean;
89
103
  resetNextPageSession(flag: boolean): void;
90
104
  private _start;
91
- start(options?: StartOptions): Promise<OnStartInfo>;
105
+ start(options?: StartOptions): Promise<StartPromiseReturn>;
92
106
  stop(): void;
93
107
  }
94
108
  export {};
package/cjs/app/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_INGEST_POINT = exports.CANCELED = void 0;
3
+ exports.DEFAULT_INGEST_POINT = void 0;
4
+ const messages_js_1 = require("../common/messages.js");
4
5
  const utils_js_1 = require("../utils.js");
5
- const index_js_1 = require("../messages/index.js");
6
6
  const nodes_js_1 = require("./nodes.js");
7
7
  const top_observer_js_1 = require("./observer/top_observer.js");
8
8
  const sanitizer_js_1 = require("./sanitizer.js");
@@ -10,13 +10,16 @@ const ticker_js_1 = require("./ticker.js");
10
10
  const logger_js_1 = require("./logger.js");
11
11
  const session_js_1 = require("./session.js");
12
12
  const performance_js_1 = require("../modules/performance.js");
13
+ const CANCELED = "canceled";
14
+ const START_ERROR = ":(";
15
+ const UnsuccessfulStart = (reason) => ({ reason, success: false });
16
+ const SuccessfulStart = (body) => (Object.assign(Object.assign({}, body), { success: true }));
13
17
  var ActivityState;
14
18
  (function (ActivityState) {
15
19
  ActivityState[ActivityState["NotActive"] = 0] = "NotActive";
16
20
  ActivityState[ActivityState["Starting"] = 1] = "Starting";
17
21
  ActivityState[ActivityState["Active"] = 2] = "Active";
18
22
  })(ActivityState || (ActivityState = {}));
19
- exports.CANCELED = "canceled";
20
23
  // TODO: use backendHost only
21
24
  exports.DEFAULT_INGEST_POINT = 'https://api.openreplay.com/ingest';
22
25
  class App {
@@ -29,7 +32,7 @@ class App {
29
32
  this.stopCallbacks = [];
30
33
  this.commitCallbacks = [];
31
34
  this.activityState = ActivityState.NotActive;
32
- this.version = '3.5.10'; // TODO: version compatability check inside each plugin.
35
+ this.version = '3.5.13-beta.0'; // TODO: version compatability check inside each plugin.
33
36
  this.projectKey = projectKey;
34
37
  this.options = Object.assign({
35
38
  revID: '',
@@ -43,10 +46,9 @@ class App {
43
46
  verbose: false,
44
47
  __is_snippet: false,
45
48
  __debug_report_edp: null,
49
+ localStorage: window.localStorage,
50
+ sessionStorage: window.sessionStorage,
46
51
  }, options);
47
- if (sessionToken != null) {
48
- sessionStorage.setItem(this.options.session_token_key, sessionToken);
49
- }
50
52
  this.revID = this.options.revID;
51
53
  this.sanitizer = new sanitizer_js_1.default(this, options);
52
54
  this.nodes = new nodes_js_1.default(this.options.node_id);
@@ -56,6 +58,11 @@ class App {
56
58
  this.debug = new logger_js_1.default(this.options.__debug__);
57
59
  this.notify = new logger_js_1.default(this.options.verbose ? logger_js_1.LogLevel.Warnings : logger_js_1.LogLevel.Silent);
58
60
  this.session = new session_js_1.default(this);
61
+ this.localStorage = this.options.localStorage;
62
+ this.sessionStorage = this.options.sessionStorage;
63
+ if (sessionToken != null) {
64
+ this.sessionStorage.setItem(this.options.session_token_key, sessionToken);
65
+ }
59
66
  try {
60
67
  this.worker = new Worker(URL.createObjectURL(new Blob([`"use strict";function t(t){function i(...i){return new t(...i)}return i.prototype=t.prototype,i}const i=new Map;const s=t(class{constructor(t,i,s){this.pageNo=t,this.firstIndex=i,this.timestamp=s,this._id=80}encode(t){return t.uint(80)&&t.uint(this.pageNo)&&t.uint(this.firstIndex)&&t.int(this.timestamp)}});i.set(80,s);const e=t(class{constructor(t){this.timestamp=t,this._id=0}encode(t){return t.uint(0)&&t.uint(this.timestamp)}});i.set(0,e);const n=t(class{constructor(t,i,s){this.url=t,this.referrer=i,this.navigationStart=s,this._id=4}encode(t){return t.uint(4)&&t.string(this.url)&&t.string(this.referrer)&&t.uint(this.navigationStart)}});i.set(4,n);const r=t(class{constructor(t,i){this.width=t,this.height=i,this._id=5}encode(t){return t.uint(5)&&t.uint(this.width)&&t.uint(this.height)}});i.set(5,r);const h=t(class{constructor(t,i){this.x=t,this.y=i,this._id=6}encode(t){return t.uint(6)&&t.int(this.x)&&t.int(this.y)}});i.set(6,h);const o=t(class{constructor(){this._id=7}encode(t){return t.uint(7)}});i.set(7,o);const c=t(class{constructor(t,i,s,e,n){this.id=t,this.parentID=i,this.index=s,this.tag=e,this.svg=n,this._id=8}encode(t){return t.uint(8)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)&&t.string(this.tag)&&t.boolean(this.svg)}});i.set(8,c);const a=t(class{constructor(t,i,s){this.id=t,this.parentID=i,this.index=s,this._id=9}encode(t){return t.uint(9)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});i.set(9,a);const u=t(class{constructor(t,i,s){this.id=t,this.parentID=i,this.index=s,this._id=10}encode(t){return t.uint(10)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});i.set(10,u);const d=t(class{constructor(t){this.id=t,this._id=11}encode(t){return t.uint(11)&&t.uint(this.id)}});i.set(11,d);const l=t(class{constructor(t,i,s){this.id=t,this.name=i,this.value=s,this._id=12}encode(t){return t.uint(12)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)}});i.set(12,l);const p=t(class{constructor(t,i){this.id=t,this.name=i,this._id=13}encode(t){return t.uint(13)&&t.uint(this.id)&&t.string(this.name)}});i.set(13,p);const m=t(class{constructor(t,i){this.id=t,this.data=i,this._id=14}encode(t){return t.uint(14)&&t.uint(this.id)&&t.string(this.data)}});i.set(14,m);const g=t(class{constructor(t,i,s){this.id=t,this.x=i,this.y=s,this._id=16}encode(t){return t.uint(16)&&t.uint(this.id)&&t.int(this.x)&&t.int(this.y)}});i.set(16,g);const f=t(class{constructor(t,i){this.id=t,this.label=i,this._id=17}encode(t){return t.uint(17)&&t.uint(this.id)&&t.string(this.label)}});i.set(17,f);const y=t(class{constructor(t,i,s){this.id=t,this.value=i,this.mask=s,this._id=18}encode(t){return t.uint(18)&&t.uint(this.id)&&t.string(this.value)&&t.int(this.mask)}});i.set(18,y);const _=t(class{constructor(t,i){this.id=t,this.checked=i,this._id=19}encode(t){return t.uint(19)&&t.uint(this.id)&&t.boolean(this.checked)}});i.set(19,_);const v=t(class{constructor(t,i){this.x=t,this.y=i,this._id=20}encode(t){return t.uint(20)&&t.uint(this.x)&&t.uint(this.y)}});i.set(20,v);const b=t(class{constructor(t,i){this.level=t,this.value=i,this._id=22}encode(t){return t.uint(22)&&t.string(this.level)&&t.string(this.value)}});i.set(22,b);const S=t(class{constructor(t,i,s,e,n,r,h,o,c){this.requestStart=t,this.responseStart=i,this.responseEnd=s,this.domContentLoadedEventStart=e,this.domContentLoadedEventEnd=n,this.loadEventStart=r,this.loadEventEnd=h,this.firstPaint=o,this.firstContentfulPaint=c,this._id=23}encode(t){return t.uint(23)&&t.uint(this.requestStart)&&t.uint(this.responseStart)&&t.uint(this.responseEnd)&&t.uint(this.domContentLoadedEventStart)&&t.uint(this.domContentLoadedEventEnd)&&t.uint(this.loadEventStart)&&t.uint(this.loadEventEnd)&&t.uint(this.firstPaint)&&t.uint(this.firstContentfulPaint)}});i.set(23,S);const w=t(class{constructor(t,i,s){this.speedIndex=t,this.visuallyComplete=i,this.timeToInteractive=s,this._id=24}encode(t){return t.uint(24)&&t.uint(this.speedIndex)&&t.uint(this.visuallyComplete)&&t.uint(this.timeToInteractive)}});i.set(24,w);const E=t(class{constructor(t,i,s){this.name=t,this.message=i,this.payload=s,this._id=25}encode(t){return t.uint(25)&&t.string(this.name)&&t.string(this.message)&&t.string(this.payload)}});i.set(25,E);const x=t(class{constructor(t,i){this.name=t,this.payload=i,this._id=27}encode(t){return t.uint(27)&&t.string(this.name)&&t.string(this.payload)}});i.set(27,x);const T=t(class{constructor(t){this.id=t,this._id=28}encode(t){return t.uint(28)&&t.string(this.id)}});i.set(28,T);const z=t(class{constructor(t){this.id=t,this._id=29}encode(t){return t.uint(29)&&t.string(this.id)}});i.set(29,z);const k=t(class{constructor(t,i){this.key=t,this.value=i,this._id=30}encode(t){return t.uint(30)&&t.string(this.key)&&t.string(this.value)}});i.set(30,k);const I=t(class{constructor(t,i,s){this.id=t,this.rule=i,this.index=s,this._id=37}encode(t){return t.uint(37)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)}});i.set(37,I);const M=t(class{constructor(t,i){this.id=t,this.index=i,this._id=38}encode(t){return t.uint(38)&&t.uint(this.id)&&t.uint(this.index)}});i.set(38,M);const B=t(class{constructor(t,i,s,e,n,r,h){this.method=t,this.url=i,this.request=s,this.response=e,this.status=n,this.timestamp=r,this.duration=h,this._id=39}encode(t){return t.uint(39)&&t.string(this.method)&&t.string(this.url)&&t.string(this.request)&&t.string(this.response)&&t.uint(this.status)&&t.uint(this.timestamp)&&t.uint(this.duration)}});i.set(39,B);const L=t(class{constructor(t,i,s,e){this.name=t,this.duration=i,this.args=s,this.result=e,this._id=40}encode(t){return t.uint(40)&&t.string(this.name)&&t.uint(this.duration)&&t.string(this.args)&&t.string(this.result)}});i.set(40,L);const C=t(class{constructor(t,i){this.key=t,this.value=i,this._id=41}encode(t){return t.uint(41)&&t.string(this.key)&&t.string(this.value)}});i.set(41,C);const A=t(class{constructor(t){this.type=t,this._id=42}encode(t){return t.uint(42)&&t.string(this.type)}});i.set(42,A);const U=t(class{constructor(t,i,s){this.action=t,this.state=i,this.duration=s,this._id=44}encode(t){return t.uint(44)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});i.set(44,U);const N=t(class{constructor(t,i){this.mutation=t,this.state=i,this._id=45}encode(t){return t.uint(45)&&t.string(this.mutation)&&t.string(this.state)}});i.set(45,N);const R=t(class{constructor(t,i){this.type=t,this.payload=i,this._id=46}encode(t){return t.uint(46)&&t.string(this.type)&&t.string(this.payload)}});i.set(46,R);const O=t(class{constructor(t,i,s){this.action=t,this.state=i,this.duration=s,this._id=47}encode(t){return t.uint(47)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});i.set(47,O);const P=t(class{constructor(t,i,s,e){this.operationKind=t,this.operationName=i,this.variables=s,this.response=e,this._id=48}encode(t){return t.uint(48)&&t.string(this.operationKind)&&t.string(this.operationName)&&t.string(this.variables)&&t.string(this.response)}});i.set(48,P);const q=t(class{constructor(t,i,s,e){this.frames=t,this.ticks=i,this.totalJSHeapSize=s,this.usedJSHeapSize=e,this._id=49}encode(t){return t.uint(49)&&t.int(this.frames)&&t.int(this.ticks)&&t.uint(this.totalJSHeapSize)&&t.uint(this.usedJSHeapSize)}});i.set(49,q);const D=t(class{constructor(t,i,s,e,n,r,h,o){this.timestamp=t,this.duration=i,this.ttfb=s,this.headerSize=e,this.encodedBodySize=n,this.decodedBodySize=r,this.url=h,this.initiator=o,this._id=53}encode(t){return t.uint(53)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.ttfb)&&t.uint(this.headerSize)&&t.uint(this.encodedBodySize)&&t.uint(this.decodedBodySize)&&t.string(this.url)&&t.string(this.initiator)}});i.set(53,D);const W=t(class{constructor(t,i){this.downlink=t,this.type=i,this._id=54}encode(t){return t.uint(54)&&t.uint(this.downlink)&&t.string(this.type)}});i.set(54,W);const H=t(class{constructor(t){this.hidden=t,this._id=55}encode(t){return t.uint(55)&&t.boolean(this.hidden)}});i.set(55,H);const J=t(class{constructor(t,i,s,e,n,r,h){this.timestamp=t,this.duration=i,this.context=s,this.containerType=e,this.containerSrc=n,this.containerId=r,this.containerName=h,this._id=59}encode(t){return t.uint(59)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.context)&&t.uint(this.containerType)&&t.string(this.containerSrc)&&t.string(this.containerId)&&t.string(this.containerName)}});i.set(59,J);const F=t(class{constructor(t,i,s,e){this.id=t,this.name=i,this.value=s,this.baseURL=e,this._id=60}encode(t){return t.uint(60)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)&&t.string(this.baseURL)}});i.set(60,F);const X=t(class{constructor(t,i,s){this.id=t,this.data=i,this.baseURL=s,this._id=61}encode(t){return t.uint(61)&&t.uint(this.id)&&t.string(this.data)&&t.string(this.baseURL)}});i.set(61,X);const G=t(class{constructor(t,i){this.type=t,this.value=i,this._id=63}encode(t){return t.uint(63)&&t.string(this.type)&&t.string(this.value)}});i.set(63,G);const K=t(class{constructor(t,i){this.name=t,this.payload=i,this._id=64}encode(t){return t.uint(64)&&t.string(this.name)&&t.string(this.payload)}});i.set(64,K);const j=t(class{constructor(){this._id=65}encode(t){return t.uint(65)}});i.set(65,j);const Q=t(class{constructor(t,i,s,e){this.id=t,this.rule=i,this.index=s,this.baseURL=e,this._id=67}encode(t){return t.uint(67)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)&&t.string(this.baseURL)}});i.set(67,Q);const V=t(class{constructor(t,i,s,e){this.id=t,this.hesitationTime=i,this.label=s,this.selector=e,this._id=69}encode(t){return t.uint(69)&&t.uint(this.id)&&t.uint(this.hesitationTime)&&t.string(this.label)&&t.string(this.selector)}});i.set(69,V);const Y=t(class{constructor(t,i){this.frameID=t,this.id=i,this._id=70}encode(t){return t.uint(70)&&t.uint(this.frameID)&&t.uint(this.id)}});i.set(70,Y);class Z{constructor(t,i,s,e=10,n=1e3){this.onUnauthorised=i,this.onFailure=s,this.MAX_ATTEMPTS_COUNT=e,this.ATTEMPT_TIMEOUT=n,this.attemptsCount=0,this.busy=!1,this.queue=[],this.token=null,this.ingestURL=t+"/v1/web/i"}authorise(t){this.token=t}push(t){this.busy||!this.token?this.queue.push(t):this.sendBatch(t)}retry(t){this.attemptsCount>=this.MAX_ATTEMPTS_COUNT?this.onFailure():(this.attemptsCount++,setTimeout(()=>this.sendBatch(t),this.ATTEMPT_TIMEOUT*this.attemptsCount))}sendBatch(t){this.busy=!0,fetch(this.ingestURL,{body:t,method:"POST",headers:{Authorization:"Bearer "+this.token},keepalive:t.length<65536}).then(i=>{if(401===i.status)return this.busy=!1,void this.onUnauthorised();if(i.status>=400)return void this.retry(t);this.attemptsCount=0;const s=this.queue.shift();s?this.sendBatch(s):this.busy=!1}).catch(i=>{console.warn("OpenReplay:",i),this.retry(t)})}clean(){this.queue.length=0}}const tt="function"==typeof TextEncoder?new TextEncoder:{encode(t){const i=t.length,s=new Uint8Array(3*i);let e=-1;for(var n=0,r=0,h=0;h!==i;){if(n=t.charCodeAt(h),h+=1,n>=55296&&n<=56319){if(h===i){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;break}if(!((r=t.charCodeAt(h))>=56320&&r<=57343)){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;continue}if(h+=1,(n=1024*(n-55296)+r-56320+65536)>65535){s[e+=1]=240|n>>>18,s[e+=1]=128|n>>>12&63,s[e+=1]=128|n>>>6&63,s[e+=1]=128|63&n;continue}}n<=127?s[e+=1]=0|n:n<=2047?(s[e+=1]=192|n>>>6,s[e+=1]=128|63&n):(s[e+=1]=224|n>>>12,s[e+=1]=128|n>>>6&63,s[e+=1]=128|63&n)}return s.subarray(0,e+1)}};class it{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}checkpoint(){this.checkpointOffset=this.offset}isEmpty(){return 0===this.offset}boolean(t){return this.data[this.offset++]=+t,this.offset<=this.size}uint(t){for((t<0||t>Number.MAX_SAFE_INTEGER)&&(t=0);t>=128;)this.data[this.offset++]=t%256|128,t=Math.floor(t/128);return this.data[this.offset++]=t,this.offset<=this.size}int(t){return t=Math.round(t),this.uint(t>=0?2*t:-2*t-1)}string(t){const i=tt.encode(t),s=i.byteLength;return!(!this.uint(s)||this.offset+s>this.size)&&(this.data.set(i,this.offset),this.offset+=s,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}class st{constructor(t,i,s){this.pageNo=t,this.timestamp=i,this.onBatch=s,this.nextIndex=0,this.beaconSize=2e5,this.writer=new it(this.beaconSize),this.isEmpty=!0,this.beaconSizeLimit=1e6,this.prepareBatchMeta()}prepareBatchMeta(){return new s(this.pageNo,this.nextIndex,this.timestamp).encode(this.writer)}setBeaconSizeLimit(t){this.beaconSizeLimit=t}writeMessage(t){if(t instanceof e&&(this.timestamp=t.timestamp),!t.encode(this.writer))for(this.isEmpty||(this.onBatch(this.writer.flush()),this.prepareBatchMeta());!t.encode(this.writer);){if(this.beaconSize===this.beaconSizeLimit)return console.warn("OpenReplay: beacon size overflow. Skipping large message."),this.writer.reset(),this.prepareBatchMeta(),void(this.isEmpty=!0);this.beaconSize=Math.min(2*this.beaconSize,this.beaconSizeLimit),this.writer=new it(this.beaconSize),this.prepareBatchMeta()}this.writer.checkpoint(),this.nextIndex++,this.isEmpty=!1}finaliseBatch(){this.isEmpty||(this.onBatch(this.writer.flush()),this.prepareBatchMeta(),this.isEmpty=!0)}clean(){this.writer.reset()}}let et=null,nt=null;function rt(){nt&&nt.finaliseBatch()}function ht(){null!==ct&&(clearInterval(ct),ct=null),nt&&(nt.clean(),nt=null)}let ot,ct=null;self.onmessage=({data:t})=>{if(null!=t){if("stop"===t)return rt(),void ht();if(Array.isArray(t)){if(!nt)throw new Error("WebWorker: writer not initialised.");const s=nt;t.forEach(t=>{const e=new(i.get(t._id));Object.assign(e,t),e instanceof H&&(e.hidden?ot=setTimeout(()=>self.postMessage("restart"),18e5):clearTimeout(ot)),s.writeMessage(e)})}else{if("start"===t.type)return et=new Z(t.ingestPoint,()=>{self.postMessage("restart")},()=>{et&&(et.clean(),et=null),ht(),self.postMessage("failed")},t.connAttemptCount,t.connAttemptGap),nt=new st(t.pageNo,t.timestamp,t=>et&&et.push(t)),void(null===ct&&(ct=setInterval(rt,1e4)));if("auth"===t.type){if(!et)throw new Error("WebWorker: sender not initialised. Recieved auth.");if(!nt)throw new Error("WebWorker: writer not initialised. Recieved auth.");return et.authorise(t.token),void(t.beaconSizeLimit&&nt.setBeaconSizeLimit(t.beaconSizeLimit))}}}else rt()};
61
68
  `], { type: 'text/javascript' })));
@@ -113,7 +120,7 @@ class App {
113
120
  }
114
121
  commit() {
115
122
  if (this.worker && this.messages.length) {
116
- this.messages.unshift(new index_js_1.Timestamp((0, utils_js_1.timestamp)()));
123
+ this.messages.unshift(new messages_js_1.Timestamp((0, utils_js_1.timestamp)()));
117
124
  this.worker.postMessage(this.messages);
118
125
  this.commitCallbacks.forEach(cb => cb(this.messages));
119
126
  this.messages.length = 0;
@@ -163,7 +170,7 @@ class App {
163
170
  }
164
171
  getStartInfo() {
165
172
  return {
166
- userUUID: localStorage.getItem(this.options.local_uuid_key),
173
+ userUUID: this.localStorage.getItem(this.options.local_uuid_key),
167
174
  projectKey: this.projectKey,
168
175
  revID: this.revID,
169
176
  timestamp: (0, utils_js_1.timestamp)(),
@@ -175,7 +182,7 @@ class App {
175
182
  return Object.assign(Object.assign({}, this.session.getInfo()), this.getStartInfo());
176
183
  }
177
184
  getSessionToken() {
178
- const token = sessionStorage.getItem(this.options.session_token_key);
185
+ const token = this.sessionStorage.getItem(this.options.session_token_key);
179
186
  if (token !== null) {
180
187
  return token;
181
188
  }
@@ -217,27 +224,27 @@ class App {
217
224
  }
218
225
  resetNextPageSession(flag) {
219
226
  if (flag) {
220
- sessionStorage.setItem(this.options.session_reset_key, 't');
227
+ this.sessionStorage.setItem(this.options.session_reset_key, 't');
221
228
  }
222
229
  else {
223
- sessionStorage.removeItem(this.options.session_reset_key);
230
+ this.sessionStorage.removeItem(this.options.session_reset_key);
224
231
  }
225
232
  }
226
233
  _start(startOpts) {
227
234
  if (!this.worker) {
228
- return Promise.reject("No worker found: perhaps, CSP is not set.");
235
+ return Promise.resolve(UnsuccessfulStart("No worker found: perhaps, CSP is not set."));
229
236
  }
230
237
  if (this.activityState !== ActivityState.NotActive) {
231
- return Promise.reject("OpenReplay: trying to call `start()` on the instance that has been started already.");
238
+ return Promise.resolve(UnsuccessfulStart("OpenReplay: trying to call `start()` on the instance that has been started already."));
232
239
  }
233
240
  this.activityState = ActivityState.Starting;
234
241
  let pageNo = 0;
235
- const pageNoStr = sessionStorage.getItem(this.options.session_pageno_key);
242
+ const pageNoStr = this.sessionStorage.getItem(this.options.session_pageno_key);
236
243
  if (pageNoStr != null) {
237
244
  pageNo = parseInt(pageNoStr);
238
245
  pageNo++;
239
246
  }
240
- sessionStorage.setItem(this.options.session_pageno_key, pageNo.toString());
247
+ this.sessionStorage.setItem(this.options.session_pageno_key, pageNo.toString());
241
248
  const startInfo = this.getStartInfo();
242
249
  const startWorkerMsg = {
243
250
  type: "start",
@@ -248,14 +255,14 @@ class App {
248
255
  connAttemptGap: this.options.connAttemptGap,
249
256
  };
250
257
  this.worker.postMessage(startWorkerMsg); // brings delay of 10th ms?
251
- const sReset = sessionStorage.getItem(this.options.session_reset_key);
252
- sessionStorage.removeItem(this.options.session_reset_key);
258
+ const sReset = this.sessionStorage.getItem(this.options.session_reset_key);
259
+ this.sessionStorage.removeItem(this.options.session_reset_key);
253
260
  return window.fetch(this.options.ingestPoint + '/v1/web/start', {
254
261
  method: 'POST',
255
262
  headers: {
256
263
  'Content-Type': 'application/json',
257
264
  },
258
- body: JSON.stringify(Object.assign(Object.assign({}, startInfo), { userID: startOpts.userID || this.session.getInfo().userID, token: sessionStorage.getItem(this.options.session_token_key), deviceMemory: performance_js_1.deviceMemory,
265
+ body: JSON.stringify(Object.assign(Object.assign({}, startInfo), { userID: startOpts.userID || this.session.getInfo().userID, token: this.sessionStorage.getItem(this.options.session_token_key), deviceMemory: performance_js_1.deviceMemory,
259
266
  jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit, reset: startOpts.forceNew || sReset !== null })),
260
267
  })
261
268
  .then(r => {
@@ -263,8 +270,8 @@ class App {
263
270
  return r.json();
264
271
  }
265
272
  else {
266
- return r.text().then(text => text === exports.CANCELED
267
- ? Promise.reject(exports.CANCELED) // TODO: return {error: CANCELED} instead
273
+ return r.text().then(text => text === CANCELED
274
+ ? Promise.reject(CANCELED) // TODO: return {error: CANCELED} instead
268
275
  : Promise.reject(`Server error: ${r.status}. ${text}`));
269
276
  }
270
277
  })
@@ -278,8 +285,8 @@ class App {
278
285
  (typeof beaconSizeLimit !== 'number' && typeof beaconSizeLimit !== 'undefined')) {
279
286
  return Promise.reject(`Incorrect server response: ${JSON.stringify(r)}`);
280
287
  }
281
- sessionStorage.setItem(this.options.session_token_key, token);
282
- localStorage.setItem(this.options.local_uuid_key, userUUID);
288
+ this.sessionStorage.setItem(this.options.session_token_key, token);
289
+ this.localStorage.setItem(this.options.local_uuid_key, userUUID);
283
290
  this.session.update(Object.assign({ sessionID }, startOpts));
284
291
  this.activityState = ActivityState.Active;
285
292
  const startWorkerMsg = {
@@ -297,17 +304,17 @@ class App {
297
304
  if (typeof this.options.onStart === 'function') {
298
305
  this.options.onStart(onStartInfo);
299
306
  }
300
- return onStartInfo;
307
+ return SuccessfulStart(onStartInfo);
301
308
  })
302
309
  .catch(reason => {
303
- sessionStorage.removeItem(this.options.session_token_key);
310
+ this.sessionStorage.removeItem(this.options.session_token_key);
304
311
  this.stop();
305
- //if (reason === CANCELED) { return Promise.resolve(CANCELED) } // TODO: what to return ????? Throwing is baad
306
- if (reason !== exports.CANCELED) {
307
- this.notify.log("OpenReplay was unable to start. ", reason);
308
- this._debug("session_start", reason);
312
+ if (reason === CANCELED) {
313
+ return UnsuccessfulStart(CANCELED);
309
314
  }
310
- return Promise.reject(reason);
315
+ this.notify.log("OpenReplay was unable to start. ", reason);
316
+ this._debug("session_start", reason);
317
+ return UnsuccessfulStart(START_ERROR);
311
318
  });
312
319
  }
313
320
  start(options = {}) {
@@ -7,7 +7,7 @@ export default class Nodes {
7
7
  constructor(node_id: string);
8
8
  attachNodeCallback(nodeCallback: NodeCallback): void;
9
9
  attachElementListener(type: string, node: Element, elementListener: EventListener): void;
10
- registerNode(node: Node): [number, boolean];
10
+ registerNode(node: Node): [id: number, isNew: boolean];
11
11
  unregisterNode(node: Node): number | undefined;
12
12
  callNodeCallbacks(node: Node): void;
13
13
  getID(node: Node): number | undefined;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const observer_js_1 = require("./observer.js");
4
- const index_js_1 = require("../../messages/index.js");
4
+ const messages_js_1 = require("../../common/messages.js");
5
5
  class IFrameObserver extends observer_js_1.default {
6
6
  observe(iframe) {
7
7
  const doc = iframe.contentDocument;
@@ -15,7 +15,7 @@ class IFrameObserver extends observer_js_1.default {
15
15
  console.log("OpenReplay: Iframe document not bound");
16
16
  return;
17
17
  }
18
- this.app.send((0, index_js_1.CreateIFrameDocument)(hostID, docID));
18
+ this.app.send((0, messages_js_1.CreateIFrameDocument)(hostID, docID));
19
19
  });
20
20
  }
21
21
  }
@@ -4,11 +4,11 @@ export default abstract class Observer {
4
4
  protected readonly isTopContext: boolean;
5
5
  private readonly observer;
6
6
  private readonly commited;
7
- private readonly recents;
8
- private readonly myNodes;
9
7
  private readonly indexes;
10
8
  private readonly attributesList;
11
9
  private readonly textSet;
10
+ private readonly newSet;
11
+ private readonly affectedSet;
12
12
  constructor(app: App, isTopContext?: boolean);
13
13
  private clear;
14
14
  private sendNodeAttribute;