@openreplay/tracker 3.6.1 → 3.6.5

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 (90) hide show
  1. package/.eslintignore +1 -1
  2. package/LICENSE +1 -1
  3. package/cjs/app/guards.d.ts +1 -2
  4. package/cjs/app/guards.js +1 -5
  5. package/cjs/app/index.d.ts +13 -16
  6. package/cjs/app/index.js +45 -47
  7. package/cjs/app/nodes.d.ts +1 -1
  8. package/cjs/app/nodes.js +0 -2
  9. package/cjs/app/observer/iframe_observer.js +2 -2
  10. package/cjs/app/observer/observer.js +13 -13
  11. package/cjs/app/observer/shadow_root_observer.js +2 -2
  12. package/cjs/app/observer/top_observer.d.ts +0 -11
  13. package/cjs/app/observer/top_observer.js +12 -46
  14. package/cjs/app/session.d.ts +0 -6
  15. package/cjs/app/session.js +0 -46
  16. package/cjs/common/messages.d.ts +444 -0
  17. package/cjs/common/messages.js +743 -0
  18. package/cjs/common/types.d.ts +9 -0
  19. package/cjs/common/{interaction.js → types.js} +0 -0
  20. package/cjs/common/{interaction.d.ts → webworker.d.ts} +3 -3
  21. package/cjs/common/{messages.gen.js → webworker.js} +0 -1
  22. package/cjs/index.d.ts +2 -2
  23. package/cjs/index.js +9 -14
  24. package/cjs/modules/connection.js +2 -2
  25. package/cjs/modules/console.js +20 -6
  26. package/cjs/modules/cssrules.js +12 -16
  27. package/cjs/modules/exception.d.ts +2 -2
  28. package/cjs/modules/exception.js +12 -16
  29. package/cjs/modules/img.js +21 -31
  30. package/cjs/modules/input.js +6 -6
  31. package/cjs/modules/longtasks.d.ts +2 -0
  32. package/cjs/modules/longtasks.js +34 -0
  33. package/cjs/modules/mouse.js +33 -42
  34. package/cjs/modules/performance.js +2 -2
  35. package/cjs/modules/scroll.js +7 -16
  36. package/cjs/modules/timing.js +4 -4
  37. package/cjs/modules/viewport.js +4 -4
  38. package/lib/app/guards.d.ts +1 -2
  39. package/lib/app/guards.js +0 -3
  40. package/lib/app/index.d.ts +13 -16
  41. package/lib/app/index.js +46 -48
  42. package/lib/app/nodes.d.ts +1 -1
  43. package/lib/app/nodes.js +0 -2
  44. package/lib/app/observer/iframe_observer.js +1 -1
  45. package/lib/app/observer/observer.js +12 -12
  46. package/lib/app/observer/shadow_root_observer.js +1 -1
  47. package/lib/app/observer/top_observer.d.ts +0 -11
  48. package/lib/app/observer/top_observer.js +12 -46
  49. package/lib/app/session.d.ts +0 -6
  50. package/lib/app/session.js +0 -46
  51. package/lib/common/messages.d.ts +444 -0
  52. package/lib/common/messages.js +739 -0
  53. package/lib/common/tsconfig.tsbuildinfo +1 -1
  54. package/lib/common/types.d.ts +9 -0
  55. package/lib/common/{interaction.js → types.js} +0 -0
  56. package/lib/common/{interaction.d.ts → webworker.d.ts} +3 -3
  57. package/lib/common/webworker.js +1 -0
  58. package/lib/index.d.ts +2 -2
  59. package/lib/index.js +9 -14
  60. package/lib/modules/connection.js +2 -2
  61. package/lib/modules/console.js +20 -6
  62. package/lib/modules/cssrules.js +12 -16
  63. package/lib/modules/exception.d.ts +2 -2
  64. package/lib/modules/exception.js +12 -16
  65. package/lib/modules/img.js +21 -31
  66. package/lib/modules/input.js +6 -6
  67. package/lib/modules/longtasks.d.ts +2 -0
  68. package/lib/modules/longtasks.js +31 -0
  69. package/lib/modules/mouse.js +34 -43
  70. package/lib/modules/performance.js +2 -2
  71. package/lib/modules/scroll.js +8 -17
  72. package/lib/modules/timing.js +4 -4
  73. package/lib/modules/viewport.js +4 -4
  74. package/package.json +4 -3
  75. package/.prettierignore +0 -1
  76. package/cjs/app/messages.d.ts +0 -52
  77. package/cjs/app/messages.gen.d.ts +0 -57
  78. package/cjs/app/messages.gen.js +0 -493
  79. package/cjs/app/messages.js +0 -234
  80. package/cjs/common/messages.gen.d.ts +0 -382
  81. package/cjs/modules/adoptedStyleSheets.d.ts +0 -2
  82. package/cjs/modules/adoptedStyleSheets.js +0 -127
  83. package/lib/app/messages.d.ts +0 -52
  84. package/lib/app/messages.gen.d.ts +0 -57
  85. package/lib/app/messages.gen.js +0 -434
  86. package/lib/app/messages.js +0 -181
  87. package/lib/common/messages.gen.d.ts +0 -382
  88. package/lib/common/messages.gen.js +0 -2
  89. package/lib/modules/adoptedStyleSheets.d.ts +0 -2
  90. package/lib/modules/adoptedStyleSheets.js +0 -124
package/.eslintignore CHANGED
@@ -5,4 +5,4 @@ cjs
5
5
  build
6
6
  .cache
7
7
  .eslintrc.cjs
8
- *.gen.ts
8
+ src/common/messages.ts
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2022 Asayer, Inc
1
+ Copyright (c) 2021 OpenReplay.com <support@openreplay.com>
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,8 +1,7 @@
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 isDocument(node: Node): node is Document;
5
- export declare function isRootNode(node: Node): node is Document | DocumentFragment;
4
+ export declare function isRootNode(node: Node): boolean;
6
5
  declare type TagTypeMap = {
7
6
  HTML: HTMLHtmlElement;
8
7
  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.isDocument = exports.isTextNode = exports.isElementNode = exports.isSVGElement = void 0;
3
+ exports.hasTag = exports.isRootNode = 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,10 +13,6 @@ 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;
20
16
  function isRootNode(node) {
21
17
  return node.nodeType === Node.DOCUMENT_NODE || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
22
18
  }
@@ -1,6 +1,5 @@
1
- import type Message from './messages.gen.js';
1
+ import type Message from '../common/messages.js';
2
2
  import Nodes from './nodes.js';
3
- import Observer from './observer/top_observer.js';
4
3
  import Sanitizer from './sanitizer.js';
5
4
  import Ticker from './ticker.js';
6
5
  import Logger from './logger.js';
@@ -8,13 +7,11 @@ import Session from './session.js';
8
7
  import type { Options as ObserverOptions } from './observer/top_observer.js';
9
8
  import type { Options as SanitizerOptions } from './sanitizer.js';
10
9
  import type { Options as LoggerOptions } from './logger.js';
11
- import type { Options as SessOptions } from './session.js';
12
- import type { Options as WebworkerOptions } from '../common/interaction.js';
10
+ import type { Options as WebworkerOptions } from '../common/webworker.js';
13
11
  export interface StartOptions {
14
12
  userID?: string;
15
13
  metadata?: Record<string, string>;
16
14
  forceNew?: boolean;
17
- sessionHash?: string;
18
15
  }
19
16
  interface OnStartInfo {
20
17
  sessionID: string;
@@ -37,9 +34,9 @@ declare type CommitCallback = (messages: Array<Message>) => void;
37
34
  declare type AppOptions = {
38
35
  revID: string;
39
36
  node_id: string;
40
- session_reset_key: string;
41
37
  session_token_key: string;
42
38
  session_pageno_key: string;
39
+ session_reset_key: string;
43
40
  local_uuid_key: string;
44
41
  ingestPoint: string;
45
42
  resourceBaseHref: string | null;
@@ -47,10 +44,10 @@ declare type AppOptions = {
47
44
  __is_snippet: boolean;
48
45
  __debug_report_edp: string | null;
49
46
  __debug__?: LoggerOptions;
50
- localStorage: Storage | null;
51
- sessionStorage: Storage | null;
47
+ localStorage: Storage;
48
+ sessionStorage: Storage;
52
49
  onStart?: StartCallback;
53
- } & WebworkerOptions & SessOptions;
50
+ } & WebworkerOptions;
54
51
  export declare type Options = AppOptions & ObserverOptions & SanitizerOptions;
55
52
  export declare const DEFAULT_INGEST_POINT = "https://api.openreplay.com/ingest";
56
53
  export default class App {
@@ -64,7 +61,7 @@ export default class App {
64
61
  readonly localStorage: Storage;
65
62
  readonly sessionStorage: Storage;
66
63
  private readonly messages;
67
- readonly observer: Observer;
64
+ private readonly observer;
68
65
  private readonly startCallbacks;
69
66
  private readonly stopCallbacks;
70
67
  private readonly commitCallbacks;
@@ -73,27 +70,27 @@ export default class App {
73
70
  private activityState;
74
71
  private readonly version;
75
72
  private readonly worker?;
76
- constructor(projectKey: string, sessionToken: string | undefined, options: Partial<Options>);
73
+ constructor(projectKey: string, sessionToken: string | null | undefined, options: Partial<Options>);
77
74
  private _debug;
78
75
  send(message: Message, urgent?: boolean): void;
79
76
  private commit;
80
77
  safe<T extends (...args: any[]) => void>(fn: T): T;
81
78
  attachCommitCallback(cb: CommitCallback): void;
82
- attachStartCallback(cb: StartCallback, useSafe?: boolean): void;
83
- attachStopCallback(cb: () => any, useSafe?: boolean): void;
79
+ attachStartCallback(cb: StartCallback): void;
80
+ attachStopCallback(cb: () => any): void;
84
81
  attachEventListener(target: EventTarget, type: string, listener: EventListener, useSafe?: boolean, useCapture?: boolean): void;
85
82
  checkRequiredVersion(version: string): boolean;
86
- private getTrackerInfo;
83
+ private getStartInfo;
87
84
  getSessionInfo(): {
88
85
  userUUID: string | null;
89
86
  projectKey: string;
90
87
  revID: string;
88
+ timestamp: number;
91
89
  trackerVersion: string;
92
90
  isSnippet: boolean;
93
91
  sessionID: string | undefined;
94
92
  metadata: Record<string, string>;
95
93
  userID: string | null;
96
- timestamp: number;
97
94
  projectID?: string | undefined;
98
95
  };
99
96
  getSessionToken(): string | undefined;
@@ -108,7 +105,7 @@ export default class App {
108
105
  resetNextPageSession(flag: boolean): void;
109
106
  private _start;
110
107
  start(options?: StartOptions): Promise<StartPromiseReturn>;
111
- stop(stopWorker?: boolean): void;
108
+ stop(calledFromAPI?: boolean, restarting?: boolean): void;
112
109
  restart(): void;
113
110
  }
114
111
  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_gen_js_1 = require("./messages.gen.js");
4
+ const messages_js_1 = require("../common/messages.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");
@@ -32,7 +32,7 @@ class App {
32
32
  this.stopCallbacks = [];
33
33
  this.commitCallbacks = [];
34
34
  this.activityState = ActivityState.NotActive;
35
- this.version = '3.6.1'; // TODO: version compatability check inside each plugin.
35
+ this.version = '3.6.4'; // TODO: version compatability check inside each plugin.
36
36
  this.projectKey = projectKey;
37
37
  this.options = Object.assign({
38
38
  revID: '',
@@ -46,8 +46,8 @@ class App {
46
46
  verbose: false,
47
47
  __is_snippet: false,
48
48
  __debug_report_edp: null,
49
- localStorage: window === null || window === void 0 ? void 0 : window.localStorage,
50
- sessionStorage: window === null || window === void 0 ? void 0 : window.sessionStorage,
49
+ localStorage: window.localStorage,
50
+ sessionStorage: window.sessionStorage,
51
51
  }, options);
52
52
  this.revID = this.options.revID;
53
53
  this.sanitizer = new sanitizer_js_1.default(this, options);
@@ -57,24 +57,23 @@ class App {
57
57
  this.ticker.attach(() => this.commit());
58
58
  this.debug = new logger_js_1.default(this.options.__debug__);
59
59
  this.notify = new logger_js_1.default(this.options.verbose ? logger_js_1.LogLevel.Warnings : logger_js_1.LogLevel.Silent);
60
- this.localStorage = this.options.localStorage || window.localStorage;
61
- this.sessionStorage = this.options.sessionStorage || window.sessionStorage;
62
60
  this.session = new session_js_1.default(this, this.options);
63
61
  this.session.attachUpdateCallback(({ userID, metadata }) => {
64
62
  if (userID != null) {
65
63
  // TODO: nullable userID
66
- this.send((0, messages_gen_js_1.UserID)(userID));
64
+ this.send(new messages_js_1.UserID(userID));
67
65
  }
68
66
  if (metadata != null) {
69
- Object.entries(metadata).forEach(([key, value]) => this.send((0, messages_gen_js_1.Metadata)(key, value)));
67
+ Object.entries(metadata).forEach(([key, value]) => this.send(new messages_js_1.Metadata(key, value)));
70
68
  }
71
69
  });
72
- // @depricated (use sessionHash on start instead)
70
+ this.localStorage = this.options.localStorage;
71
+ this.sessionStorage = this.options.sessionStorage;
73
72
  if (sessionToken != null) {
74
- this.session.applySessionHash(sessionToken);
73
+ this.sessionStorage.setItem(this.options.session_token_key, sessionToken);
75
74
  }
76
75
  try {
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' })));
76
+ 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){for(t instanceof e&&(this.timestamp=t.timestamp);!this.write(t);){if(this.finaliseBatch(),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' })));
78
77
  this.worker.onerror = (e) => {
79
78
  this._debug('webworker_error', e);
80
79
  };
@@ -131,7 +130,7 @@ class App {
131
130
  }
132
131
  commit() {
133
132
  if (this.worker && this.messages.length) {
134
- this.messages.unshift((0, messages_gen_js_1.Timestamp)((0, utils_js_1.timestamp)()));
133
+ this.messages.unshift(new messages_js_1.Timestamp((0, utils_js_1.timestamp)()));
135
134
  this.worker.postMessage(this.messages);
136
135
  this.commitCallbacks.forEach((cb) => cb(this.messages));
137
136
  this.messages.length = 0;
@@ -145,7 +144,7 @@ class App {
145
144
  }
146
145
  catch (e) {
147
146
  app._debug('safe_fn_call', e);
148
- // time: now(),
147
+ // time: timestamp(),
149
148
  // name: e.name,
150
149
  // message: e.message,
151
150
  // stack: e.stack
@@ -153,28 +152,20 @@ class App {
153
152
  }; // TODO: correct typing
154
153
  }
155
154
  attachCommitCallback(cb) {
156
- // TODO!: what if start callback added when activityState === Active ?
157
- // For example - attachEventListener() called during dynamic <iframe> appearance
158
155
  this.commitCallbacks.push(cb);
159
156
  }
160
- attachStartCallback(cb, useSafe = false) {
161
- if (useSafe) {
162
- cb = this.safe(cb);
163
- }
157
+ attachStartCallback(cb) {
164
158
  this.startCallbacks.push(cb);
165
159
  }
166
- attachStopCallback(cb, useSafe = false) {
167
- if (useSafe) {
168
- cb = this.safe(cb);
169
- }
160
+ attachStopCallback(cb) {
170
161
  this.stopCallbacks.push(cb);
171
162
  }
172
163
  attachEventListener(target, type, listener, useSafe = true, useCapture = true) {
173
164
  if (useSafe) {
174
165
  listener = this.safe(listener);
175
166
  }
176
- this.attachStartCallback(() => target.addEventListener(type, listener, useCapture), useSafe);
177
- this.attachStopCallback(() => target.removeEventListener(type, listener, useCapture), useSafe);
167
+ this.attachStartCallback(() => target.addEventListener(type, listener, useCapture));
168
+ this.attachStopCallback(() => target.removeEventListener(type, listener, useCapture));
178
169
  }
179
170
  // TODO: full correct semantic
180
171
  checkRequiredVersion(version) {
@@ -193,20 +184,24 @@ class App {
193
184
  }
194
185
  return true;
195
186
  }
196
- getTrackerInfo() {
187
+ getStartInfo() {
197
188
  return {
198
189
  userUUID: this.localStorage.getItem(this.options.local_uuid_key),
199
190
  projectKey: this.projectKey,
200
191
  revID: this.revID,
192
+ timestamp: (0, utils_js_1.timestamp)(),
201
193
  trackerVersion: this.version,
202
194
  isSnippet: this.options.__is_snippet,
203
195
  };
204
196
  }
205
197
  getSessionInfo() {
206
- return Object.assign(Object.assign({}, this.session.getInfo()), this.getTrackerInfo());
198
+ return Object.assign(Object.assign({}, this.session.getInfo()), this.getStartInfo());
207
199
  }
208
200
  getSessionToken() {
209
- return this.session.getSessionToken();
201
+ const token = this.sessionStorage.getItem(this.options.session_token_key);
202
+ if (token !== null) {
203
+ return token;
204
+ }
210
205
  }
211
206
  getSessionID() {
212
207
  return this.session.getInfo().sessionID || undefined;
@@ -231,7 +226,7 @@ class App {
231
226
  return this.options.resourceBaseHref;
232
227
  }
233
228
  else if (typeof this.options.resourceBaseHref === 'object') {
234
- //TODO: switch between types
229
+ //switch between types
235
230
  }
236
231
  if (document.baseURI) {
237
232
  return document.baseURI;
@@ -268,16 +263,19 @@ class App {
268
263
  return Promise.resolve(UnsuccessfulStart('OpenReplay: trying to call `start()` on the instance that has been started already.'));
269
264
  }
270
265
  this.activityState = ActivityState.Starting;
271
- if (startOpts.sessionHash) {
272
- this.session.applySessionHash(startOpts.sessionHash);
266
+ let pageNo = 0;
267
+ const pageNoStr = this.sessionStorage.getItem(this.options.session_pageno_key);
268
+ if (pageNoStr != null) {
269
+ pageNo = parseInt(pageNoStr);
270
+ pageNo++;
273
271
  }
274
- const timestamp = (0, utils_js_1.timestamp)();
272
+ this.sessionStorage.setItem(this.options.session_pageno_key, pageNo.toString());
273
+ const startInfo = this.getStartInfo();
275
274
  const startWorkerMsg = {
276
275
  type: 'start',
277
- pageNo: this.session.incPageNo(),
276
+ pageNo,
278
277
  ingestPoint: this.options.ingestPoint,
279
- timestamp,
280
- url: document.URL,
278
+ timestamp: startInfo.timestamp,
281
279
  connAttemptCount: this.options.connAttemptCount,
282
280
  connAttemptGap: this.options.connAttemptGap,
283
281
  };
@@ -297,7 +295,7 @@ class App {
297
295
  headers: {
298
296
  'Content-Type': 'application/json',
299
297
  },
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,
298
+ 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,
301
299
  jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit, reset: startOpts.forceNew || sReset !== null })),
302
300
  })
303
301
  .then((r) => {
@@ -316,29 +314,26 @@ class App {
316
314
  if (!this.worker) {
317
315
  return Promise.reject('no worker found after start request (this might not happen)');
318
316
  }
319
- const { token, userUUID, sessionID, projectID, beaconSizeLimit, startTimestamp, // real startTS, derived from sessionID
320
- } = r;
317
+ const { token, userUUID, sessionID, beaconSizeLimit } = r;
321
318
  if (typeof token !== 'string' ||
322
319
  typeof userUUID !== 'string' ||
323
- //typeof startTimestamp !== 'number' ||
324
- //typeof sessionID !== 'string' ||
325
320
  (typeof beaconSizeLimit !== 'number' && typeof beaconSizeLimit !== 'undefined')) {
326
321
  return Promise.reject(`Incorrect server response: ${JSON.stringify(r)}`);
327
322
  }
328
- this.session.setSessionToken(token);
323
+ this.sessionStorage.setItem(this.options.session_token_key, token);
329
324
  this.localStorage.setItem(this.options.local_uuid_key, userUUID);
330
- this.session.update({ sessionID, timestamp: startTimestamp || timestamp, projectID }); // TODO: no no-explicit 'any'
325
+ this.session.update({ sessionID }); // TODO: no no-explicit 'any'
331
326
  const startWorkerMsg = {
332
327
  type: 'auth',
333
328
  token,
334
329
  beaconSizeLimit,
335
330
  };
336
331
  this.worker.postMessage(startWorkerMsg);
332
+ this.activityState = ActivityState.Active;
337
333
  const onStartInfo = { sessionToken: token, userUUID, sessionID };
338
334
  this.startCallbacks.forEach((cb) => cb(onStartInfo)); // TODO: start as early as possible (before receiving the token)
339
335
  this.observer.observe();
340
336
  this.ticker.start();
341
- this.activityState = ActivityState.Active;
342
337
  this.notify.log('OpenReplay tracking started.');
343
338
  // get rid of onStart ?
344
339
  if (typeof this.options.onStart === 'function') {
@@ -347,8 +342,8 @@ class App {
347
342
  return SuccessfulStart(onStartInfo);
348
343
  })
349
344
  .catch((reason) => {
345
+ this.sessionStorage.removeItem(this.options.session_token_key);
350
346
  this.stop();
351
- this.session.reset();
352
347
  if (reason === CANCELED) {
353
348
  return UnsuccessfulStart(CANCELED);
354
349
  }
@@ -373,7 +368,7 @@ class App {
373
368
  });
374
369
  }
375
370
  }
376
- stop(stopWorker = true) {
371
+ stop(calledFromAPI = false, restarting = false) {
377
372
  if (this.activityState !== ActivityState.NotActive) {
378
373
  try {
379
374
  this.sanitizer.clear();
@@ -381,8 +376,11 @@ class App {
381
376
  this.nodes.clear();
382
377
  this.ticker.stop();
383
378
  this.stopCallbacks.forEach((cb) => cb());
379
+ if (calledFromAPI) {
380
+ this.session.reset();
381
+ }
384
382
  this.notify.log('OpenReplay tracking stopped.');
385
- if (this.worker && stopWorker) {
383
+ if (this.worker && !restarting) {
386
384
  this.worker.postMessage('stop');
387
385
  }
388
386
  }
@@ -392,7 +390,7 @@ class App {
392
390
  }
393
391
  }
394
392
  restart() {
395
- this.stop(false);
393
+ this.stop(false, true);
396
394
  this.start({ forceNew: false });
397
395
  }
398
396
  }
@@ -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): [/*id:*/ number, /*isNew:*/ boolean];
10
+ registerNode(node: Node): [id: number, isNew: boolean];
11
11
  unregisterNode(node: Node): number | undefined;
12
12
  cleanTree(): void;
13
13
  callNodeCallbacks(node: Node, isStart: boolean): void;
package/cjs/app/nodes.js CHANGED
@@ -7,11 +7,9 @@ class Nodes {
7
7
  this.nodeCallbacks = [];
8
8
  this.elementListeners = new Map();
9
9
  }
10
- // Attached once per Tracker instance
11
10
  attachNodeCallback(nodeCallback) {
12
11
  this.nodeCallbacks.push(nodeCallback);
13
12
  }
14
- // TODO: what is the difference with app.attachEventListener. can we use only one of those?
15
13
  attachElementListener(type, node, elementListener) {
16
14
  const id = this.getID(node);
17
15
  if (id === 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 messages_gen_js_1 = require("../messages.gen.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, messages_gen_js_1.CreateIFrameDocument)(hostID, docID));
18
+ this.app.send((0, messages_js_1.CreateIFrameDocument)(hostID, docID));
19
19
  });
20
20
  }
21
21
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const messages_gen_js_1 = require("../messages.gen.js");
3
+ const messages_js_1 = require("../../common/messages.js");
4
4
  const guards_js_1 = require("../guards.js");
5
5
  function isIgnored(node) {
6
6
  if ((0, guards_js_1.isTextNode)(node)) {
@@ -103,16 +103,16 @@ class Observer {
103
103
  name = name.substr(6);
104
104
  }
105
105
  if (value === null) {
106
- this.app.send((0, messages_gen_js_1.RemoveNodeAttribute)(id, name));
106
+ this.app.send(new messages_js_1.RemoveNodeAttribute(id, name));
107
107
  }
108
108
  else if (name === 'href') {
109
109
  if (value.length > 1e5) {
110
110
  value = '';
111
111
  }
112
- this.app.send((0, messages_gen_js_1.SetNodeAttributeURLBased)(id, name, value, this.app.getBaseHref()));
112
+ this.app.send(new messages_js_1.SetNodeAttributeURLBased(id, name, value, this.app.getBaseHref()));
113
113
  }
114
114
  else {
115
- this.app.send((0, messages_gen_js_1.SetNodeAttribute)(id, name, value));
115
+ this.app.send(new messages_js_1.SetNodeAttribute(id, name, value));
116
116
  }
117
117
  return;
118
118
  }
@@ -132,25 +132,25 @@ class Observer {
132
132
  return;
133
133
  }
134
134
  if (value === null) {
135
- this.app.send((0, messages_gen_js_1.RemoveNodeAttribute)(id, name));
135
+ this.app.send(new messages_js_1.RemoveNodeAttribute(id, name));
136
136
  return;
137
137
  }
138
138
  if (name === 'style' || (name === 'href' && (0, guards_js_1.hasTag)(node, 'LINK'))) {
139
- this.app.send((0, messages_gen_js_1.SetNodeAttributeURLBased)(id, name, value, this.app.getBaseHref()));
139
+ this.app.send(new messages_js_1.SetNodeAttributeURLBased(id, name, value, this.app.getBaseHref()));
140
140
  return;
141
141
  }
142
142
  if (name === 'href' || value.length > 1e5) {
143
143
  value = '';
144
144
  }
145
- this.app.send((0, messages_gen_js_1.SetNodeAttribute)(id, name, value));
145
+ this.app.send(new messages_js_1.SetNodeAttribute(id, name, value));
146
146
  }
147
147
  sendNodeData(id, parentElement, data) {
148
148
  if ((0, guards_js_1.hasTag)(parentElement, 'STYLE') || (0, guards_js_1.hasTag)(parentElement, 'style')) {
149
- this.app.send((0, messages_gen_js_1.SetCSSDataURLBased)(id, data, this.app.getBaseHref()));
149
+ this.app.send(new messages_js_1.SetCSSDataURLBased(id, data, this.app.getBaseHref()));
150
150
  return;
151
151
  }
152
152
  data = this.app.sanitizer.sanitize(id, data);
153
- this.app.send((0, messages_gen_js_1.SetNodeData)(id, data));
153
+ this.app.send(new messages_js_1.SetNodeData(id, data));
154
154
  }
155
155
  bindNode(node) {
156
156
  const [id, isNew] = this.app.nodes.registerNode(node);
@@ -181,7 +181,7 @@ class Observer {
181
181
  const id = this.app.nodes.unregisterNode(node);
182
182
  if (id !== undefined && this.recents.get(id) === RecentsType.Removed) {
183
183
  // Sending RemoveNode only for parent to maintain
184
- this.app.send((0, messages_gen_js_1.RemoveNode)(id));
184
+ this.app.send((0, messages_js_1.RemoveNode)(id));
185
185
  // Unregistering all the children in order to clear the memory
186
186
  const walker = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT + NodeFilter.SHOW_TEXT, {
187
187
  acceptNode: (node) => isIgnored(node) || this.app.nodes.getID(node) === undefined
@@ -258,7 +258,7 @@ class Observer {
258
258
  el.style.width = width + 'px';
259
259
  el.style.height = height + 'px';
260
260
  }
261
- this.app.send((0, messages_gen_js_1.CreateElementNode)(id, parentID, index, el.tagName, (0, guards_js_1.isSVGElement)(node)));
261
+ this.app.send(new messages_js_1.CreateElementNode(id, parentID, index, el.tagName, (0, guards_js_1.isSVGElement)(node)));
262
262
  }
263
263
  for (let i = 0; i < el.attributes.length; i++) {
264
264
  const attr = el.attributes[i];
@@ -267,13 +267,13 @@ class Observer {
267
267
  }
268
268
  else if ((0, guards_js_1.isTextNode)(node)) {
269
269
  // for text node id != 0, hence parentID !== undefined and parent is Element
270
- this.app.send((0, messages_gen_js_1.CreateTextNode)(id, parentID, index));
270
+ this.app.send(new messages_js_1.CreateTextNode(id, parentID, index));
271
271
  this.sendNodeData(id, parent, node.data);
272
272
  }
273
273
  return true;
274
274
  }
275
275
  if (recentsType === RecentsType.Removed && parentID !== undefined) {
276
- this.app.send((0, messages_gen_js_1.MoveNode)(id, parentID, index));
276
+ this.app.send(new messages_js_1.MoveNode(id, parentID, index));
277
277
  }
278
278
  const attr = this.attributesMap.get(id);
279
279
  if (attr !== 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 messages_gen_js_1 = require("../messages.gen.js");
4
+ const messages_js_1 = require("../../common/messages.js");
5
5
  class ShadowRootObserver extends observer_js_1.default {
6
6
  observe(el) {
7
7
  const shRoot = el.shadowRoot;
@@ -14,7 +14,7 @@ class ShadowRootObserver extends observer_js_1.default {
14
14
  console.log('OpenReplay: Shadow Root was not bound');
15
15
  return;
16
16
  }
17
- this.app.send((0, messages_gen_js_1.CreateIFrameDocument)(hostID, rootID));
17
+ this.app.send((0, messages_js_1.CreateIFrameDocument)(hostID, rootID));
18
18
  });
19
19
  }
20
20
  }
@@ -3,19 +3,9 @@ import App from '../index.js';
3
3
  export interface Options {
4
4
  captureIFrames: boolean;
5
5
  }
6
- declare type Context = Window & typeof globalThis;
7
- declare type ContextCallback = (context: Context) => void;
8
- declare type Offset = {
9
- top: number;
10
- left: number;
11
- };
12
6
  export default class TopObserver extends Observer {
13
7
  private readonly options;
14
8
  constructor(app: App, options: Partial<Options>);
15
- private readonly contextCallbacks;
16
- private readonly contextsSet;
17
- attachContextCallback(cb: ContextCallback): void;
18
- getDocumentOffset(doc: Document): Offset;
19
9
  private iframeObservers;
20
10
  private handleIframe;
21
11
  private shadowRootObservers;
@@ -23,4 +13,3 @@ export default class TopObserver extends Observer {
23
13
  observe(): void;
24
14
  disconnect(): void;
25
15
  }
26
- export {};