@openreplay/tracker 3.5.17-beta.0 → 3.6.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.
Files changed (92) hide show
  1. package/.eslintignore +1 -1
  2. package/.prettierignore +1 -0
  3. package/LICENSE +1 -1
  4. package/cjs/app/guards.d.ts +2 -1
  5. package/cjs/app/guards.js +5 -1
  6. package/cjs/app/index.d.ts +17 -12
  7. package/cjs/app/index.js +63 -49
  8. package/cjs/app/messages.d.ts +52 -0
  9. package/cjs/app/messages.gen.d.ts +57 -0
  10. package/cjs/app/messages.gen.js +493 -0
  11. package/cjs/app/messages.js +234 -0
  12. package/cjs/app/nodes.d.ts +1 -1
  13. package/cjs/app/nodes.js +2 -0
  14. package/cjs/app/observer/iframe_observer.js +2 -2
  15. package/cjs/app/observer/observer.d.ts +1 -2
  16. package/cjs/app/observer/observer.js +40 -39
  17. package/cjs/app/observer/shadow_root_observer.js +2 -2
  18. package/cjs/app/observer/top_observer.d.ts +11 -0
  19. package/cjs/app/observer/top_observer.js +46 -12
  20. package/cjs/app/session.d.ts +19 -1
  21. package/cjs/app/session.js +61 -3
  22. package/cjs/common/{webworker.d.ts → interaction.d.ts} +3 -3
  23. package/cjs/common/{types.js → interaction.js} +0 -0
  24. package/cjs/common/messages.gen.d.ts +382 -0
  25. package/cjs/common/{webworker.js → messages.gen.js} +1 -0
  26. package/cjs/index.d.ts +3 -2
  27. package/cjs/index.js +20 -9
  28. package/cjs/modules/adoptedStyleSheets.d.ts +2 -0
  29. package/cjs/modules/adoptedStyleSheets.js +127 -0
  30. package/cjs/modules/connection.js +2 -2
  31. package/cjs/modules/console.js +6 -20
  32. package/cjs/modules/cssrules.js +16 -12
  33. package/cjs/modules/exception.d.ts +2 -2
  34. package/cjs/modules/exception.js +16 -12
  35. package/cjs/modules/img.js +31 -21
  36. package/cjs/modules/input.js +6 -6
  37. package/cjs/modules/mouse.js +42 -33
  38. package/cjs/modules/performance.js +2 -2
  39. package/cjs/modules/scroll.js +16 -7
  40. package/cjs/modules/timing.js +4 -4
  41. package/cjs/modules/viewport.js +4 -4
  42. package/lib/app/guards.d.ts +2 -1
  43. package/lib/app/guards.js +3 -0
  44. package/lib/app/index.d.ts +17 -12
  45. package/lib/app/index.js +64 -50
  46. package/lib/app/messages.d.ts +52 -0
  47. package/lib/app/messages.gen.d.ts +57 -0
  48. package/lib/app/messages.gen.js +434 -0
  49. package/lib/app/messages.js +181 -0
  50. package/lib/app/nodes.d.ts +1 -1
  51. package/lib/app/nodes.js +2 -0
  52. package/lib/app/observer/iframe_observer.js +1 -1
  53. package/lib/app/observer/observer.d.ts +1 -2
  54. package/lib/app/observer/observer.js +40 -39
  55. package/lib/app/observer/shadow_root_observer.js +1 -1
  56. package/lib/app/observer/top_observer.d.ts +11 -0
  57. package/lib/app/observer/top_observer.js +46 -12
  58. package/lib/app/session.d.ts +19 -1
  59. package/lib/app/session.js +61 -3
  60. package/lib/common/{webworker.d.ts → interaction.d.ts} +3 -3
  61. package/lib/common/{types.js → interaction.js} +0 -0
  62. package/lib/common/messages.gen.d.ts +382 -0
  63. package/lib/common/messages.gen.js +2 -0
  64. package/lib/common/tsconfig.tsbuildinfo +1 -1
  65. package/lib/index.d.ts +3 -2
  66. package/lib/index.js +20 -9
  67. package/lib/modules/adoptedStyleSheets.d.ts +2 -0
  68. package/lib/modules/adoptedStyleSheets.js +124 -0
  69. package/lib/modules/connection.js +2 -2
  70. package/lib/modules/console.js +6 -20
  71. package/lib/modules/cssrules.js +16 -12
  72. package/lib/modules/exception.d.ts +2 -2
  73. package/lib/modules/exception.js +16 -12
  74. package/lib/modules/img.js +31 -21
  75. package/lib/modules/input.js +6 -6
  76. package/lib/modules/mouse.js +43 -34
  77. package/lib/modules/performance.js +2 -2
  78. package/lib/modules/scroll.js +17 -8
  79. package/lib/modules/timing.js +4 -4
  80. package/lib/modules/viewport.js +4 -4
  81. package/package.json +1 -1
  82. package/cjs/common/messages.d.ts +0 -444
  83. package/cjs/common/messages.js +0 -794
  84. package/cjs/common/types.d.ts +0 -9
  85. package/cjs/modules/longtasks.d.ts +0 -2
  86. package/cjs/modules/longtasks.js +0 -34
  87. package/lib/common/messages.d.ts +0 -444
  88. package/lib/common/messages.js +0 -790
  89. package/lib/common/types.d.ts +0 -9
  90. package/lib/common/webworker.js +0 -1
  91. package/lib/modules/longtasks.d.ts +0 -2
  92. package/lib/modules/longtasks.js +0 -31
package/.eslintignore CHANGED
@@ -5,4 +5,4 @@ cjs
5
5
  build
6
6
  .cache
7
7
  .eslintrc.cjs
8
- src/common/messages.ts
8
+ *.gen.ts
@@ -0,0 +1 @@
1
+ *.gen.ts
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2021 OpenReplay.com <support@openreplay.com>
1
+ Copyright (c) 2022 Asayer, Inc
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,8 @@
1
1
  export declare function isSVGElement(node: Element): node is SVGElement;
2
2
  export declare function isElementNode(node: Node): node is Element;
3
3
  export declare function isTextNode(node: Node): node is Text;
4
- export declare function isRootNode(node: Node): boolean;
4
+ export declare function isDocument(node: Node): node is Document;
5
+ export declare function isRootNode(node: Node): node is Document | DocumentFragment;
5
6
  declare type TagTypeMap = {
6
7
  HTML: HTMLHtmlElement;
7
8
  IMG: HTMLImageElement;
package/cjs/app/guards.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasTag = exports.isRootNode = exports.isTextNode = exports.isElementNode = exports.isSVGElement = void 0;
3
+ exports.hasTag = exports.isRootNode = exports.isDocument = exports.isTextNode = exports.isElementNode = exports.isSVGElement = void 0;
4
4
  function isSVGElement(node) {
5
5
  return node.namespaceURI === 'http://www.w3.org/2000/svg';
6
6
  }
@@ -13,6 +13,10 @@ function isTextNode(node) {
13
13
  return node.nodeType === Node.TEXT_NODE;
14
14
  }
15
15
  exports.isTextNode = isTextNode;
16
+ function isDocument(node) {
17
+ return node.nodeType === Node.DOCUMENT_NODE;
18
+ }
19
+ exports.isDocument = isDocument;
16
20
  function isRootNode(node) {
17
21
  return node.nodeType === Node.DOCUMENT_NODE || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
18
22
  }
@@ -1,5 +1,6 @@
1
- import type Message from '../common/messages.js';
1
+ import type Message from './messages.gen.js';
2
2
  import Nodes from './nodes.js';
3
+ import Observer from './observer/top_observer.js';
3
4
  import Sanitizer from './sanitizer.js';
4
5
  import Ticker from './ticker.js';
5
6
  import Logger from './logger.js';
@@ -7,11 +8,13 @@ import Session from './session.js';
7
8
  import type { Options as ObserverOptions } from './observer/top_observer.js';
8
9
  import type { Options as SanitizerOptions } from './sanitizer.js';
9
10
  import type { Options as LoggerOptions } from './logger.js';
10
- import type { Options as WebworkerOptions } from '../common/webworker.js';
11
+ import type { Options as SessOptions } from './session.js';
12
+ import type { Options as WebworkerOptions } from '../common/interaction.js';
11
13
  export interface StartOptions {
12
14
  userID?: string;
13
15
  metadata?: Record<string, string>;
14
16
  forceNew?: boolean;
17
+ sessionHash?: string;
15
18
  }
16
19
  interface OnStartInfo {
17
20
  sessionID: string;
@@ -34,9 +37,9 @@ declare type CommitCallback = (messages: Array<Message>) => void;
34
37
  declare type AppOptions = {
35
38
  revID: string;
36
39
  node_id: string;
40
+ session_reset_key: string;
37
41
  session_token_key: string;
38
42
  session_pageno_key: string;
39
- session_reset_key: string;
40
43
  local_uuid_key: string;
41
44
  ingestPoint: string;
42
45
  resourceBaseHref: string | null;
@@ -47,7 +50,7 @@ declare type AppOptions = {
47
50
  localStorage: Storage | null;
48
51
  sessionStorage: Storage | null;
49
52
  onStart?: StartCallback;
50
- } & WebworkerOptions;
53
+ } & WebworkerOptions & SessOptions;
51
54
  export declare type Options = AppOptions & ObserverOptions & SanitizerOptions;
52
55
  export declare const DEFAULT_INGEST_POINT = "https://api.openreplay.com/ingest";
53
56
  export default class App {
@@ -61,7 +64,7 @@ export default class App {
61
64
  readonly localStorage: Storage;
62
65
  readonly sessionStorage: Storage;
63
66
  private readonly messages;
64
- private readonly observer;
67
+ readonly observer: Observer;
65
68
  private readonly startCallbacks;
66
69
  private readonly stopCallbacks;
67
70
  private readonly commitCallbacks;
@@ -70,30 +73,32 @@ export default class App {
70
73
  private activityState;
71
74
  private readonly version;
72
75
  private readonly worker?;
73
- constructor(projectKey: string, sessionToken: string | null | undefined, options: Partial<Options>);
76
+ constructor(projectKey: string, sessionToken: string | undefined, options: Partial<Options>);
74
77
  private _debug;
75
78
  send(message: Message, urgent?: boolean): void;
76
79
  private commit;
77
80
  safe<T extends (...args: any[]) => void>(fn: T): T;
78
81
  attachCommitCallback(cb: CommitCallback): void;
79
- attachStartCallback(cb: StartCallback): void;
80
- attachStopCallback(cb: () => any): void;
82
+ attachStartCallback(cb: StartCallback, useSafe?: boolean): void;
83
+ attachStopCallback(cb: () => any, useSafe?: boolean): void;
81
84
  attachEventListener(target: EventTarget, type: string, listener: EventListener, useSafe?: boolean, useCapture?: boolean): void;
82
85
  checkRequiredVersion(version: string): boolean;
83
- private getStartInfo;
86
+ private getTrackerInfo;
84
87
  getSessionInfo(): {
85
88
  userUUID: string | null;
86
89
  projectKey: string;
87
90
  revID: string;
88
- timestamp: number;
89
91
  trackerVersion: string;
90
92
  isSnippet: boolean;
91
- sessionID: string | null;
93
+ sessionID: string | undefined;
92
94
  metadata: Record<string, string>;
93
95
  userID: string | null;
96
+ timestamp: number;
97
+ projectID?: string | undefined;
94
98
  };
95
99
  getSessionToken(): string | undefined;
96
100
  getSessionID(): string | undefined;
101
+ getSessionURL(): string | undefined;
97
102
  getHost(): string;
98
103
  getProjectKey(): string;
99
104
  getBaseHref(): string;
@@ -103,7 +108,7 @@ export default class App {
103
108
  resetNextPageSession(flag: boolean): void;
104
109
  private _start;
105
110
  start(options?: StartOptions): Promise<StartPromiseReturn>;
106
- stop(calledFromAPI?: boolean, restarting?: boolean): void;
111
+ stop(stopWorker?: boolean): void;
107
112
  restart(): void;
108
113
  }
109
114
  export {};
package/cjs/app/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFAULT_INGEST_POINT = void 0;
4
- const messages_js_1 = require("../common/messages.js");
4
+ const messages_gen_js_1 = require("./messages.gen.js");
5
5
  const utils_js_1 = require("../utils.js");
6
6
  const nodes_js_1 = require("./nodes.js");
7
7
  const top_observer_js_1 = require("./observer/top_observer.js");
@@ -27,13 +27,12 @@ class App {
27
27
  // if (options.onStart !== undefined) {
28
28
  // deprecationWarn("'onStart' option", "tracker.start().then(/* handle session info */)")
29
29
  // } ?? maybe onStart is good
30
- var _a, _b;
31
30
  this.messages = [];
32
31
  this.startCallbacks = [];
33
32
  this.stopCallbacks = [];
34
33
  this.commitCallbacks = [];
35
34
  this.activityState = ActivityState.NotActive;
36
- this.version = '3.5.16'; // TODO: version compatability check inside each plugin.
35
+ this.version = '3.6.1'; // TODO: version compatability check inside each plugin.
37
36
  this.projectKey = projectKey;
38
37
  this.options = Object.assign({
39
38
  revID: '',
@@ -47,8 +46,8 @@ class App {
47
46
  verbose: false,
48
47
  __is_snippet: false,
49
48
  __debug_report_edp: null,
50
- localStorage: null,
51
- sessionStorage: null,
49
+ localStorage: window === null || window === void 0 ? void 0 : window.localStorage,
50
+ sessionStorage: window === null || window === void 0 ? void 0 : window.sessionStorage,
52
51
  }, options);
53
52
  this.revID = this.options.revID;
54
53
  this.sanitizer = new sanitizer_js_1.default(this, options);
@@ -58,24 +57,24 @@ class App {
58
57
  this.ticker.attach(() => this.commit());
59
58
  this.debug = new logger_js_1.default(this.options.__debug__);
60
59
  this.notify = new logger_js_1.default(this.options.verbose ? logger_js_1.LogLevel.Warnings : logger_js_1.LogLevel.Silent);
61
- this.session = new session_js_1.default();
60
+ this.localStorage = this.options.localStorage || window.localStorage;
61
+ this.sessionStorage = this.options.sessionStorage || window.sessionStorage;
62
+ this.session = new session_js_1.default(this, this.options);
62
63
  this.session.attachUpdateCallback(({ userID, metadata }) => {
63
64
  if (userID != null) {
64
65
  // TODO: nullable userID
65
- this.send(new messages_js_1.UserID(userID));
66
+ this.send((0, messages_gen_js_1.UserID)(userID));
66
67
  }
67
68
  if (metadata != null) {
68
- Object.entries(metadata).forEach(([key, value]) => this.send(new messages_js_1.Metadata(key, value)));
69
+ Object.entries(metadata).forEach(([key, value]) => this.send((0, messages_gen_js_1.Metadata)(key, value)));
69
70
  }
70
71
  });
71
- // window.localStorage and window.sessionStorage should only be accessed if required, see #490, #637
72
- this.localStorage = (_a = this.options.localStorage) !== null && _a !== void 0 ? _a : window.localStorage;
73
- this.sessionStorage = (_b = this.options.sessionStorage) !== null && _b !== void 0 ? _b : window.sessionStorage;
72
+ // @depricated (use sessionHash on start instead)
74
73
  if (sessionToken != null) {
75
- this.sessionStorage.setItem(this.options.session_token_key, sessionToken);
74
+ this.session.applySessionHash(sessionToken);
76
75
  }
77
76
  try {
78
- 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 g=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,g);const m=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,m);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 S=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,S);const b=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,b);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 A=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,A);const I=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,I);const L=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,L);const C=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,C);const M=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,M);const N=t(class{constructor(t){this.type=t,this._id=42}encode(t){return t.uint(42)&&t.string(this.type)}});i.set(42,N);const B=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,B);const U=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,U);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(let 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),!(r>=56320&&r<=57343)){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;continue}if(n=1024*(n-55296)+r-56320+65536,h+=1,n>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.prepare()}prepare(){this.writer.isEmpty()&&new s(this.pageNo,this.nextIndex,this.timestamp).encode(this.writer)}write(t){const i=t.encode(this.writer);return i&&(this.isEmpty=!1,this.writer.checkpoint(),this.nextIndex++),i}setBeaconSizeLimit(t){this.beaconSizeLimit=t}writeMessage(t){if(t instanceof e&&(this.timestamp=t.timestamp),!this.write(t))for(this.finaliseBatch();!this.write(t);){if(this.beaconSize===this.beaconSizeLimit)return console.warn("OpenReplay: beacon size overflow. Skipping large message."),this.writer.reset(),this.prepare(),void(this.isEmpty=!0);this.beaconSize=Math.min(2*this.beaconSize,this.beaconSizeLimit),this.writer=new it(this.beaconSize),this.prepare(),this.isEmpty=!0}}finaliseBatch(){this.isEmpty||(this.onBatch(this.writer.flush()),this.prepare(),this.isEmpty=!0)}clean(){this.writer.reset()}}var et;!function(t){t[t.NotActive=0]="NotActive",t[t.Starting=1]="Starting",t[t.Stopping=2]="Stopping",t[t.Active=3]="Active"}(et||(et={}));let nt=null,rt=null;function ht(){rt&&rt.finaliseBatch()}function ot(){et.Stopping,null!==at&&(clearInterval(at),at=null),rt&&(rt.clean(),rt=null),et.NotActive}et.NotActive;let ct,at=null;self.onmessage=({data:t})=>{if(null!=t){if("stop"===t)return ht(),void ot();if(Array.isArray(t)){if(!rt)throw new Error("WebWorker: writer not initialised. Service Should be Started.");const s=rt;t.forEach(t=>{const e=new(i.get(t._id));Object.assign(e,t),e instanceof H&&(e.hidden?ct=setTimeout(()=>self.postMessage("restart"),18e5):clearTimeout(ct)),s.writeMessage(e)})}else{if("start"===t.type)return et.Starting,nt=new Z(t.ingestPoint,()=>{self.postMessage("restart")},()=>{nt&&(nt.clean(),nt=null),ot(),self.postMessage("failed")},t.connAttemptCount,t.connAttemptGap),rt=new st(t.pageNo,t.timestamp,t=>nt&&nt.push(t)),null===at&&(at=setInterval(ht,1e4)),et.Active;if("auth"===t.type){if(!nt)throw new Error("WebWorker: sender not initialised. Received auth.");if(!rt)throw new Error("WebWorker: writer not initialised. Received auth.");return nt.authorise(t.token),void(t.beaconSizeLimit&&rt.setBeaconSizeLimit(t.beaconSizeLimit))}}}else ht()};'], { type: 'text/javascript' })));
77
+ this.worker = new Worker(URL.createObjectURL(new Blob(['"use strict";class t{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 i="function"==typeof TextEncoder?new TextEncoder:{encode(t){const i=t.length,s=new Uint8Array(3*i);let e=-1;for(let 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),!(r>=56320&&r<=57343)){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;continue}if(n=1024*(n-55296)+r-56320+65536,h+=1,n>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 s extends class{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}getCurrentOffset(){return this.offset}checkpoint(){this.checkpointOffset=this.offset}isEmpty(){return 0===this.offset}skip(t){return this.offset+=t,this.offset<=this.size}set(t,i){this.data.set(t,i)}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 s=i.encode(t),e=s.byteLength;return!(!this.uint(e)||this.offset+e>this.size)&&(this.data.set(s,this.offset),this.offset+=e,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}{encode(t){switch(t[0]){case 81:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.int(t[4])&&this.string(t[5]);case 82:return this.uint(t[1])&&this.uint(t[2]);case 0:return this.uint(t[1]);case 4:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 5:return this.uint(t[1])&&this.uint(t[2]);case 6:return this.int(t[1])&&this.int(t[2]);case 7:return!0;case 8:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.string(t[4])&&this.boolean(t[5]);case 9:case 10:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 11:return this.uint(t[1]);case 12:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 13:case 14:return this.uint(t[1])&&this.string(t[2]);case 16:return this.uint(t[1])&&this.int(t[2])&&this.int(t[3]);case 17:return this.uint(t[1])&&this.string(t[2]);case 18:return this.uint(t[1])&&this.string(t[2])&&this.int(t[3]);case 19:return this.uint(t[1])&&this.boolean(t[2]);case 20:return this.uint(t[1])&&this.uint(t[2]);case 22:return this.string(t[1])&&this.string(t[2]);case 23:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8])&&this.uint(t[9]);case 24:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 25:return this.string(t[1])&&this.string(t[2])&&this.string(t[3]);case 27:return this.string(t[1])&&this.string(t[2]);case 28:case 29:return this.string(t[1]);case 30:return this.string(t[1])&&this.string(t[2]);case 37:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3]);case 38:return this.uint(t[1])&&this.uint(t[2]);case 39:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.uint(t[7]);case 40:return this.string(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 41:return this.string(t[1])&&this.string(t[2]);case 42:return this.string(t[1]);case 44:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 45:case 46:return this.string(t[1])&&this.string(t[2]);case 47:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 48:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 49:return this.int(t[1])&&this.int(t[2])&&this.uint(t[3])&&this.uint(t[4]);case 53:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8]);case 54:return this.uint(t[1])&&this.string(t[2]);case 55:return this.boolean(t[1]);case 59:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.string(t[5])&&this.string(t[6])&&this.string(t[7]);case 60:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 61:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 63:case 64:return this.string(t[1])&&this.string(t[2]);case 67:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 69:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 70:return this.uint(t[1])&&this.uint(t[2]);case 71:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 73:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 75:case 76:case 77:return this.uint(t[1])&&this.uint(t[2])}}}class e{constructor(t,i,e,n){this.pageNo=t,this.timestamp=i,this.url=e,this.onBatch=n,this.nextIndex=0,this.beaconSize=2e5,this.encoder=new s(this.beaconSize),this.sizeBuffer=new Uint8Array(3),this.isEmpty=!0,this.beaconSizeLimit=1e6,this.prepare()}writeType(t){return this.encoder.uint(t[0])}writeFields(t){return this.encoder.encode(t)}writeSizeAt(t,i){for(let i=0;i<3;i++)this.sizeBuffer[i]=t>>8*i;this.encoder.set(this.sizeBuffer,i)}prepare(){if(!this.encoder.isEmpty())return;const t=[81,1,this.pageNo,this.nextIndex,this.timestamp,this.url];this.writeType(t),this.writeFields(t),this.isEmpty=!0}writeWithSize(t){const i=this.encoder;if(!this.writeType(t)||!i.skip(3))return!1;const s=i.getCurrentOffset(),e=this.writeFields(t);if(e){const e=i.getCurrentOffset()-s;if(e>16777215)return console.warn("OpenReplay: max message size overflow."),!1;this.writeSizeAt(e,s-3),i.checkpoint(),this.isEmpty=this.isEmpty&&0===t[0],this.nextIndex++}return e}setBeaconSizeLimit(t){this.beaconSizeLimit=t}writeMessage(t){if(0===t[0]&&(this.timestamp=t[1]),4===t[0]&&(this.url=t[1]),!this.writeWithSize(t))for(this.finaliseBatch();!this.writeWithSize(t);){if(this.beaconSize===this.beaconSizeLimit)return console.warn("OpenReplay: beacon size overflow. Skipping large message.",t,this),this.encoder.reset(),void this.prepare();this.beaconSize=Math.min(2*this.beaconSize,this.beaconSizeLimit),this.encoder=new s(this.beaconSize),this.prepare()}}finaliseBatch(){this.isEmpty||(this.onBatch(this.encoder.flush()),this.prepare())}clean(){this.encoder.reset()}}var n;!function(t){t[t.NotActive=0]="NotActive",t[t.Starting=1]="Starting",t[t.Stopping=2]="Stopping",t[t.Active=3]="Active"}(n||(n={}));let r=null,h=null;function u(){h&&h.finaliseBatch()}function a(){n.Stopping,null!==c&&(clearInterval(c),c=null),h&&(h.clean(),h=null),n.NotActive}n.NotActive;let o,c=null;self.onmessage=({data:i})=>{if(null!=i){if("stop"===i)return u(),void a();if(Array.isArray(i)){if(!h)throw new Error("WebWorker: writer not initialised. Service Should be Started.");const t=h;i.forEach(i=>{55===i[0]&&(i[1]?o=setTimeout(()=>self.postMessage("restart"),18e5):clearTimeout(o)),t.writeMessage(i)})}else{if("start"===i.type)return n.Starting,r=new t(i.ingestPoint,()=>{self.postMessage("restart")},()=>{r&&(r.clean(),r=null),a(),self.postMessage("failed")},i.connAttemptCount,i.connAttemptGap),h=new e(i.pageNo,i.timestamp,i.url,t=>r&&r.push(t)),null===c&&(c=setInterval(u,1e4)),n.Active;if("auth"===i.type){if(!r)throw new Error("WebWorker: sender not initialised. Received auth.");if(!h)throw new Error("WebWorker: writer not initialised. Received auth.");return r.authorise(i.token),void(i.beaconSizeLimit&&h.setBeaconSizeLimit(i.beaconSizeLimit))}}}else u()};'], { type: 'text/javascript' })));
79
78
  this.worker.onerror = (e) => {
80
79
  this._debug('webworker_error', e);
81
80
  };
@@ -132,7 +131,7 @@ class App {
132
131
  }
133
132
  commit() {
134
133
  if (this.worker && this.messages.length) {
135
- this.messages.unshift(new messages_js_1.Timestamp((0, utils_js_1.timestamp)()));
134
+ this.messages.unshift((0, messages_gen_js_1.Timestamp)((0, utils_js_1.timestamp)()));
136
135
  this.worker.postMessage(this.messages);
137
136
  this.commitCallbacks.forEach((cb) => cb(this.messages));
138
137
  this.messages.length = 0;
@@ -146,7 +145,7 @@ class App {
146
145
  }
147
146
  catch (e) {
148
147
  app._debug('safe_fn_call', e);
149
- // time: timestamp(),
148
+ // time: now(),
150
149
  // name: e.name,
151
150
  // message: e.message,
152
151
  // stack: e.stack
@@ -154,54 +153,72 @@ class App {
154
153
  }; // TODO: correct typing
155
154
  }
156
155
  attachCommitCallback(cb) {
156
+ // TODO!: what if start callback added when activityState === Active ?
157
+ // For example - attachEventListener() called during dynamic <iframe> appearance
157
158
  this.commitCallbacks.push(cb);
158
159
  }
159
- attachStartCallback(cb) {
160
+ attachStartCallback(cb, useSafe = false) {
161
+ if (useSafe) {
162
+ cb = this.safe(cb);
163
+ }
160
164
  this.startCallbacks.push(cb);
161
165
  }
162
- attachStopCallback(cb) {
166
+ attachStopCallback(cb, useSafe = false) {
167
+ if (useSafe) {
168
+ cb = this.safe(cb);
169
+ }
163
170
  this.stopCallbacks.push(cb);
164
171
  }
165
172
  attachEventListener(target, type, listener, useSafe = true, useCapture = true) {
166
173
  if (useSafe) {
167
174
  listener = this.safe(listener);
168
175
  }
169
- this.attachStartCallback(() => target.addEventListener(type, listener, useCapture));
170
- this.attachStopCallback(() => target.removeEventListener(type, listener, useCapture));
176
+ this.attachStartCallback(() => target.addEventListener(type, listener, useCapture), useSafe);
177
+ this.attachStopCallback(() => target.removeEventListener(type, listener, useCapture), useSafe);
171
178
  }
172
179
  // TODO: full correct semantic
173
180
  checkRequiredVersion(version) {
174
181
  const reqVer = version.split(/[.-]/);
175
182
  const ver = this.version.split(/[.-]/);
176
183
  for (let i = 0; i < 3; i++) {
177
- if (Number(ver[i]) < Number(reqVer[i]) || isNaN(Number(ver[i])) || isNaN(Number(reqVer[i]))) {
184
+ if (isNaN(Number(ver[i])) || isNaN(Number(reqVer[i]))) {
185
+ return false;
186
+ }
187
+ if (Number(ver[i]) > Number(reqVer[i])) {
188
+ return true;
189
+ }
190
+ if (Number(ver[i]) < Number(reqVer[i])) {
178
191
  return false;
179
192
  }
180
193
  }
181
194
  return true;
182
195
  }
183
- getStartInfo() {
196
+ getTrackerInfo() {
184
197
  return {
185
198
  userUUID: this.localStorage.getItem(this.options.local_uuid_key),
186
199
  projectKey: this.projectKey,
187
200
  revID: this.revID,
188
- timestamp: (0, utils_js_1.timestamp)(),
189
201
  trackerVersion: this.version,
190
202
  isSnippet: this.options.__is_snippet,
191
203
  };
192
204
  }
193
205
  getSessionInfo() {
194
- return Object.assign(Object.assign({}, this.session.getInfo()), this.getStartInfo());
206
+ return Object.assign(Object.assign({}, this.session.getInfo()), this.getTrackerInfo());
195
207
  }
196
208
  getSessionToken() {
197
- const token = this.sessionStorage.getItem(this.options.session_token_key);
198
- if (token !== null) {
199
- return token;
200
- }
209
+ return this.session.getSessionToken();
201
210
  }
202
211
  getSessionID() {
203
212
  return this.session.getInfo().sessionID || undefined;
204
213
  }
214
+ getSessionURL() {
215
+ const { projectID, sessionID } = this.session.getInfo();
216
+ if (!projectID || !sessionID) {
217
+ this.debug.error('OpenReplay error: Unable to build session URL');
218
+ return undefined;
219
+ }
220
+ return this.options.ingestPoint.replace(/ingest$/, `${projectID}/session/${sessionID}`);
221
+ }
205
222
  getHost() {
206
223
  return new URL(this.options.ingestPoint).hostname;
207
224
  }
@@ -214,7 +231,7 @@ class App {
214
231
  return this.options.resourceBaseHref;
215
232
  }
216
233
  else if (typeof this.options.resourceBaseHref === 'object') {
217
- //switch between types
234
+ //TODO: switch between types
218
235
  }
219
236
  if (document.baseURI) {
220
237
  return document.baseURI;
@@ -251,19 +268,16 @@ class App {
251
268
  return Promise.resolve(UnsuccessfulStart('OpenReplay: trying to call `start()` on the instance that has been started already.'));
252
269
  }
253
270
  this.activityState = ActivityState.Starting;
254
- let pageNo = 0;
255
- const pageNoStr = this.sessionStorage.getItem(this.options.session_pageno_key);
256
- if (pageNoStr != null) {
257
- pageNo = parseInt(pageNoStr);
258
- pageNo++;
271
+ if (startOpts.sessionHash) {
272
+ this.session.applySessionHash(startOpts.sessionHash);
259
273
  }
260
- this.sessionStorage.setItem(this.options.session_pageno_key, pageNo.toString());
261
- const startInfo = this.getStartInfo();
274
+ const timestamp = (0, utils_js_1.timestamp)();
262
275
  const startWorkerMsg = {
263
276
  type: 'start',
264
- pageNo,
277
+ pageNo: this.session.incPageNo(),
265
278
  ingestPoint: this.options.ingestPoint,
266
- timestamp: startInfo.timestamp,
279
+ timestamp,
280
+ url: document.URL,
267
281
  connAttemptCount: this.options.connAttemptCount,
268
282
  connAttemptGap: this.options.connAttemptGap,
269
283
  };
@@ -283,7 +297,7 @@ class App {
283
297
  headers: {
284
298
  'Content-Type': 'application/json',
285
299
  },
286
- body: JSON.stringify(Object.assign(Object.assign({}, startInfo), { userID: this.session.getInfo().userID, token: this.sessionStorage.getItem(this.options.session_token_key), deviceMemory: performance_js_1.deviceMemory,
300
+ body: JSON.stringify(Object.assign(Object.assign({}, this.getTrackerInfo()), { timestamp, userID: this.session.getInfo().userID, token: this.session.getSessionToken(), deviceMemory: performance_js_1.deviceMemory,
287
301
  jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit, reset: startOpts.forceNew || sReset !== null })),
288
302
  })
289
303
  .then((r) => {
@@ -302,26 +316,29 @@ class App {
302
316
  if (!this.worker) {
303
317
  return Promise.reject('no worker found after start request (this might not happen)');
304
318
  }
305
- const { token, userUUID, sessionID, beaconSizeLimit } = r;
319
+ const { token, userUUID, sessionID, projectID, beaconSizeLimit, startTimestamp, // real startTS, derived from sessionID
320
+ } = r;
306
321
  if (typeof token !== 'string' ||
307
322
  typeof userUUID !== 'string' ||
323
+ //typeof startTimestamp !== 'number' ||
324
+ //typeof sessionID !== 'string' ||
308
325
  (typeof beaconSizeLimit !== 'number' && typeof beaconSizeLimit !== 'undefined')) {
309
326
  return Promise.reject(`Incorrect server response: ${JSON.stringify(r)}`);
310
327
  }
311
- this.sessionStorage.setItem(this.options.session_token_key, token);
328
+ this.session.setSessionToken(token);
312
329
  this.localStorage.setItem(this.options.local_uuid_key, userUUID);
313
- this.session.update({ sessionID }); // TODO: no no-explicit 'any'
330
+ this.session.update({ sessionID, timestamp: startTimestamp || timestamp, projectID }); // TODO: no no-explicit 'any'
314
331
  const startWorkerMsg = {
315
332
  type: 'auth',
316
333
  token,
317
334
  beaconSizeLimit,
318
335
  };
319
336
  this.worker.postMessage(startWorkerMsg);
320
- this.activityState = ActivityState.Active;
321
337
  const onStartInfo = { sessionToken: token, userUUID, sessionID };
322
338
  this.startCallbacks.forEach((cb) => cb(onStartInfo)); // TODO: start as early as possible (before receiving the token)
323
339
  this.observer.observe();
324
340
  this.ticker.start();
341
+ this.activityState = ActivityState.Active;
325
342
  this.notify.log('OpenReplay tracking started.');
326
343
  // get rid of onStart ?
327
344
  if (typeof this.options.onStart === 'function') {
@@ -330,8 +347,8 @@ class App {
330
347
  return SuccessfulStart(onStartInfo);
331
348
  })
332
349
  .catch((reason) => {
333
- this.sessionStorage.removeItem(this.options.session_token_key);
334
350
  this.stop();
351
+ this.session.reset();
335
352
  if (reason === CANCELED) {
336
353
  return UnsuccessfulStart(CANCELED);
337
354
  }
@@ -356,7 +373,7 @@ class App {
356
373
  });
357
374
  }
358
375
  }
359
- stop(calledFromAPI = false, restarting = false) {
376
+ stop(stopWorker = true) {
360
377
  if (this.activityState !== ActivityState.NotActive) {
361
378
  try {
362
379
  this.sanitizer.clear();
@@ -364,11 +381,8 @@ class App {
364
381
  this.nodes.clear();
365
382
  this.ticker.stop();
366
383
  this.stopCallbacks.forEach((cb) => cb());
367
- if (calledFromAPI) {
368
- this.session.reset();
369
- }
370
384
  this.notify.log('OpenReplay tracking stopped.');
371
- if (this.worker && !restarting) {
385
+ if (this.worker && stopWorker) {
372
386
  this.worker.postMessage('stop');
373
387
  }
374
388
  }
@@ -378,7 +392,7 @@ class App {
378
392
  }
379
393
  }
380
394
  restart() {
381
- this.stop(false, true);
395
+ this.stop(false);
382
396
  this.start({ forceNew: false });
383
397
  }
384
398
  }
@@ -0,0 +1,52 @@
1
+ import * as Messages from '../common/messages.gen.js';
2
+ export { default } from '../common/messages.gen.js';
3
+ export declare function BatchMetadata(version: number, pageNo: number, firstIndex: number, timestamp: number, location: string): Messages.BatchMetadata;
4
+ export declare function PartitionedMessage(partNo: number, partTotal: number): Messages.PartitionedMessage;
5
+ export declare function Timestamp(timestamp: number): Messages.Timestamp;
6
+ export declare function SetPageLocation(url: string, referrer: string, navigationStart: number): Messages.SetPageLocation;
7
+ export declare function SetViewportSize(width: number, height: number): Messages.SetViewportSize;
8
+ export declare function SetViewportScroll(x: number, y: number): Messages.SetViewportScroll;
9
+ export declare function CreateDocument(): Messages.CreateDocument;
10
+ export declare function CreateElementNode(id: number, parentID: number, index: number, tag: string, svg: boolean): Messages.CreateElementNode;
11
+ export declare function CreateTextNode(id: number, parentID: number, index: number): Messages.CreateTextNode;
12
+ export declare function MoveNode(id: number, parentID: number, index: number): Messages.MoveNode;
13
+ export declare function RemoveNode(id: number): Messages.RemoveNode;
14
+ export declare function SetNodeAttribute(id: number, name: string, value: string): Messages.SetNodeAttribute;
15
+ export declare function RemoveNodeAttribute(id: number, name: string): Messages.RemoveNodeAttribute;
16
+ export declare function SetNodeData(id: number, data: string): Messages.SetNodeData;
17
+ export declare function SetNodeScroll(id: number, x: number, y: number): Messages.SetNodeScroll;
18
+ export declare function SetInputTarget(id: number, label: string): Messages.SetInputTarget;
19
+ export declare function SetInputValue(id: number, value: string, mask: number): Messages.SetInputValue;
20
+ export declare function SetInputChecked(id: number, checked: boolean): Messages.SetInputChecked;
21
+ export declare function MouseMove(x: number, y: number): Messages.MouseMove;
22
+ export declare function ConsoleLog(level: string, value: string): Messages.ConsoleLog;
23
+ export declare function PageLoadTiming(requestStart: number, responseStart: number, responseEnd: number, domContentLoadedEventStart: number, domContentLoadedEventEnd: number, loadEventStart: number, loadEventEnd: number, firstPaint: number, firstContentfulPaint: number): Messages.PageLoadTiming;
24
+ export declare function PageRenderTiming(speedIndex: number, visuallyComplete: number, timeToInteractive: number): Messages.PageRenderTiming;
25
+ export declare function JSException(name: string, message: string, payload: string): Messages.JSException;
26
+ export declare function RawCustomEvent(name: string, payload: string): Messages.RawCustomEvent;
27
+ export declare function UserID(id: string): Messages.UserID;
28
+ export declare function UserAnonymousID(id: string): Messages.UserAnonymousID;
29
+ export declare function Metadata(key: string, value: string): Messages.Metadata;
30
+ export declare function CSSInsertRule(id: number, rule: string, index: number): Messages.CSSInsertRule;
31
+ export declare function CSSDeleteRule(id: number, index: number): Messages.CSSDeleteRule;
32
+ export declare function Fetch(method: string, url: string, request: string, response: string, status: number, timestamp: number, duration: number): Messages.Fetch;
33
+ export declare function Profiler(name: string, duration: number, args: string, result: string): Messages.Profiler;
34
+ export declare function OTable(key: string, value: string): Messages.OTable;
35
+ export declare function StateAction(type: string): Messages.StateAction;
36
+ export declare function Redux(action: string, state: string, duration: number): Messages.Redux;
37
+ export declare function Vuex(mutation: string, state: string): Messages.Vuex;
38
+ export declare function MobX(type: string, payload: string): Messages.MobX;
39
+ export declare function NgRx(action: string, state: string, duration: number): Messages.NgRx;
40
+ export declare function GraphQL(operationKind: string, operationName: string, variables: string, response: string): Messages.GraphQL;
41
+ export declare function PerformanceTrack(frames: number, ticks: number, totalJSHeapSize: number, usedJSHeapSize: number): Messages.PerformanceTrack;
42
+ export declare function ResourceTiming(timestamp: number, duration: number, ttfb: number, headerSize: number, encodedBodySize: number, decodedBodySize: number, url: string, initiator: string): Messages.ResourceTiming;
43
+ export declare function ConnectionInformation(downlink: number, type: string): Messages.ConnectionInformation;
44
+ export declare function SetPageVisibility(hidden: boolean): Messages.SetPageVisibility;
45
+ export declare function LongTask(timestamp: number, duration: number, context: number, containerType: number, containerSrc: string, containerId: string, containerName: string): Messages.LongTask;
46
+ export declare function SetNodeAttributeURLBased(id: number, name: string, value: string, baseURL: string): Messages.SetNodeAttributeURLBased;
47
+ export declare function SetCSSDataURLBased(id: number, data: string, baseURL: string): Messages.SetCSSDataURLBased;
48
+ export declare function TechnicalInfo(type: string, value: string): Messages.TechnicalInfo;
49
+ export declare function CustomIssue(name: string, payload: string): Messages.CustomIssue;
50
+ export declare function CSSInsertRuleURLBased(id: number, rule: string, index: number, baseURL: string): Messages.CSSInsertRuleURLBased;
51
+ export declare function MouseClick(id: number, hesitationTime: number, label: string, selector: string): Messages.MouseClick;
52
+ export declare function CreateIFrameDocument(frameID: number, id: number): Messages.CreateIFrameDocument;
@@ -0,0 +1,57 @@
1
+ import * as Messages from '../common/messages.gen.js';
2
+ export { default } from '../common/messages.gen.js';
3
+ export declare function BatchMetadata(version: number, pageNo: number, firstIndex: number, timestamp: number, location: string): Messages.BatchMetadata;
4
+ export declare function PartitionedMessage(partNo: number, partTotal: number): Messages.PartitionedMessage;
5
+ export declare function Timestamp(timestamp: number): Messages.Timestamp;
6
+ export declare function SetPageLocation(url: string, referrer: string, navigationStart: number): Messages.SetPageLocation;
7
+ export declare function SetViewportSize(width: number, height: number): Messages.SetViewportSize;
8
+ export declare function SetViewportScroll(x: number, y: number): Messages.SetViewportScroll;
9
+ export declare function CreateDocument(): Messages.CreateDocument;
10
+ export declare function CreateElementNode(id: number, parentID: number, index: number, tag: string, svg: boolean): Messages.CreateElementNode;
11
+ export declare function CreateTextNode(id: number, parentID: number, index: number): Messages.CreateTextNode;
12
+ export declare function MoveNode(id: number, parentID: number, index: number): Messages.MoveNode;
13
+ export declare function RemoveNode(id: number): Messages.RemoveNode;
14
+ export declare function SetNodeAttribute(id: number, name: string, value: string): Messages.SetNodeAttribute;
15
+ export declare function RemoveNodeAttribute(id: number, name: string): Messages.RemoveNodeAttribute;
16
+ export declare function SetNodeData(id: number, data: string): Messages.SetNodeData;
17
+ export declare function SetNodeScroll(id: number, x: number, y: number): Messages.SetNodeScroll;
18
+ export declare function SetInputTarget(id: number, label: string): Messages.SetInputTarget;
19
+ export declare function SetInputValue(id: number, value: string, mask: number): Messages.SetInputValue;
20
+ export declare function SetInputChecked(id: number, checked: boolean): Messages.SetInputChecked;
21
+ export declare function MouseMove(x: number, y: number): Messages.MouseMove;
22
+ export declare function ConsoleLog(level: string, value: string): Messages.ConsoleLog;
23
+ export declare function PageLoadTiming(requestStart: number, responseStart: number, responseEnd: number, domContentLoadedEventStart: number, domContentLoadedEventEnd: number, loadEventStart: number, loadEventEnd: number, firstPaint: number, firstContentfulPaint: number): Messages.PageLoadTiming;
24
+ export declare function PageRenderTiming(speedIndex: number, visuallyComplete: number, timeToInteractive: number): Messages.PageRenderTiming;
25
+ export declare function JSException(name: string, message: string, payload: string): Messages.JSException;
26
+ export declare function RawCustomEvent(name: string, payload: string): Messages.RawCustomEvent;
27
+ export declare function UserID(id: string): Messages.UserID;
28
+ export declare function UserAnonymousID(id: string): Messages.UserAnonymousID;
29
+ export declare function Metadata(key: string, value: string): Messages.Metadata;
30
+ export declare function CSSInsertRule(id: number, rule: string, index: number): Messages.CSSInsertRule;
31
+ export declare function CSSDeleteRule(id: number, index: number): Messages.CSSDeleteRule;
32
+ export declare function Fetch(method: string, url: string, request: string, response: string, status: number, timestamp: number, duration: number): Messages.Fetch;
33
+ export declare function Profiler(name: string, duration: number, args: string, result: string): Messages.Profiler;
34
+ export declare function OTable(key: string, value: string): Messages.OTable;
35
+ export declare function StateAction(type: string): Messages.StateAction;
36
+ export declare function Redux(action: string, state: string, duration: number): Messages.Redux;
37
+ export declare function Vuex(mutation: string, state: string): Messages.Vuex;
38
+ export declare function MobX(type: string, payload: string): Messages.MobX;
39
+ export declare function NgRx(action: string, state: string, duration: number): Messages.NgRx;
40
+ export declare function GraphQL(operationKind: string, operationName: string, variables: string, response: string): Messages.GraphQL;
41
+ export declare function PerformanceTrack(frames: number, ticks: number, totalJSHeapSize: number, usedJSHeapSize: number): Messages.PerformanceTrack;
42
+ export declare function ResourceTiming(timestamp: number, duration: number, ttfb: number, headerSize: number, encodedBodySize: number, decodedBodySize: number, url: string, initiator: string): Messages.ResourceTiming;
43
+ export declare function ConnectionInformation(downlink: number, type: string): Messages.ConnectionInformation;
44
+ export declare function SetPageVisibility(hidden: boolean): Messages.SetPageVisibility;
45
+ export declare function LongTask(timestamp: number, duration: number, context: number, containerType: number, containerSrc: string, containerId: string, containerName: string): Messages.LongTask;
46
+ export declare function SetNodeAttributeURLBased(id: number, name: string, value: string, baseURL: string): Messages.SetNodeAttributeURLBased;
47
+ export declare function SetCSSDataURLBased(id: number, data: string, baseURL: string): Messages.SetCSSDataURLBased;
48
+ export declare function TechnicalInfo(type: string, value: string): Messages.TechnicalInfo;
49
+ export declare function CustomIssue(name: string, payload: string): Messages.CustomIssue;
50
+ export declare function CSSInsertRuleURLBased(id: number, rule: string, index: number, baseURL: string): Messages.CSSInsertRuleURLBased;
51
+ export declare function MouseClick(id: number, hesitationTime: number, label: string, selector: string): Messages.MouseClick;
52
+ export declare function CreateIFrameDocument(frameID: number, id: number): Messages.CreateIFrameDocument;
53
+ export declare function AdoptedSSReplaceURLBased(sheetID: number, text: string, baseURL: string): Messages.AdoptedSSReplaceURLBased;
54
+ export declare function AdoptedSSInsertRuleURLBased(sheetID: number, rule: string, index: number, baseURL: string): Messages.AdoptedSSInsertRuleURLBased;
55
+ export declare function AdoptedSSDeleteRule(sheetID: number, index: number): Messages.AdoptedSSDeleteRule;
56
+ export declare function AdoptedSSAddOwner(sheetID: number, id: number): Messages.AdoptedSSAddOwner;
57
+ export declare function AdoptedSSRemoveOwner(sheetID: number, id: number): Messages.AdoptedSSRemoveOwner;