@openreplay/tracker 3.5.8 → 3.5.11

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 (69) hide show
  1. package/cjs/app/context.js +4 -2
  2. package/cjs/app/index.d.ts +12 -13
  3. package/cjs/app/index.js +23 -21
  4. package/cjs/app/observer/iframe_observer.js +2 -2
  5. package/cjs/app/observer/observer.js +13 -13
  6. package/cjs/app/observer/shadow_root_observer.js +2 -2
  7. package/cjs/app/observer/top_observer.js +2 -2
  8. package/cjs/app/session.js +3 -3
  9. package/cjs/{messages/index.d.ts → common/messages.d.ts} +2 -3
  10. package/cjs/{messages/index.js → common/messages.js} +0 -0
  11. package/cjs/common/types.d.ts +9 -0
  12. package/cjs/{messages/message.js → common/types.js} +0 -0
  13. package/cjs/common/webworker.d.ts +19 -0
  14. package/cjs/{messages → common}/webworker.js +0 -0
  15. package/cjs/index.d.ts +2 -2
  16. package/cjs/index.js +7 -7
  17. package/cjs/modules/connection.js +2 -2
  18. package/cjs/modules/console.js +2 -2
  19. package/cjs/modules/cssrules.js +4 -4
  20. package/cjs/modules/exception.d.ts +1 -1
  21. package/cjs/modules/exception.js +4 -4
  22. package/cjs/modules/img.js +7 -7
  23. package/cjs/modules/input.js +5 -5
  24. package/cjs/modules/longtasks.js +2 -2
  25. package/cjs/modules/mouse.js +3 -7
  26. package/cjs/modules/performance.js +2 -2
  27. package/cjs/modules/scroll.js +3 -3
  28. package/cjs/modules/timing.js +15 -18
  29. package/cjs/modules/viewport.js +4 -4
  30. package/lib/app/context.js +4 -2
  31. package/lib/app/index.d.ts +12 -13
  32. package/lib/app/index.js +22 -20
  33. package/lib/app/observer/iframe_observer.js +1 -1
  34. package/lib/app/observer/observer.js +1 -1
  35. package/lib/app/observer/shadow_root_observer.js +1 -1
  36. package/lib/app/observer/top_observer.js +1 -1
  37. package/lib/app/session.js +1 -1
  38. package/lib/{messages/index.d.ts → common/messages.d.ts} +2 -3
  39. package/lib/{messages/index.js → common/messages.js} +0 -0
  40. package/lib/common/tsconfig.tsbuildinfo +1 -0
  41. package/lib/common/types.d.ts +9 -0
  42. package/lib/{messages/message.js → common/types.js} +0 -0
  43. package/lib/common/webworker.d.ts +19 -0
  44. package/lib/{messages → common}/webworker.js +0 -0
  45. package/lib/index.d.ts +2 -2
  46. package/lib/index.js +4 -4
  47. package/lib/modules/connection.js +1 -1
  48. package/lib/modules/console.js +1 -1
  49. package/lib/modules/cssrules.js +1 -1
  50. package/lib/modules/exception.d.ts +1 -1
  51. package/lib/modules/exception.js +1 -1
  52. package/lib/modules/img.js +1 -1
  53. package/lib/modules/input.js +1 -1
  54. package/lib/modules/longtasks.js +1 -1
  55. package/lib/modules/mouse.js +1 -5
  56. package/lib/modules/performance.js +1 -1
  57. package/lib/modules/scroll.js +1 -1
  58. package/lib/modules/timing.js +13 -16
  59. package/lib/modules/viewport.js +1 -1
  60. package/package.json +1 -1
  61. package/cjs/messages/message.d.ts +0 -4
  62. package/cjs/messages/webworker.d.ts +0 -17
  63. package/cjs/messages/writer.d.ts +0 -15
  64. package/cjs/messages/writer.js +0 -115
  65. package/lib/messages/message.d.ts +0 -4
  66. package/lib/messages/tsconfig.tsbuildinfo +0 -1
  67. package/lib/messages/webworker.d.ts +0 -17
  68. package/lib/messages/writer.d.ts +0 -15
  69. package/lib/messages/writer.js +0 -112
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getExceptionMessageFromEvent = exports.getExceptionMessage = void 0;
4
- const index_js_1 = require("../messages/index.js");
4
+ const messages_js_1 = require("../common/messages.js");
5
5
  const error_stack_parser_1 = require("error-stack-parser");
6
6
  function getDefaultStack(e) {
7
7
  return [{
@@ -19,7 +19,7 @@ function getExceptionMessage(error, fallbackStack) {
19
19
  }
20
20
  catch (e) {
21
21
  }
22
- return new index_js_1.JSException(error.name, error.message, JSON.stringify(stack));
22
+ return new messages_js_1.JSException(error.name, error.message, JSON.stringify(stack));
23
23
  }
24
24
  exports.getExceptionMessage = getExceptionMessage;
25
25
  function getExceptionMessageFromEvent(e) {
@@ -33,7 +33,7 @@ function getExceptionMessageFromEvent(e) {
33
33
  name = 'Error';
34
34
  message = e.message;
35
35
  }
36
- return new index_js_1.JSException(name, message, JSON.stringify(getDefaultStack(e)));
36
+ return new messages_js_1.JSException(name, message, JSON.stringify(getDefaultStack(e)));
37
37
  }
38
38
  }
39
39
  else if ('PromiseRejectionEvent' in window && e instanceof PromiseRejectionEvent) {
@@ -48,7 +48,7 @@ function getExceptionMessageFromEvent(e) {
48
48
  catch (_) {
49
49
  message = String(e.reason);
50
50
  }
51
- return new index_js_1.JSException('Unhandled Promise Rejection', message, '[]');
51
+ return new messages_js_1.JSException('Unhandled Promise Rejection', message, '[]');
52
52
  }
53
53
  }
54
54
  return null;
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const utils_js_1 = require("../utils.js");
4
- const index_js_1 = require("../messages/index.js");
4
+ const messages_js_1 = require("../common/messages.js");
5
5
  const PLACEHOLDER_SRC = "https://static.openreplay.com/tracker/placeholder.jpeg";
6
6
  function default_1(app) {
7
7
  function sendPlaceholder(id, node) {
8
- app.send(new index_js_1.SetNodeAttribute(id, "src", PLACEHOLDER_SRC));
8
+ app.send(new messages_js_1.SetNodeAttribute(id, "src", PLACEHOLDER_SRC));
9
9
  const { width, height } = node.getBoundingClientRect();
10
10
  if (!node.hasAttribute("width")) {
11
- app.send(new index_js_1.SetNodeAttribute(id, "width", String(width)));
11
+ app.send(new messages_js_1.SetNodeAttribute(id, "width", String(width)));
12
12
  }
13
13
  if (!node.hasAttribute("height")) {
14
- app.send(new index_js_1.SetNodeAttribute(id, "height", String(height)));
14
+ app.send(new messages_js_1.SetNodeAttribute(id, "height", String(height)));
15
15
  }
16
16
  }
17
17
  const sendImgSrc = app.safe(function () {
@@ -25,14 +25,14 @@ function default_1(app) {
25
25
  }
26
26
  if (naturalWidth === 0 && naturalHeight === 0) {
27
27
  if (src != null && (0, utils_js_1.isURL)(src)) { // TODO: How about relative urls ? Src type is null sometimes.
28
- app.send(new index_js_1.ResourceTiming((0, utils_js_1.timestamp)(), 0, 0, 0, 0, 0, src, 'img'));
28
+ app.send(new messages_js_1.ResourceTiming((0, utils_js_1.timestamp)(), 0, 0, 0, 0, 0, src, 'img'));
29
29
  }
30
30
  }
31
31
  else if (src.length >= 1e5 || app.sanitizer.isMasked(id)) {
32
32
  sendPlaceholder(id, this);
33
33
  }
34
34
  else {
35
- app.send(new index_js_1.SetNodeAttributeURLBased(id, 'src', src, app.getBaseHref()));
35
+ app.send(new messages_js_1.SetNodeAttributeURLBased(id, 'src', src, app.getBaseHref()));
36
36
  }
37
37
  });
38
38
  const observer = new MutationObserver((mutations) => {
@@ -44,7 +44,7 @@ function default_1(app) {
44
44
  return;
45
45
  }
46
46
  const src = target.src;
47
- app.send(new index_js_1.SetNodeAttributeURLBased(id, 'src', src, app.getBaseHref()));
47
+ app.send(new messages_js_1.SetNodeAttributeURLBased(id, 'src', src, app.getBaseHref()));
48
48
  }
49
49
  }
50
50
  });
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getInputLabel = void 0;
4
4
  const utils_js_1 = require("../utils.js");
5
- const index_js_1 = require("../messages/index.js");
5
+ const messages_js_1 = require("../common/messages.js");
6
6
  function isTextEditable(node) {
7
7
  if (node instanceof HTMLTextAreaElement) {
8
8
  return true;
@@ -76,7 +76,7 @@ function default_1(app, opts) {
76
76
  function sendInputTarget(id, node) {
77
77
  const label = getInputLabel(node);
78
78
  if (label !== '') {
79
- app.send(new index_js_1.SetInputTarget(id, label));
79
+ app.send(new messages_js_1.SetInputTarget(id, label));
80
80
  }
81
81
  }
82
82
  function sendInputValue(id, node) {
@@ -103,7 +103,7 @@ function default_1(app, opts) {
103
103
  value = '';
104
104
  break;
105
105
  }
106
- app.send(new index_js_1.SetInputValue(id, value, mask));
106
+ app.send(new messages_js_1.SetInputValue(id, value, mask));
107
107
  }
108
108
  const inputValues = new Map();
109
109
  const checkableValues = new Map();
@@ -137,7 +137,7 @@ function default_1(app, opts) {
137
137
  }
138
138
  if (checked !== node.checked) {
139
139
  checkableValues.set(id, node.checked);
140
- app.send(new index_js_1.SetInputChecked(id, node.checked));
140
+ app.send(new messages_js_1.SetInputChecked(id, node.checked));
141
141
  }
142
142
  });
143
143
  });
@@ -161,7 +161,7 @@ function default_1(app, opts) {
161
161
  }
162
162
  if (isCheckable(node)) {
163
163
  checkableValues.set(id, node.checked);
164
- app.send(new index_js_1.SetInputChecked(id, node.checked));
164
+ app.send(new messages_js_1.SetInputChecked(id, node.checked));
165
165
  return;
166
166
  }
167
167
  }));
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_js_1 = require("../messages/index.js");
3
+ const messages_js_1 = require("../common/messages.js");
4
4
  ;
5
5
  ;
6
6
  function default_1(app) {
@@ -18,7 +18,7 @@ function default_1(app) {
18
18
  id = container.containerId;
19
19
  src = container.containerSrc;
20
20
  }
21
- app.send(new index_js_1.LongTask(entry.startTime + performance.timing.navigationStart, entry.duration, Math.max(contexts.indexOf(entry.name), 0), Math.max(containerTypes.indexOf(type), 0), name, id, src));
21
+ app.send(new messages_js_1.LongTask(entry.startTime + performance.timing.navigationStart, entry.duration, Math.max(contexts.indexOf(entry.name), 0), Math.max(containerTypes.indexOf(type), 0), name, id, src));
22
22
  }
23
23
  const observer = new PerformanceObserver((list) => list.getEntries().forEach(longTask));
24
24
  observer.observe({ entryTypes: ['longtask'] });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const utils_js_1 = require("../utils.js");
4
- const index_js_1 = require("../messages/index.js");
4
+ const messages_js_1 = require("../common/messages.js");
5
5
  const input_js_1 = require("./input.js");
6
6
  function _getSelector(target) {
7
7
  let el = target;
@@ -74,10 +74,6 @@ function _getTarget(target) {
74
74
  return target === document.documentElement ? null : target;
75
75
  }
76
76
  function default_1(app) {
77
- // const options: Options = Object.assign(
78
- // {},
79
- // opts,
80
- // );
81
77
  function getTargetLabel(target) {
82
78
  const dl = (0, utils_js_1.getLabelAttribute)(target);
83
79
  if (dl !== null) {
@@ -109,7 +105,7 @@ function default_1(app) {
109
105
  });
110
106
  const sendMouseMove = () => {
111
107
  if (mousePositionChanged) {
112
- app.send(new index_js_1.MouseMove(mousePositionX, mousePositionY));
108
+ app.send(new messages_js_1.MouseMove(mousePositionX, mousePositionY));
113
109
  mousePositionChanged = false;
114
110
  }
115
111
  };
@@ -137,7 +133,7 @@ function default_1(app) {
137
133
  const id = app.nodes.getID(target);
138
134
  if (id !== undefined) {
139
135
  sendMouseMove();
140
- app.send(new index_js_1.MouseClick(id, mouseTarget === target
136
+ app.send(new messages_js_1.MouseClick(id, mouseTarget === target
141
137
  ? Math.round(performance.now() - mouseTargetTime)
142
138
  : 0, getTargetLabel(target), getSelector(id, target)), true);
143
139
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.jsHeapSizeLimit = exports.deviceMemory = void 0;
4
4
  const utils_js_1 = require("../utils.js");
5
- const index_js_1 = require("../messages/index.js");
5
+ const messages_js_1 = require("../common/messages.js");
6
6
  const perf = utils_js_1.IN_BROWSER && 'performance' in window && 'memory' in performance // works in Chrome only
7
7
  ? performance
8
8
  : { memory: {} };
@@ -34,7 +34,7 @@ function default_1(app, opts) {
34
34
  if (frames === undefined || ticks === undefined) {
35
35
  return;
36
36
  }
37
- app.send(new index_js_1.PerformanceTrack(frames, ticks, perf.memory.totalJSHeapSize || 0, perf.memory.usedJSHeapSize || 0));
37
+ app.send(new messages_js_1.PerformanceTrack(frames, ticks, perf.memory.totalJSHeapSize || 0, perf.memory.usedJSHeapSize || 0));
38
38
  ticks = frames = document.hidden ? -1 : 0;
39
39
  };
40
40
  app.attachStartCallback(() => {
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_js_1 = require("../messages/index.js");
3
+ const messages_js_1 = require("../common/messages.js");
4
4
  function default_1(app) {
5
5
  let documentScroll = false;
6
6
  const nodeScroll = new Map();
7
- const sendSetViewportScroll = app.safe(() => app.send(new index_js_1.SetViewportScroll(window.pageXOffset ||
7
+ const sendSetViewportScroll = app.safe(() => app.send(new messages_js_1.SetViewportScroll(window.pageXOffset ||
8
8
  (document.documentElement && document.documentElement.scrollLeft) ||
9
9
  (document.body && document.body.scrollLeft) ||
10
10
  0, window.pageYOffset ||
@@ -14,7 +14,7 @@ function default_1(app) {
14
14
  const sendSetNodeScroll = app.safe((s, node) => {
15
15
  const id = app.nodes.getID(node);
16
16
  if (id !== undefined) {
17
- app.send(new index_js_1.SetNodeScroll(id, s[0], s[1]));
17
+ app.send(new messages_js_1.SetNodeScroll(id, s[0], s[1]));
18
18
  }
19
19
  });
20
20
  app.attachStartCallback(sendSetViewportScroll);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const utils_js_1 = require("../utils.js");
4
- const index_js_1 = require("../messages/index.js");
4
+ const messages_js_1 = require("../common/messages.js");
5
5
  function getPaintBlocks(resources) {
6
6
  const paintBlocks = [];
7
7
  const elements = document.getElementsByTagName('*');
@@ -70,18 +70,6 @@ function default_1(app, opts) {
70
70
  if (!options.captureResourceTimings) {
71
71
  return;
72
72
  } // Resources are necessary for all timings
73
- const mQueue = [];
74
- function sendOnStart(m) {
75
- if (app.active()) {
76
- app.send(m);
77
- }
78
- else {
79
- mQueue.push(m);
80
- }
81
- }
82
- app.attachStartCallback(function () {
83
- mQueue.forEach(m => app.send(m));
84
- });
85
73
  let resources = {};
86
74
  function resourceTiming(entry) {
87
75
  if (entry.duration < 0 || !(0, utils_js_1.isURL)(entry.name) || app.isServiceURL(entry.name))
@@ -89,15 +77,24 @@ function default_1(app, opts) {
89
77
  if (resources !== null) {
90
78
  resources[entry.name] = entry.startTime + entry.duration;
91
79
  }
92
- sendOnStart(new index_js_1.ResourceTiming(entry.startTime + performance.timing.navigationStart, entry.duration, entry.responseStart && entry.startTime
80
+ app.send(new messages_js_1.ResourceTiming(entry.startTime + performance.timing.navigationStart, entry.duration, entry.responseStart && entry.startTime
93
81
  ? entry.responseStart - entry.startTime
94
82
  : 0, entry.transferSize > entry.encodedBodySize
95
83
  ? entry.transferSize - entry.encodedBodySize
96
84
  : 0, entry.encodedBodySize || 0, entry.decodedBodySize || 0, entry.name, entry.initiatorType));
97
85
  }
98
86
  const observer = new PerformanceObserver((list) => list.getEntries().forEach(resourceTiming));
99
- performance.getEntriesByType('resource').forEach(resourceTiming);
100
- observer.observe({ entryTypes: ['resource'] });
87
+ let prevSessionID;
88
+ app.attachStartCallback(function ({ sessionID }) {
89
+ if (sessionID !== prevSessionID) { // Send past page resources on a newly started session
90
+ performance.getEntriesByType('resource').forEach(resourceTiming);
91
+ prevSessionID = sessionID;
92
+ }
93
+ observer.observe({ entryTypes: ['resource'] });
94
+ });
95
+ app.attachStopCallback(function () {
96
+ observer.disconnect();
97
+ });
101
98
  let firstPaint = 0, firstContentfulPaint = 0;
102
99
  if (options.capturePageLoadTimings) {
103
100
  let pageLoadTimingSent = false;
@@ -123,7 +120,7 @@ function default_1(app, opts) {
123
120
  if (performance.timing.loadEventEnd || performance.now() > 30000) {
124
121
  pageLoadTimingSent = true;
125
122
  const { navigationStart, requestStart, responseStart, responseEnd, domContentLoadedEventStart, domContentLoadedEventEnd, loadEventStart, loadEventEnd, } = performance.timing;
126
- app.send(new index_js_1.PageLoadTiming(requestStart - navigationStart || 0, responseStart - navigationStart || 0, responseEnd - navigationStart || 0, domContentLoadedEventStart - navigationStart || 0, domContentLoadedEventEnd - navigationStart || 0, loadEventStart - navigationStart || 0, loadEventEnd - navigationStart || 0, firstPaint, firstContentfulPaint));
123
+ app.send(new messages_js_1.PageLoadTiming(requestStart - navigationStart || 0, responseStart - navigationStart || 0, responseEnd - navigationStart || 0, domContentLoadedEventStart - navigationStart || 0, domContentLoadedEventEnd - navigationStart || 0, loadEventStart - navigationStart || 0, loadEventEnd - navigationStart || 0, firstPaint, firstContentfulPaint));
127
124
  }
128
125
  }, 30);
129
126
  }
@@ -160,7 +157,7 @@ function default_1(app, opts) {
160
157
  ? Math.max(interactiveWindowStartTime, firstContentfulPaint, performance.timing.domContentLoadedEventEnd -
161
158
  performance.timing.navigationStart || 0)
162
159
  : 0;
163
- app.send(new index_js_1.PageRenderTiming(speedIndex, firstContentfulPaint > visuallyComplete
160
+ app.send(new messages_js_1.PageRenderTiming(speedIndex, firstContentfulPaint > visuallyComplete
164
161
  ? firstContentfulPaint
165
162
  : visuallyComplete, timeToInteractive));
166
163
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_js_1 = require("../messages/index.js");
3
+ const messages_js_1 = require("../common/messages.js");
4
4
  function default_1(app) {
5
5
  let url, width, height;
6
6
  let navigationStart = performance.timing.navigationStart;
@@ -8,7 +8,7 @@ function default_1(app) {
8
8
  const { URL } = document;
9
9
  if (URL !== url) {
10
10
  url = URL;
11
- app.send(new index_js_1.SetPageLocation(url, document.referrer, navigationStart));
11
+ app.send(new messages_js_1.SetPageLocation(url, document.referrer, navigationStart));
12
12
  navigationStart = 0;
13
13
  }
14
14
  });
@@ -17,12 +17,12 @@ function default_1(app) {
17
17
  if (innerWidth !== width || innerHeight !== height) {
18
18
  width = innerWidth;
19
19
  height = innerHeight;
20
- app.send(new index_js_1.SetViewportSize(width, height));
20
+ app.send(new messages_js_1.SetViewportSize(width, height));
21
21
  }
22
22
  });
23
23
  const sendSetPageVisibility = document.hidden === undefined
24
24
  ? Function.prototype
25
- : app.safe(() => app.send(new index_js_1.SetPageVisibility(document.hidden)));
25
+ : app.safe(() => app.send(new messages_js_1.SetPageVisibility(document.hidden)));
26
26
  app.attachStartCallback(() => {
27
27
  url = '';
28
28
  width = height = -1;
@@ -1,5 +1,7 @@
1
1
  // TODO: we need a type expert here so we won't have to ignore the lines
2
2
  // TODO: use it everywhere (static function; export from which file? <-- global Window typing required)
3
+ // TODO: most efficient and common way
4
+ // Problem: on YouTube there is context[constr.name] undefined for constr=ShadowDom due to some minimisations
3
5
  export function isInstance(node, constr) {
4
6
  const doc = node.ownerDocument;
5
7
  if (!doc) { // null if Document
@@ -11,14 +13,14 @@ export function isInstance(node, constr) {
11
13
  doc.defaultView; // TODO: smart global typing for Window object
12
14
  while (context !== window) {
13
15
  // @ts-ignore
14
- if (node instanceof context[constr.name]) {
16
+ if (context[constr.name] && node instanceof context[constr.name]) {
15
17
  return true;
16
18
  }
17
19
  // @ts-ignore
18
20
  context = context.parent || window;
19
21
  }
20
22
  // @ts-ignore
21
- return node instanceof context[constr.name];
23
+ return context[constr.name] ? node instanceof context[constr.name] : node instanceof constr;
22
24
  }
23
25
  // TODO: ensure 1. it works in every cases (iframes/detached nodes) and 2. the most efficient
24
26
  export function inDocument(node) {
@@ -1,4 +1,4 @@
1
- import Message from "../messages/message.js";
1
+ import type Message from "../common/messages.js";
2
2
  import Nodes from "./nodes.js";
3
3
  import Sanitizer from "./sanitizer.js";
4
4
  import Ticker from "./ticker.js";
@@ -7,17 +7,19 @@ import Session from "./session.js";
7
7
  import type { Options as ObserverOptions } from "./observer/top_observer.js";
8
8
  import type { Options as SanitizerOptions } from "./sanitizer.js";
9
9
  import type { Options as LoggerOptions } from "./logger.js";
10
- import type { Options as WebworkerOptions } from "../messages/webworker.js";
11
- export interface OnStartInfo {
12
- sessionID: string;
13
- sessionToken: string;
14
- userUUID: string;
15
- }
10
+ import type { Options as WebworkerOptions } from "../common/webworker.js";
16
11
  export interface StartOptions {
17
12
  userID?: string;
18
13
  metadata?: Record<string, string>;
19
14
  forceNew?: boolean;
20
15
  }
16
+ export interface OnStartInfo {
17
+ sessionID: string;
18
+ sessionToken: string;
19
+ userUUID: string;
20
+ }
21
+ declare type StartCallback = (i: OnStartInfo) => void;
22
+ declare type CommitCallback = (messages: Array<Message>) => void;
21
23
  declare type AppOptions = {
22
24
  revID: string;
23
25
  node_id: string;
@@ -31,11 +33,9 @@ declare type AppOptions = {
31
33
  __is_snippet: boolean;
32
34
  __debug_report_edp: string | null;
33
35
  __debug__?: LoggerOptions;
34
- onStart?: (info: OnStartInfo) => void;
36
+ onStart?: StartCallback;
35
37
  } & WebworkerOptions;
36
38
  export declare type Options = AppOptions & ObserverOptions & SanitizerOptions;
37
- declare type Callback = () => void;
38
- declare type CommitCallback = (messages: Array<Message>) => void;
39
39
  export declare const CANCELED = "canceled";
40
40
  export declare const DEFAULT_INGEST_POINT = "https://api.openreplay.com/ingest";
41
41
  export default class App {
@@ -58,13 +58,12 @@ export default class App {
58
58
  private readonly worker?;
59
59
  constructor(projectKey: string, sessionToken: string | null | undefined, options: Partial<Options>);
60
60
  private _debug;
61
- private readonly preStartMessages;
62
61
  send(message: Message, urgent?: boolean): void;
63
62
  private commit;
64
63
  safe<T extends (...args: any[]) => void>(fn: T): T;
65
64
  attachCommitCallback(cb: CommitCallback): void;
66
- attachStartCallback(cb: Callback): void;
67
- attachStopCallback(cb: Callback): void;
65
+ attachStartCallback(cb: StartCallback): void;
66
+ attachStopCallback(cb: Function): void;
68
67
  attachEventListener(target: EventTarget, type: string, listener: EventListener, useSafe?: boolean, useCapture?: boolean): void;
69
68
  checkRequiredVersion(version: string): boolean;
70
69
  private getStartInfo;
package/lib/app/index.js CHANGED
@@ -1,5 +1,5 @@
1
+ import { Timestamp } from "../common/messages.js";
1
2
  import { timestamp } from "../utils.js";
2
- import { Timestamp } from "../messages/index.js";
3
3
  import Nodes from "./nodes.js";
4
4
  import Observer from "./observer/top_observer.js";
5
5
  import Sanitizer from "./sanitizer.js";
@@ -26,8 +26,7 @@ export default class App {
26
26
  this.stopCallbacks = [];
27
27
  this.commitCallbacks = [];
28
28
  this.activityState = ActivityState.NotActive;
29
- this.version = '3.5.8'; // TODO: version compatability check inside each plugin.
30
- this.preStartMessages = [];
29
+ this.version = '3.5.11'; // TODO: version compatability check inside each plugin.
31
30
  this.projectKey = projectKey;
32
31
  this.options = Object.assign({
33
32
  revID: '',
@@ -55,13 +54,13 @@ export default class App {
55
54
  this.notify = new Logger(this.options.verbose ? LogLevel.Warnings : LogLevel.Silent);
56
55
  this.session = new Session(this);
57
56
  try {
58
- this.worker = new Worker(URL.createObjectURL(new Blob([`"use strict";function t(t){function s(...s){return new t(...s)}return s.prototype=t.prototype,s}const s=new Map;const i=t(class{constructor(t,s,i){this.pageNo=t,this.firstIndex=s,this.timestamp=i,this._id=80}encode(t){return t.uint(80)&&t.uint(this.pageNo)&&t.uint(this.firstIndex)&&t.int(this.timestamp)}});s.set(80,i);const n=t(class{constructor(t){this.timestamp=t,this._id=0}encode(t){return t.uint(0)&&t.uint(this.timestamp)}});s.set(0,n);const e=t(class{constructor(t,s,i){this.url=t,this.referrer=s,this.navigationStart=i,this._id=4}encode(t){return t.uint(4)&&t.string(this.url)&&t.string(this.referrer)&&t.uint(this.navigationStart)}});s.set(4,e);const r=t(class{constructor(t,s){this.width=t,this.height=s,this._id=5}encode(t){return t.uint(5)&&t.uint(this.width)&&t.uint(this.height)}});s.set(5,r);const o=t(class{constructor(t,s){this.x=t,this.y=s,this._id=6}encode(t){return t.uint(6)&&t.int(this.x)&&t.int(this.y)}});s.set(6,o);const h=t(class{constructor(){this._id=7}encode(t){return t.uint(7)}});s.set(7,h);const c=t(class{constructor(t,s,i,n,e){this.id=t,this.parentID=s,this.index=i,this.tag=n,this.svg=e,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)}});s.set(8,c);const u=t(class{constructor(t,s,i){this.id=t,this.parentID=s,this.index=i,this._id=9}encode(t){return t.uint(9)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});s.set(9,u);const a=t(class{constructor(t,s,i){this.id=t,this.parentID=s,this.index=i,this._id=10}encode(t){return t.uint(10)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});s.set(10,a);const d=t(class{constructor(t){this.id=t,this._id=11}encode(t){return t.uint(11)&&t.uint(this.id)}});s.set(11,d);const l=t(class{constructor(t,s,i){this.id=t,this.name=s,this.value=i,this._id=12}encode(t){return t.uint(12)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)}});s.set(12,l);const g=t(class{constructor(t,s){this.id=t,this.name=s,this._id=13}encode(t){return t.uint(13)&&t.uint(this.id)&&t.string(this.name)}});s.set(13,g);const f=t(class{constructor(t,s){this.id=t,this.data=s,this._id=14}encode(t){return t.uint(14)&&t.uint(this.id)&&t.string(this.data)}});s.set(14,f);const p=t(class{constructor(t,s,i){this.id=t,this.x=s,this.y=i,this._id=16}encode(t){return t.uint(16)&&t.uint(this.id)&&t.int(this.x)&&t.int(this.y)}});s.set(16,p);const m=t(class{constructor(t,s){this.id=t,this.label=s,this._id=17}encode(t){return t.uint(17)&&t.uint(this.id)&&t.string(this.label)}});s.set(17,m);const _=t(class{constructor(t,s,i){this.id=t,this.value=s,this.mask=i,this._id=18}encode(t){return t.uint(18)&&t.uint(this.id)&&t.string(this.value)&&t.int(this.mask)}});s.set(18,_);const y=t(class{constructor(t,s){this.id=t,this.checked=s,this._id=19}encode(t){return t.uint(19)&&t.uint(this.id)&&t.boolean(this.checked)}});s.set(19,y);const v=t(class{constructor(t,s){this.x=t,this.y=s,this._id=20}encode(t){return t.uint(20)&&t.uint(this.x)&&t.uint(this.y)}});s.set(20,v);const S=t(class{constructor(t,s){this.level=t,this.value=s,this._id=22}encode(t){return t.uint(22)&&t.string(this.level)&&t.string(this.value)}});s.set(22,S);const b=t(class{constructor(t,s,i,n,e,r,o,h,c){this.requestStart=t,this.responseStart=s,this.responseEnd=i,this.domContentLoadedEventStart=n,this.domContentLoadedEventEnd=e,this.loadEventStart=r,this.loadEventEnd=o,this.firstPaint=h,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)}});s.set(23,b);const x=t(class{constructor(t,s,i){this.speedIndex=t,this.visuallyComplete=s,this.timeToInteractive=i,this._id=24}encode(t){return t.uint(24)&&t.uint(this.speedIndex)&&t.uint(this.visuallyComplete)&&t.uint(this.timeToInteractive)}});s.set(24,x);const E=t(class{constructor(t,s,i){this.name=t,this.message=s,this.payload=i,this._id=25}encode(t){return t.uint(25)&&t.string(this.name)&&t.string(this.message)&&t.string(this.payload)}});s.set(25,E);const k=t(class{constructor(t,s){this.name=t,this.payload=s,this._id=27}encode(t){return t.uint(27)&&t.string(this.name)&&t.string(this.payload)}});s.set(27,k);const I=t(class{constructor(t){this.id=t,this._id=28}encode(t){return t.uint(28)&&t.string(this.id)}});s.set(28,I);const z=t(class{constructor(t){this.id=t,this._id=29}encode(t){return t.uint(29)&&t.string(this.id)}});s.set(29,z);const w=t(class{constructor(t,s){this.key=t,this.value=s,this._id=30}encode(t){return t.uint(30)&&t.string(this.key)&&t.string(this.value)}});s.set(30,w);const T=t(class{constructor(t,s,i){this.id=t,this.rule=s,this.index=i,this._id=37}encode(t){return t.uint(37)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)}});s.set(37,T);const L=t(class{constructor(t,s){this.id=t,this.index=s,this._id=38}encode(t){return t.uint(38)&&t.uint(this.id)&&t.uint(this.index)}});s.set(38,L);const A=t(class{constructor(t,s,i,n,e,r,o){this.method=t,this.url=s,this.request=i,this.response=n,this.status=e,this.timestamp=r,this.duration=o,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)}});s.set(39,A);const C=t(class{constructor(t,s,i,n){this.name=t,this.duration=s,this.args=i,this.result=n,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)}});s.set(40,C);const M=t(class{constructor(t,s){this.key=t,this.value=s,this._id=41}encode(t){return t.uint(41)&&t.string(this.key)&&t.string(this.value)}});s.set(41,M);const R=t(class{constructor(t){this.type=t,this._id=42}encode(t){return t.uint(42)&&t.string(this.type)}});s.set(42,R);const N=t(class{constructor(t,s,i){this.action=t,this.state=s,this.duration=i,this._id=44}encode(t){return t.uint(44)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});s.set(44,N);const D=t(class{constructor(t,s){this.mutation=t,this.state=s,this._id=45}encode(t){return t.uint(45)&&t.string(this.mutation)&&t.string(this.state)}});s.set(45,D);const U=t(class{constructor(t,s){this.type=t,this.payload=s,this._id=46}encode(t){return t.uint(46)&&t.string(this.type)&&t.string(this.payload)}});s.set(46,U);const O=t(class{constructor(t,s,i){this.action=t,this.state=s,this.duration=i,this._id=47}encode(t){return t.uint(47)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});s.set(47,O);const q=t(class{constructor(t,s,i,n){this.operationKind=t,this.operationName=s,this.variables=i,this.response=n,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)}});s.set(48,q);const H=t(class{constructor(t,s,i,n){this.frames=t,this.ticks=s,this.totalJSHeapSize=i,this.usedJSHeapSize=n,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)}});s.set(49,H);const P=t(class{constructor(t,s,i,n,e,r,o,h){this.timestamp=t,this.duration=s,this.ttfb=i,this.headerSize=n,this.encodedBodySize=e,this.decodedBodySize=r,this.url=o,this.initiator=h,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)}});s.set(53,P);const B=t(class{constructor(t,s){this.downlink=t,this.type=s,this._id=54}encode(t){return t.uint(54)&&t.uint(this.downlink)&&t.string(this.type)}});s.set(54,B);const J=t(class{constructor(t){this.hidden=t,this._id=55}encode(t){return t.uint(55)&&t.boolean(this.hidden)}});s.set(55,J);const j=t(class{constructor(t,s,i,n,e,r,o){this.timestamp=t,this.duration=s,this.context=i,this.containerType=n,this.containerSrc=e,this.containerId=r,this.containerName=o,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)}});s.set(59,j);const G=t(class{constructor(t,s,i,n){this.id=t,this.name=s,this.value=i,this.baseURL=n,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)}});s.set(60,G);const K=t(class{constructor(t,s,i){this.id=t,this.data=s,this.baseURL=i,this._id=61}encode(t){return t.uint(61)&&t.uint(this.id)&&t.string(this.data)&&t.string(this.baseURL)}});s.set(61,K);const X=t(class{constructor(t,s){this.type=t,this.value=s,this._id=63}encode(t){return t.uint(63)&&t.string(this.type)&&t.string(this.value)}});s.set(63,X);const F=t(class{constructor(t,s){this.name=t,this.payload=s,this._id=64}encode(t){return t.uint(64)&&t.string(this.name)&&t.string(this.payload)}});s.set(64,F);const Q=t(class{constructor(){this._id=65}encode(t){return t.uint(65)}});s.set(65,Q);const V=t(class{constructor(t,s,i,n){this.id=t,this.rule=s,this.index=i,this.baseURL=n,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)}});s.set(67,V);const W=t(class{constructor(t,s,i,n){this.id=t,this.hesitationTime=s,this.label=i,this.selector=n,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)}});s.set(69,W);const Y=t(class{constructor(t,s){this.frameID=t,this.id=s,this._id=70}encode(t){return t.uint(70)&&t.uint(this.frameID)&&t.uint(this.id)}});s.set(70,Y);const Z="function"==typeof TextEncoder?new TextEncoder:{encode(t){const s=t.length,i=new Uint8Array(3*s);let n=-1;for(var e=0,r=0,o=0;o!==s;){if(e=t.charCodeAt(o),o+=1,e>=55296&&e<=56319){if(o===s){i[n+=1]=239,i[n+=1]=191,i[n+=1]=189;break}if(!((r=t.charCodeAt(o))>=56320&&r<=57343)){i[n+=1]=239,i[n+=1]=191,i[n+=1]=189;continue}if(o+=1,(e=1024*(e-55296)+r-56320+65536)>65535){i[n+=1]=240|e>>>18,i[n+=1]=128|e>>>12&63,i[n+=1]=128|e>>>6&63,i[n+=1]=128|63&e;continue}}e<=127?i[n+=1]=0|e:e<=2047?(i[n+=1]=192|e>>>6,i[n+=1]=128|63&e):(i[n+=1]=224|e>>>12,i[n+=1]=128|e>>>6&63,i[n+=1]=128|63&e)}return i.subarray(0,n+1)}};class tt{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 s=Z.encode(t),i=s.byteLength;return!(!this.uint(i)||this.offset+i>this.size)&&(this.data.set(s,this.offset),this.offset+=i,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}let st=1e6,it=2e5,nt=new tt(it),et="",rt="",ot=0,ht=0,ct=0,ut=0,at=!0;function dt(){return new i(ot,ut,ht).encode(nt)}let lt=null;const gt=[];let ft,pt=!1,mt=0,_t=3e3,yt=10;function vt(){if(at||""===rt||""===et)return;const t=nt.flush();pt?gt.push(t):(pt=!0,function t(s){const i=new XMLHttpRequest;function n(){if(mt>=yt)return St(),void self.postMessage(null);mt++,setTimeout(()=>t(s),_t)}i.open("POST",et+"/v1/web/i",!1),i.setRequestHeader("Authorization","Bearer "+rt),i.onreadystatechange=function(){if(4===this.readyState){if(0==this.status)return;if(401===this.status)return pt=!1,void self.postMessage("restart");if(this.status>=400)return void n();mt=0;const s=gt.shift();s?t(s):pt=!1}},i.onerror=n,i.send(s.buffer)}(t)),at=!0,dt()}function St(){et="",rt="",null!==lt&&(clearInterval(lt),lt=null),gt.length=0,nt.reset()}self.onmessage=({data:t})=>{if(null!==t)return"stop"===t?(vt(),void St()):Array.isArray(t)?void t.forEach(t=>{const i=new(s.get(t._id));if(Object.assign(i,t),i instanceof n?ht=i.timestamp:i instanceof J&&(i.hidden?ft=setTimeout(()=>self.postMessage("restart"),18e5):clearTimeout(ft)),nt.checkpoint(),!i.encode(nt)&&(vt(),!i.encode(nt)))for(;!i.encode(nt);){if(it===st)return console.warn("OpenReplay: beacon size overflow."),nt.reset(),void dt();it=Math.min(2*it,st),nt=new tt(it),dt()}ut++,at=!1}):(et=t.ingestPoint||et,rt=t.token||rt,ot=t.pageNo||ot,ht=t.startTimestamp||ht,ct=t.timeAdjustment||ct,yt=t.connAttemptCount||yt,_t=t.connAttemptGap||_t,st=t.beaconSizeLimit||st,it=Math.min(st,t.beaconSize||it),nt.isEmpty()&&dt(),void(null===lt&&(lt=setInterval(vt,1e4))));vt()};
57
+ this.worker = new Worker(URL.createObjectURL(new Blob([`"use strict";function t(t){function i(...i){return new t(...i)}return i.prototype=t.prototype,i}const i=new Map;const s=t(class{constructor(t,i,s){this.pageNo=t,this.firstIndex=i,this.timestamp=s,this._id=80}encode(t){return t.uint(80)&&t.uint(this.pageNo)&&t.uint(this.firstIndex)&&t.int(this.timestamp)}});i.set(80,s);const e=t(class{constructor(t){this.timestamp=t,this._id=0}encode(t){return t.uint(0)&&t.uint(this.timestamp)}});i.set(0,e);const n=t(class{constructor(t,i,s){this.url=t,this.referrer=i,this.navigationStart=s,this._id=4}encode(t){return t.uint(4)&&t.string(this.url)&&t.string(this.referrer)&&t.uint(this.navigationStart)}});i.set(4,n);const r=t(class{constructor(t,i){this.width=t,this.height=i,this._id=5}encode(t){return t.uint(5)&&t.uint(this.width)&&t.uint(this.height)}});i.set(5,r);const h=t(class{constructor(t,i){this.x=t,this.y=i,this._id=6}encode(t){return t.uint(6)&&t.int(this.x)&&t.int(this.y)}});i.set(6,h);const o=t(class{constructor(){this._id=7}encode(t){return t.uint(7)}});i.set(7,o);const c=t(class{constructor(t,i,s,e,n){this.id=t,this.parentID=i,this.index=s,this.tag=e,this.svg=n,this._id=8}encode(t){return t.uint(8)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)&&t.string(this.tag)&&t.boolean(this.svg)}});i.set(8,c);const a=t(class{constructor(t,i,s){this.id=t,this.parentID=i,this.index=s,this._id=9}encode(t){return t.uint(9)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});i.set(9,a);const u=t(class{constructor(t,i,s){this.id=t,this.parentID=i,this.index=s,this._id=10}encode(t){return t.uint(10)&&t.uint(this.id)&&t.uint(this.parentID)&&t.uint(this.index)}});i.set(10,u);const d=t(class{constructor(t){this.id=t,this._id=11}encode(t){return t.uint(11)&&t.uint(this.id)}});i.set(11,d);const l=t(class{constructor(t,i,s){this.id=t,this.name=i,this.value=s,this._id=12}encode(t){return t.uint(12)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)}});i.set(12,l);const p=t(class{constructor(t,i){this.id=t,this.name=i,this._id=13}encode(t){return t.uint(13)&&t.uint(this.id)&&t.string(this.name)}});i.set(13,p);const m=t(class{constructor(t,i){this.id=t,this.data=i,this._id=14}encode(t){return t.uint(14)&&t.uint(this.id)&&t.string(this.data)}});i.set(14,m);const g=t(class{constructor(t,i,s){this.id=t,this.x=i,this.y=s,this._id=16}encode(t){return t.uint(16)&&t.uint(this.id)&&t.int(this.x)&&t.int(this.y)}});i.set(16,g);const f=t(class{constructor(t,i){this.id=t,this.label=i,this._id=17}encode(t){return t.uint(17)&&t.uint(this.id)&&t.string(this.label)}});i.set(17,f);const y=t(class{constructor(t,i,s){this.id=t,this.value=i,this.mask=s,this._id=18}encode(t){return t.uint(18)&&t.uint(this.id)&&t.string(this.value)&&t.int(this.mask)}});i.set(18,y);const _=t(class{constructor(t,i){this.id=t,this.checked=i,this._id=19}encode(t){return t.uint(19)&&t.uint(this.id)&&t.boolean(this.checked)}});i.set(19,_);const v=t(class{constructor(t,i){this.x=t,this.y=i,this._id=20}encode(t){return t.uint(20)&&t.uint(this.x)&&t.uint(this.y)}});i.set(20,v);const b=t(class{constructor(t,i){this.level=t,this.value=i,this._id=22}encode(t){return t.uint(22)&&t.string(this.level)&&t.string(this.value)}});i.set(22,b);const S=t(class{constructor(t,i,s,e,n,r,h,o,c){this.requestStart=t,this.responseStart=i,this.responseEnd=s,this.domContentLoadedEventStart=e,this.domContentLoadedEventEnd=n,this.loadEventStart=r,this.loadEventEnd=h,this.firstPaint=o,this.firstContentfulPaint=c,this._id=23}encode(t){return t.uint(23)&&t.uint(this.requestStart)&&t.uint(this.responseStart)&&t.uint(this.responseEnd)&&t.uint(this.domContentLoadedEventStart)&&t.uint(this.domContentLoadedEventEnd)&&t.uint(this.loadEventStart)&&t.uint(this.loadEventEnd)&&t.uint(this.firstPaint)&&t.uint(this.firstContentfulPaint)}});i.set(23,S);const w=t(class{constructor(t,i,s){this.speedIndex=t,this.visuallyComplete=i,this.timeToInteractive=s,this._id=24}encode(t){return t.uint(24)&&t.uint(this.speedIndex)&&t.uint(this.visuallyComplete)&&t.uint(this.timeToInteractive)}});i.set(24,w);const E=t(class{constructor(t,i,s){this.name=t,this.message=i,this.payload=s,this._id=25}encode(t){return t.uint(25)&&t.string(this.name)&&t.string(this.message)&&t.string(this.payload)}});i.set(25,E);const x=t(class{constructor(t,i){this.name=t,this.payload=i,this._id=27}encode(t){return t.uint(27)&&t.string(this.name)&&t.string(this.payload)}});i.set(27,x);const T=t(class{constructor(t){this.id=t,this._id=28}encode(t){return t.uint(28)&&t.string(this.id)}});i.set(28,T);const z=t(class{constructor(t){this.id=t,this._id=29}encode(t){return t.uint(29)&&t.string(this.id)}});i.set(29,z);const k=t(class{constructor(t,i){this.key=t,this.value=i,this._id=30}encode(t){return t.uint(30)&&t.string(this.key)&&t.string(this.value)}});i.set(30,k);const I=t(class{constructor(t,i,s){this.id=t,this.rule=i,this.index=s,this._id=37}encode(t){return t.uint(37)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)}});i.set(37,I);const M=t(class{constructor(t,i){this.id=t,this.index=i,this._id=38}encode(t){return t.uint(38)&&t.uint(this.id)&&t.uint(this.index)}});i.set(38,M);const B=t(class{constructor(t,i,s,e,n,r,h){this.method=t,this.url=i,this.request=s,this.response=e,this.status=n,this.timestamp=r,this.duration=h,this._id=39}encode(t){return t.uint(39)&&t.string(this.method)&&t.string(this.url)&&t.string(this.request)&&t.string(this.response)&&t.uint(this.status)&&t.uint(this.timestamp)&&t.uint(this.duration)}});i.set(39,B);const L=t(class{constructor(t,i,s,e){this.name=t,this.duration=i,this.args=s,this.result=e,this._id=40}encode(t){return t.uint(40)&&t.string(this.name)&&t.uint(this.duration)&&t.string(this.args)&&t.string(this.result)}});i.set(40,L);const C=t(class{constructor(t,i){this.key=t,this.value=i,this._id=41}encode(t){return t.uint(41)&&t.string(this.key)&&t.string(this.value)}});i.set(41,C);const A=t(class{constructor(t){this.type=t,this._id=42}encode(t){return t.uint(42)&&t.string(this.type)}});i.set(42,A);const U=t(class{constructor(t,i,s){this.action=t,this.state=i,this.duration=s,this._id=44}encode(t){return t.uint(44)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});i.set(44,U);const N=t(class{constructor(t,i){this.mutation=t,this.state=i,this._id=45}encode(t){return t.uint(45)&&t.string(this.mutation)&&t.string(this.state)}});i.set(45,N);const R=t(class{constructor(t,i){this.type=t,this.payload=i,this._id=46}encode(t){return t.uint(46)&&t.string(this.type)&&t.string(this.payload)}});i.set(46,R);const O=t(class{constructor(t,i,s){this.action=t,this.state=i,this.duration=s,this._id=47}encode(t){return t.uint(47)&&t.string(this.action)&&t.string(this.state)&&t.uint(this.duration)}});i.set(47,O);const P=t(class{constructor(t,i,s,e){this.operationKind=t,this.operationName=i,this.variables=s,this.response=e,this._id=48}encode(t){return t.uint(48)&&t.string(this.operationKind)&&t.string(this.operationName)&&t.string(this.variables)&&t.string(this.response)}});i.set(48,P);const q=t(class{constructor(t,i,s,e){this.frames=t,this.ticks=i,this.totalJSHeapSize=s,this.usedJSHeapSize=e,this._id=49}encode(t){return t.uint(49)&&t.int(this.frames)&&t.int(this.ticks)&&t.uint(this.totalJSHeapSize)&&t.uint(this.usedJSHeapSize)}});i.set(49,q);const D=t(class{constructor(t,i,s,e,n,r,h,o){this.timestamp=t,this.duration=i,this.ttfb=s,this.headerSize=e,this.encodedBodySize=n,this.decodedBodySize=r,this.url=h,this.initiator=o,this._id=53}encode(t){return t.uint(53)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.ttfb)&&t.uint(this.headerSize)&&t.uint(this.encodedBodySize)&&t.uint(this.decodedBodySize)&&t.string(this.url)&&t.string(this.initiator)}});i.set(53,D);const W=t(class{constructor(t,i){this.downlink=t,this.type=i,this._id=54}encode(t){return t.uint(54)&&t.uint(this.downlink)&&t.string(this.type)}});i.set(54,W);const H=t(class{constructor(t){this.hidden=t,this._id=55}encode(t){return t.uint(55)&&t.boolean(this.hidden)}});i.set(55,H);const J=t(class{constructor(t,i,s,e,n,r,h){this.timestamp=t,this.duration=i,this.context=s,this.containerType=e,this.containerSrc=n,this.containerId=r,this.containerName=h,this._id=59}encode(t){return t.uint(59)&&t.uint(this.timestamp)&&t.uint(this.duration)&&t.uint(this.context)&&t.uint(this.containerType)&&t.string(this.containerSrc)&&t.string(this.containerId)&&t.string(this.containerName)}});i.set(59,J);const F=t(class{constructor(t,i,s,e){this.id=t,this.name=i,this.value=s,this.baseURL=e,this._id=60}encode(t){return t.uint(60)&&t.uint(this.id)&&t.string(this.name)&&t.string(this.value)&&t.string(this.baseURL)}});i.set(60,F);const X=t(class{constructor(t,i,s){this.id=t,this.data=i,this.baseURL=s,this._id=61}encode(t){return t.uint(61)&&t.uint(this.id)&&t.string(this.data)&&t.string(this.baseURL)}});i.set(61,X);const G=t(class{constructor(t,i){this.type=t,this.value=i,this._id=63}encode(t){return t.uint(63)&&t.string(this.type)&&t.string(this.value)}});i.set(63,G);const K=t(class{constructor(t,i){this.name=t,this.payload=i,this._id=64}encode(t){return t.uint(64)&&t.string(this.name)&&t.string(this.payload)}});i.set(64,K);const j=t(class{constructor(){this._id=65}encode(t){return t.uint(65)}});i.set(65,j);const Q=t(class{constructor(t,i,s,e){this.id=t,this.rule=i,this.index=s,this.baseURL=e,this._id=67}encode(t){return t.uint(67)&&t.uint(this.id)&&t.string(this.rule)&&t.uint(this.index)&&t.string(this.baseURL)}});i.set(67,Q);const V=t(class{constructor(t,i,s,e){this.id=t,this.hesitationTime=i,this.label=s,this.selector=e,this._id=69}encode(t){return t.uint(69)&&t.uint(this.id)&&t.uint(this.hesitationTime)&&t.string(this.label)&&t.string(this.selector)}});i.set(69,V);const Y=t(class{constructor(t,i){this.frameID=t,this.id=i,this._id=70}encode(t){return t.uint(70)&&t.uint(this.frameID)&&t.uint(this.id)}});i.set(70,Y);class Z{constructor(t,i,s,e=10,n=1e3){this.onUnauthorised=i,this.onFailure=s,this.MAX_ATTEMPTS_COUNT=e,this.ATTEMPT_TIMEOUT=n,this.attemptsCount=0,this.busy=!1,this.queue=[],this.token=null,this.ingestURL=t+"/v1/web/i"}authorise(t){this.token=t}push(t){this.busy||!this.token?this.queue.push(t):this.sendBatch(t)}retry(t){this.attemptsCount>=this.MAX_ATTEMPTS_COUNT?this.onFailure():(this.attemptsCount++,setTimeout(()=>this.sendBatch(t),this.ATTEMPT_TIMEOUT*this.attemptsCount))}sendBatch(t){this.busy=!0,fetch(this.ingestURL,{body:t,method:"POST",headers:{Authorization:"Bearer "+this.token},keepalive:t.length<65536}).then(i=>{if(401===i.status)return this.busy=!1,void this.onUnauthorised();if(i.status>=400)return void this.retry(t);this.attemptsCount=0;const s=this.queue.shift();s?this.sendBatch(s):this.busy=!1}).catch(i=>{console.warn("OpenReplay:",i),this.retry(t)})}clean(){this.queue.length=0}}const tt="function"==typeof TextEncoder?new TextEncoder:{encode(t){const i=t.length,s=new Uint8Array(3*i);let e=-1;for(var n=0,r=0,h=0;h!==i;){if(n=t.charCodeAt(h),h+=1,n>=55296&&n<=56319){if(h===i){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;break}if(!((r=t.charCodeAt(h))>=56320&&r<=57343)){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;continue}if(h+=1,(n=1024*(n-55296)+r-56320+65536)>65535){s[e+=1]=240|n>>>18,s[e+=1]=128|n>>>12&63,s[e+=1]=128|n>>>6&63,s[e+=1]=128|63&n;continue}}n<=127?s[e+=1]=0|n:n<=2047?(s[e+=1]=192|n>>>6,s[e+=1]=128|63&n):(s[e+=1]=224|n>>>12,s[e+=1]=128|n>>>6&63,s[e+=1]=128|63&n)}return s.subarray(0,e+1)}};class it{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}checkpoint(){this.checkpointOffset=this.offset}isEmpty(){return 0===this.offset}boolean(t){return this.data[this.offset++]=+t,this.offset<=this.size}uint(t){for((t<0||t>Number.MAX_SAFE_INTEGER)&&(t=0);t>=128;)this.data[this.offset++]=t%256|128,t=Math.floor(t/128);return this.data[this.offset++]=t,this.offset<=this.size}int(t){return t=Math.round(t),this.uint(t>=0?2*t:-2*t-1)}string(t){const i=tt.encode(t),s=i.byteLength;return!(!this.uint(s)||this.offset+s>this.size)&&(this.data.set(i,this.offset),this.offset+=s,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}class st{constructor(t,i,s){this.pageNo=t,this.timestamp=i,this.onBatch=s,this.nextIndex=0,this.beaconSize=2e5,this.writer=new it(this.beaconSize),this.isEmpty=!0,this.beaconSizeLimit=1e6,this.prepareBatchMeta()}prepareBatchMeta(){return new s(this.pageNo,this.nextIndex,this.timestamp).encode(this.writer)}setBeaconSizeLimit(t){this.beaconSizeLimit=t}writeMessage(t){if(t instanceof e&&(this.timestamp=t.timestamp),!t.encode(this.writer))for(this.isEmpty||(this.onBatch(this.writer.flush()),this.prepareBatchMeta());!t.encode(this.writer);){if(this.beaconSize===this.beaconSizeLimit)return console.warn("OpenReplay: beacon size overflow. Skipping large message."),this.writer.reset(),this.prepareBatchMeta(),void(this.isEmpty=!0);this.beaconSize=Math.min(2*this.beaconSize,this.beaconSizeLimit),this.writer=new it(this.beaconSize),this.prepareBatchMeta()}this.writer.checkpoint(),this.nextIndex++,this.isEmpty=!1}finaliseBatch(){this.isEmpty||(this.onBatch(this.writer.flush()),this.prepareBatchMeta(),this.isEmpty=!0)}clean(){this.writer.reset()}}let et=null,nt=null;function rt(){nt&&nt.finaliseBatch()}function ht(){null!==ct&&(clearInterval(ct),ct=null),nt&&(nt.clean(),nt=null)}let ot,ct=null;self.onmessage=({data:t})=>{if(null!=t){if("stop"===t)return rt(),void ht();if(Array.isArray(t)){if(!nt)throw new Error("WebWorker: writer not initialised.");const s=nt;t.forEach(t=>{const e=new(i.get(t._id));Object.assign(e,t),e instanceof H&&(e.hidden?ot=setTimeout(()=>self.postMessage("restart"),18e5):clearTimeout(ot)),s.writeMessage(e)})}else{if("start"===t.type)return et=new Z(t.ingestPoint,()=>{self.postMessage("restart")},()=>{et&&(et.clean(),et=null),ht(),self.postMessage("failed")},t.connAttemptCount,t.connAttemptGap),nt=new st(t.pageNo,t.timestamp,t=>et&&et.push(t)),void(null===ct&&(ct=setInterval(rt,1e4)));if("auth"===t.type){if(!et)throw new Error("WebWorker: sender not initialised. Recieved auth.");if(!nt)throw new Error("WebWorker: writer not initialised. Recieved auth.");return et.authorise(t.token),void(t.beaconSizeLimit&&nt.setBeaconSizeLimit(t.beaconSizeLimit))}}}else rt()};
59
58
  `], { type: 'text/javascript' })));
60
59
  this.worker.onerror = e => {
61
60
  this._debug("webworker_error", e);
62
61
  };
63
62
  this.worker.onmessage = ({ data }) => {
64
- if (data === null) {
63
+ if (data === "failed") {
65
64
  this.stop();
66
65
  }
67
66
  else if (data === "restart") {
@@ -100,15 +99,12 @@ export default class App {
100
99
  if (this.activityState === ActivityState.NotActive) {
101
100
  return;
102
101
  }
103
- if (this.activityState === ActivityState.Starting) {
104
- this.preStartMessages.push(message);
105
- }
106
- if (this.preStartMessages.length) {
107
- this.messages.push(...this.preStartMessages);
108
- this.preStartMessages.length = 0;
109
- }
110
102
  this.messages.push(message);
111
- if (urgent) {
103
+ // TODO: commit on start if there were `urgent` sends;
104
+ // Clearify where urgent can be used for;
105
+ // Clearify workflow for each type of message in case it was sent before start
106
+ // (like Fetch before start; maybe add an option "preCapture: boolean" or sth alike)
107
+ if (this.activityState === ActivityState.Active && urgent) {
112
108
  this.commit();
113
109
  }
114
110
  }
@@ -240,14 +236,15 @@ export default class App {
240
236
  }
241
237
  sessionStorage.setItem(this.options.session_pageno_key, pageNo.toString());
242
238
  const startInfo = this.getStartInfo();
243
- const messageData = {
244
- ingestPoint: this.options.ingestPoint,
239
+ const startWorkerMsg = {
240
+ type: "start",
245
241
  pageNo,
246
- startTimestamp: startInfo.timestamp,
242
+ ingestPoint: this.options.ingestPoint,
243
+ timestamp: startInfo.timestamp,
247
244
  connAttemptCount: this.options.connAttemptCount,
248
245
  connAttemptGap: this.options.connAttemptGap,
249
246
  };
250
- this.worker.postMessage(messageData); // brings delay of 10th ms?
247
+ this.worker.postMessage(startWorkerMsg); // brings delay of 10th ms?
251
248
  const sReset = sessionStorage.getItem(this.options.session_reset_key);
252
249
  sessionStorage.removeItem(this.options.session_reset_key);
253
250
  return window.fetch(this.options.ingestPoint + '/v1/web/start', {
@@ -282,13 +279,18 @@ export default class App {
282
279
  localStorage.setItem(this.options.local_uuid_key, userUUID);
283
280
  this.session.update(Object.assign({ sessionID }, startOpts));
284
281
  this.activityState = ActivityState.Active;
285
- this.worker.postMessage({ token, beaconSizeLimit });
286
- this.startCallbacks.forEach((cb) => cb());
282
+ const startWorkerMsg = {
283
+ type: "auth",
284
+ token,
285
+ beaconSizeLimit
286
+ };
287
+ this.worker.postMessage(startWorkerMsg);
288
+ const onStartInfo = { sessionToken: token, userUUID, sessionID };
289
+ this.startCallbacks.forEach((cb) => cb(onStartInfo));
287
290
  this.observer.observe();
288
291
  this.ticker.start();
289
292
  this.notify.log("OpenReplay tracking started.");
290
293
  // TODO: get rid of onStart
291
- const onStartInfo = { sessionToken: token, userUUID, sessionID };
292
294
  if (typeof this.options.onStart === 'function') {
293
295
  this.options.onStart(onStartInfo);
294
296
  }
@@ -1,5 +1,5 @@
1
1
  import Observer from "./observer.js";
2
- import { CreateIFrameDocument } from "../../messages/index.js";
2
+ import { CreateIFrameDocument } from "../../common/messages.js";
3
3
  export default class IFrameObserver extends Observer {
4
4
  observe(iframe) {
5
5
  const doc = iframe.contentDocument;
@@ -1,4 +1,4 @@
1
- import { RemoveNodeAttribute, SetNodeAttribute, SetNodeAttributeURLBased, SetCSSDataURLBased, SetNodeData, CreateTextNode, CreateElementNode, MoveNode, RemoveNode, } from "../../messages/index.js";
1
+ import { RemoveNodeAttribute, SetNodeAttribute, SetNodeAttributeURLBased, SetCSSDataURLBased, SetNodeData, CreateTextNode, CreateElementNode, MoveNode, RemoveNode, } from "../../common/messages.js";
2
2
  import { isInstance, inDocument } from "../context.js";
3
3
  function isSVGElement(node) {
4
4
  return node.namespaceURI === 'http://www.w3.org/2000/svg';
@@ -1,5 +1,5 @@
1
1
  import Observer from "./observer.js";
2
- import { CreateIFrameDocument } from "../../messages/index.js";
2
+ import { CreateIFrameDocument } from "../../common/messages.js";
3
3
  export default class ShadowRootObserver extends Observer {
4
4
  observe(el) {
5
5
  const shRoot = el.shadowRoot;
@@ -2,7 +2,7 @@ import Observer from "./observer.js";
2
2
  import { isInstance } from "../context.js";
3
3
  import IFrameObserver from "./iframe_observer.js";
4
4
  import ShadowRootObserver from "./shadow_root_observer.js";
5
- import { CreateDocument } from "../../messages/index.js";
5
+ import { CreateDocument } from "../../common/messages.js";
6
6
  import { IN_BROWSER, hasOpenreplayAttribute } from '../../utils.js';
7
7
  const attachShadowNativeFn = IN_BROWSER ? Element.prototype.attachShadow : () => new ShadowRoot();
8
8
  export default class TopObserver extends Observer {
@@ -1,4 +1,4 @@
1
- import { UserID, Metadata } from "../messages/index.js";
1
+ import { UserID, Metadata } from "../common/messages.js";
2
2
  var ActivityState;
3
3
  (function (ActivityState) {
4
4
  ActivityState[ActivityState["NotActive"] = 0] = "NotActive";
@@ -1,5 +1,5 @@
1
- import Message from "./message.js";
2
- import Writer from "./writer.js";
1
+ import type { Writer, Message } from "./types.js";
2
+ export default Message;
3
3
  export declare const classes: Map<number, Function>;
4
4
  declare class _BatchMeta implements Message {
5
5
  pageNo: number;
@@ -442,4 +442,3 @@ declare class _CreateIFrameDocument implements Message {
442
442
  encode(writer: Writer): boolean;
443
443
  }
444
444
  export declare const CreateIFrameDocument: typeof _CreateIFrameDocument & ((frameID: number, id: number) => _CreateIFrameDocument);
445
- export {};
File without changes