@openreplay/tracker 3.6.3 → 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 (95) hide show
  1. package/.eslintignore +8 -0
  2. package/cjs/app/guards.js +1 -2
  3. package/cjs/app/index.d.ts +15 -13
  4. package/cjs/app/index.js +56 -40
  5. package/cjs/app/logger.js +6 -3
  6. package/cjs/app/observer/iframe_observer.d.ts +1 -1
  7. package/cjs/app/observer/iframe_observer.js +1 -1
  8. package/cjs/app/observer/observer.d.ts +2 -3
  9. package/cjs/app/observer/observer.js +38 -40
  10. package/cjs/app/observer/shadow_root_observer.d.ts +1 -1
  11. package/cjs/app/observer/shadow_root_observer.js +1 -1
  12. package/cjs/app/observer/top_observer.d.ts +2 -2
  13. package/cjs/app/observer/top_observer.js +12 -11
  14. package/cjs/app/sanitizer.d.ts +1 -1
  15. package/cjs/app/sanitizer.js +5 -5
  16. package/cjs/app/session.d.ts +14 -2
  17. package/cjs/app/session.js +19 -6
  18. package/cjs/app/ticker.d.ts +1 -1
  19. package/cjs/common/messages.d.ts +1 -1
  20. package/cjs/common/messages.js +69 -120
  21. package/cjs/common/webworker.d.ts +3 -3
  22. package/cjs/index.d.ts +9 -8
  23. package/cjs/index.js +34 -28
  24. package/cjs/modules/connection.d.ts +1 -1
  25. package/cjs/modules/console.d.ts +1 -1
  26. package/cjs/modules/console.js +5 -5
  27. package/cjs/modules/cssrules.d.ts +1 -1
  28. package/cjs/modules/cssrules.js +3 -3
  29. package/cjs/modules/exception.d.ts +2 -2
  30. package/cjs/modules/exception.js +7 -6
  31. package/cjs/modules/img.d.ts +1 -1
  32. package/cjs/modules/img.js +15 -12
  33. package/cjs/modules/input.d.ts +1 -1
  34. package/cjs/modules/input.js +15 -15
  35. package/cjs/modules/longtasks.d.ts +1 -1
  36. package/cjs/modules/longtasks.js +13 -5
  37. package/cjs/modules/mouse.d.ts +1 -1
  38. package/cjs/modules/mouse.js +10 -12
  39. package/cjs/modules/performance.d.ts +1 -1
  40. package/cjs/modules/scroll.d.ts +1 -1
  41. package/cjs/modules/timing.d.ts +1 -1
  42. package/cjs/modules/timing.js +12 -24
  43. package/cjs/modules/viewport.d.ts +1 -1
  44. package/cjs/utils.js +7 -7
  45. package/cjs/vendors/finder/finder.js +53 -48
  46. package/lib/app/guards.js +1 -2
  47. package/lib/app/index.d.ts +15 -13
  48. package/lib/app/index.js +65 -49
  49. package/lib/app/logger.js +6 -3
  50. package/lib/app/observer/iframe_observer.d.ts +1 -1
  51. package/lib/app/observer/iframe_observer.js +3 -3
  52. package/lib/app/observer/observer.d.ts +2 -3
  53. package/lib/app/observer/observer.js +40 -42
  54. package/lib/app/observer/shadow_root_observer.d.ts +1 -1
  55. package/lib/app/observer/shadow_root_observer.js +3 -3
  56. package/lib/app/observer/top_observer.d.ts +2 -2
  57. package/lib/app/observer/top_observer.js +17 -16
  58. package/lib/app/sanitizer.d.ts +1 -1
  59. package/lib/app/sanitizer.js +7 -7
  60. package/lib/app/session.d.ts +14 -2
  61. package/lib/app/session.js +19 -6
  62. package/lib/app/ticker.d.ts +1 -1
  63. package/lib/common/messages.d.ts +1 -1
  64. package/lib/common/messages.js +69 -120
  65. package/lib/common/tsconfig.tsbuildinfo +1 -1
  66. package/lib/common/webworker.d.ts +3 -3
  67. package/lib/index.d.ts +9 -8
  68. package/lib/index.js +49 -43
  69. package/lib/modules/connection.d.ts +1 -1
  70. package/lib/modules/connection.js +1 -1
  71. package/lib/modules/console.d.ts +1 -1
  72. package/lib/modules/console.js +8 -8
  73. package/lib/modules/cssrules.d.ts +1 -1
  74. package/lib/modules/cssrules.js +5 -5
  75. package/lib/modules/exception.d.ts +2 -2
  76. package/lib/modules/exception.js +8 -7
  77. package/lib/modules/img.d.ts +1 -1
  78. package/lib/modules/img.js +18 -15
  79. package/lib/modules/input.d.ts +1 -1
  80. package/lib/modules/input.js +18 -18
  81. package/lib/modules/longtasks.d.ts +1 -1
  82. package/lib/modules/longtasks.js +14 -6
  83. package/lib/modules/mouse.d.ts +1 -1
  84. package/lib/modules/mouse.js +14 -16
  85. package/lib/modules/performance.d.ts +1 -1
  86. package/lib/modules/performance.js +2 -2
  87. package/lib/modules/scroll.d.ts +1 -1
  88. package/lib/modules/scroll.js +2 -2
  89. package/lib/modules/timing.d.ts +1 -1
  90. package/lib/modules/timing.js +15 -27
  91. package/lib/modules/viewport.d.ts +1 -1
  92. package/lib/modules/viewport.js +1 -1
  93. package/lib/utils.js +7 -7
  94. package/lib/vendors/finder/finder.js +53 -48
  95. package/package.json +28 -10
package/cjs/utils.js CHANGED
@@ -17,26 +17,26 @@ function isURL(s) {
17
17
  return s.startsWith('https://') || s.startsWith('http://');
18
18
  }
19
19
  exports.isURL = isURL;
20
- exports.IN_BROWSER = !(typeof window === "undefined");
20
+ exports.IN_BROWSER = !(typeof window === 'undefined');
21
21
  // TODO: JOIN IT WITH LOGGER somehow (use logging decorators?); Don't forget about index.js loggin when there is no logger instance.
22
22
  exports.DOCS_HOST = 'https://docs.openreplay.com';
23
23
  const warnedFeatures = {};
24
- function deprecationWarn(nameOfFeature, useInstead, docsPath = "/") {
24
+ function deprecationWarn(nameOfFeature, useInstead, docsPath = '/') {
25
25
  if (warnedFeatures[nameOfFeature]) {
26
26
  return;
27
27
  }
28
- console.warn(`OpenReplay: ${nameOfFeature} is deprecated. ${useInstead ? `Please, use ${useInstead} instead.` : ""} Visit ${exports.DOCS_HOST}${docsPath} for more information.`);
28
+ console.warn(`OpenReplay: ${nameOfFeature} is deprecated. ${useInstead ? `Please, use ${useInstead} instead.` : ''} Visit ${exports.DOCS_HOST}${docsPath} for more information.`);
29
29
  warnedFeatures[nameOfFeature] = true;
30
30
  }
31
31
  exports.deprecationWarn = deprecationWarn;
32
32
  function getLabelAttribute(e) {
33
- let value = e.getAttribute("data-openreplay-label");
33
+ let value = e.getAttribute('data-openreplay-label');
34
34
  if (value !== null) {
35
35
  return value;
36
36
  }
37
- value = e.getAttribute("data-asayer-label");
37
+ value = e.getAttribute('data-asayer-label');
38
38
  if (value !== null) {
39
- deprecationWarn(`"data-asayer-label" attribute`, `"data-openreplay-label" attribute`, "/");
39
+ deprecationWarn('"data-asayer-label" attribute', '"data-openreplay-label" attribute', '/');
40
40
  }
41
41
  return value;
42
42
  }
@@ -48,7 +48,7 @@ function hasOpenreplayAttribute(e, name) {
48
48
  }
49
49
  const oldName = `data-asayer-${name}`;
50
50
  if (e.hasAttribute(oldName)) {
51
- deprecationWarn(`"${oldName}" attribute`, `"${newName}" attribute`, "/installation/sanitize-data");
51
+ deprecationWarn(`"${oldName}" attribute`, `"${newName}" attribute`, '/installation/sanitize-data');
52
52
  return true;
53
53
  }
54
54
  return false;
@@ -11,10 +11,10 @@ let config;
11
11
  let rootDocument;
12
12
  function finder(input, options) {
13
13
  if (input.nodeType !== Node.ELEMENT_NODE) {
14
- throw new Error(`Can't generate CSS selector for non-element node type.`);
14
+ throw new Error("Can't generate CSS selector for non-element node type.");
15
15
  }
16
- if ("html" === input.tagName.toLowerCase()) {
17
- return "html";
16
+ if ('html' === input.tagName.toLowerCase()) {
17
+ return 'html';
18
18
  }
19
19
  const defaults = {
20
20
  root: document.body,
@@ -38,7 +38,7 @@ function finder(input, options) {
38
38
  return selector(path);
39
39
  }
40
40
  else {
41
- throw new Error(`Selector was not found.`);
41
+ throw new Error('Selector was not found.');
42
42
  }
43
43
  }
44
44
  exports.finder = finder;
@@ -53,30 +53,33 @@ function findRootDocument(rootNode, defaults) {
53
53
  }
54
54
  function bottomUpSearch(input, limit, fallback) {
55
55
  let path = null;
56
- let stack = [];
56
+ const stack = [];
57
57
  let current = input;
58
58
  let i = 0;
59
59
  while (current && current !== config.root.parentElement) {
60
- let level = maybe(id(current)) || maybe(...attr(current)) || maybe(...classNames(current)) || maybe(tagName(current)) || [any()];
60
+ let level = maybe(id(current)) ||
61
+ maybe(...attr(current)) ||
62
+ maybe(...classNames(current)) ||
63
+ maybe(tagName(current)) || [any()];
61
64
  const nth = index(current);
62
65
  if (limit === Limit.All) {
63
66
  if (nth) {
64
- level = level.concat(level.filter(dispensableNth).map(node => nthChild(node, nth)));
67
+ level = level.concat(level.filter(dispensableNth).map((node) => nthChild(node, nth)));
65
68
  }
66
69
  }
67
70
  else if (limit === Limit.Two) {
68
71
  level = level.slice(0, 1);
69
72
  if (nth) {
70
- level = level.concat(level.filter(dispensableNth).map(node => nthChild(node, nth)));
73
+ level = level.concat(level.filter(dispensableNth).map((node) => nthChild(node, nth)));
71
74
  }
72
75
  }
73
76
  else if (limit === Limit.One) {
74
- const [node] = level = level.slice(0, 1);
77
+ const [node] = (level = level.slice(0, 1));
75
78
  if (nth && dispensableNth(node)) {
76
79
  level = [nthChild(node, nth)];
77
80
  }
78
81
  }
79
- for (let node of level) {
82
+ for (const node of level) {
80
83
  node.level = i;
81
84
  }
82
85
  stack.push(level);
@@ -99,7 +102,7 @@ function findUniquePath(stack, fallback) {
99
102
  if (paths.length > config.threshold) {
100
103
  return fallback ? fallback() : null;
101
104
  }
102
- for (let candidate of paths) {
105
+ for (const candidate of paths) {
103
106
  if (unique(candidate)) {
104
107
  return candidate;
105
108
  }
@@ -122,7 +125,7 @@ function selector(path) {
122
125
  return query;
123
126
  }
124
127
  function penalty(path) {
125
- return path.map(node => node.penalty).reduce((acc, i) => acc + i, 0);
128
+ return path.map((node) => node.penalty).reduce((acc, i) => acc + i, 0);
126
129
  }
127
130
  function unique(path) {
128
131
  switch (rootDocument.querySelectorAll(selector(path)).length) {
@@ -135,10 +138,10 @@ function unique(path) {
135
138
  }
136
139
  }
137
140
  function id(input) {
138
- const elementId = input.getAttribute("id");
141
+ const elementId = input.getAttribute('id');
139
142
  if (elementId && config.idName(elementId)) {
140
143
  return {
141
- name: "#" + cssesc(elementId, { isIdentifier: true }),
144
+ name: '#' + cssesc(elementId, { isIdentifier: true }),
142
145
  penalty: 0,
143
146
  };
144
147
  }
@@ -147,16 +150,15 @@ function id(input) {
147
150
  function attr(input) {
148
151
  const attrs = Array.from(input.attributes).filter((attr) => config.attr(attr.name, attr.value));
149
152
  return attrs.map((attr) => ({
150
- name: "[" + cssesc(attr.name, { isIdentifier: true }) + "=\"" + cssesc(attr.value) + "\"]",
151
- penalty: 0.5
153
+ name: '[' + cssesc(attr.name, { isIdentifier: true }) + '="' + cssesc(attr.value) + '"]',
154
+ penalty: 0.5,
152
155
  }));
153
156
  }
154
157
  function classNames(input) {
155
- const names = Array.from(input.classList)
156
- .filter(config.className);
158
+ const names = Array.from(input.classList).filter(config.className);
157
159
  return names.map((name) => ({
158
- name: "." + cssesc(name, { isIdentifier: true }),
159
- penalty: 1
160
+ name: '.' + cssesc(name, { isIdentifier: true }),
161
+ penalty: 1,
160
162
  }));
161
163
  }
162
164
  function tagName(input) {
@@ -164,15 +166,15 @@ function tagName(input) {
164
166
  if (config.tagName(name)) {
165
167
  return {
166
168
  name,
167
- penalty: 2
169
+ penalty: 2,
168
170
  };
169
171
  }
170
172
  return null;
171
173
  }
172
174
  function any() {
173
175
  return {
174
- name: "*",
175
- penalty: 3
176
+ name: '*',
177
+ penalty: 3,
176
178
  };
177
179
  }
178
180
  function index(input) {
@@ -199,11 +201,11 @@ function index(input) {
199
201
  function nthChild(node, i) {
200
202
  return {
201
203
  name: node.name + `:nth-child(${i})`,
202
- penalty: node.penalty + 1
204
+ penalty: node.penalty + 1,
203
205
  };
204
206
  }
205
207
  function dispensableNth(node) {
206
- return node.name !== "html" && !node.name.startsWith("#");
208
+ return node.name !== 'html' && !node.name.startsWith('#');
207
209
  }
208
210
  function maybe(...level) {
209
211
  const list = level.filter(notEmpty);
@@ -218,7 +220,7 @@ function notEmpty(value) {
218
220
  function combinations(stack, path = []) {
219
221
  const paths = [];
220
222
  if (stack.length > 0) {
221
- for (let node of stack[0]) {
223
+ for (const node of stack[0]) {
222
224
  paths.push(...combinations(stack.slice(1, stack.length), path.concat(node)));
223
225
  }
224
226
  }
@@ -232,7 +234,7 @@ function sort(paths) {
232
234
  }
233
235
  function optimize(path, input, scope = {
234
236
  counter: 0,
235
- visited: new Map()
237
+ visited: new Map(),
236
238
  }) {
237
239
  const paths = [];
238
240
  if (path.length > 2 && path.length > config.optimizedMinLength) {
@@ -263,20 +265,20 @@ const regexAnySingleEscape = /[ -,\.\/:-@\[-\^`\{-~]/;
263
265
  const regexSingleEscape = /[ -,\.\/:-@\[\]\^`\{-~]/;
264
266
  const regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
265
267
  const defaultOptions = {
266
- "escapeEverything": false,
267
- "isIdentifier": false,
268
- "quotes": "single",
269
- "wrap": false
268
+ escapeEverything: false,
269
+ isIdentifier: false,
270
+ quotes: 'single',
271
+ wrap: false,
270
272
  };
271
273
  function cssesc(string, opt = {}) {
272
274
  const options = Object.assign(Object.assign({}, defaultOptions), opt);
273
- if (options.quotes != "single" && options.quotes != "double") {
274
- options.quotes = "single";
275
+ if (options.quotes != 'single' && options.quotes != 'double') {
276
+ options.quotes = 'single';
275
277
  }
276
- const quote = options.quotes == "double" ? "\"" : "'";
278
+ const quote = options.quotes == 'double' ? '"' : "'";
277
279
  const isIdentifier = options.isIdentifier;
278
280
  const firstChar = string.charAt(0);
279
- let output = "";
281
+ let output = '';
280
282
  let counter = 0;
281
283
  const length = string.length;
282
284
  while (counter < length) {
@@ -284,13 +286,13 @@ function cssesc(string, opt = {}) {
284
286
  let codePoint = character.charCodeAt(0);
285
287
  let value = void 0;
286
288
  // If it’s not a printable ASCII character…
287
- if (codePoint < 0x20 || codePoint > 0x7E) {
288
- if (codePoint >= 0xD800 && codePoint <= 0xDBFF && counter < length) {
289
+ if (codePoint < 0x20 || codePoint > 0x7e) {
290
+ if (codePoint >= 0xd800 && codePoint <= 0xdbff && counter < length) {
289
291
  // It’s a high surrogate, and there is a next character.
290
292
  const extra = string.charCodeAt(counter++);
291
- if ((extra & 0xFC00) == 0xDC00) {
293
+ if ((extra & 0xfc00) == 0xdc00) {
292
294
  // next character is low surrogate
293
- codePoint = ((codePoint & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
295
+ codePoint = ((codePoint & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000;
294
296
  }
295
297
  else {
296
298
  // It’s an unmatched surrogate; only append this code unit, in case
@@ -298,22 +300,25 @@ function cssesc(string, opt = {}) {
298
300
  counter--;
299
301
  }
300
302
  }
301
- value = "\\" + codePoint.toString(16).toUpperCase() + " ";
303
+ value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
302
304
  }
303
305
  else {
304
306
  if (options.escapeEverything) {
305
307
  if (regexAnySingleEscape.test(character)) {
306
- value = "\\" + character;
308
+ value = '\\' + character;
307
309
  }
308
310
  else {
309
- value = "\\" + codePoint.toString(16).toUpperCase() + " ";
311
+ value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
310
312
  }
311
313
  }
312
314
  else if (/[\t\n\f\r\x0B]/.test(character)) {
313
- value = "\\" + codePoint.toString(16).toUpperCase() + " ";
315
+ value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
314
316
  }
315
- else if (character == "\\" || !isIdentifier && (character == "\"" && quote == character || character == "'" && quote == character) || isIdentifier && regexSingleEscape.test(character)) {
316
- value = "\\" + character;
317
+ else if (character == '\\' ||
318
+ (!isIdentifier &&
319
+ ((character == '"' && quote == character) || (character == "'" && quote == character))) ||
320
+ (isIdentifier && regexSingleEscape.test(character))) {
321
+ value = '\\' + character;
317
322
  }
318
323
  else {
319
324
  value = character;
@@ -323,10 +328,10 @@ function cssesc(string, opt = {}) {
323
328
  }
324
329
  if (isIdentifier) {
325
330
  if (/^-[-\d]/.test(output)) {
326
- output = "\\-" + output.slice(1);
331
+ output = '\\-' + output.slice(1);
327
332
  }
328
333
  else if (/\d/.test(firstChar)) {
329
- output = "\\3" + firstChar + " " + output.slice(1);
334
+ output = '\\3' + firstChar + ' ' + output.slice(1);
330
335
  }
331
336
  }
332
337
  // Remove spaces after `\HEX` escapes that are not followed by a hex digit,
@@ -338,7 +343,7 @@ function cssesc(string, opt = {}) {
338
343
  return $0;
339
344
  }
340
345
  // Strip the space.
341
- return ($1 || "") + $2;
346
+ return ($1 || '') + $2;
342
347
  });
343
348
  if (!isIdentifier && options.wrap) {
344
349
  return quote + output + quote;
package/lib/app/guards.js CHANGED
@@ -8,8 +8,7 @@ export function isTextNode(node) {
8
8
  return node.nodeType === Node.TEXT_NODE;
9
9
  }
10
10
  export function isRootNode(node) {
11
- return node.nodeType === Node.DOCUMENT_NODE ||
12
- node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
11
+ return node.nodeType === Node.DOCUMENT_NODE || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
13
12
  }
14
13
  export function hasTag(el, tagName) {
15
14
  return el.nodeName === tagName;
@@ -1,13 +1,13 @@
1
- import type Message from "../common/messages.js";
2
- import Nodes from "./nodes.js";
3
- import Sanitizer from "./sanitizer.js";
4
- import Ticker from "./ticker.js";
5
- import Logger from "./logger.js";
6
- import Session from "./session.js";
7
- import type { Options as ObserverOptions } from "./observer/top_observer.js";
8
- import type { Options as SanitizerOptions } from "./sanitizer.js";
9
- import type { Options as LoggerOptions } from "./logger.js";
10
- import type { Options as WebworkerOptions } from "../common/webworker.js";
1
+ import type Message from '../common/messages.js';
2
+ import Nodes from './nodes.js';
3
+ import Sanitizer from './sanitizer.js';
4
+ import Ticker from './ticker.js';
5
+ import Logger from './logger.js';
6
+ import Session from './session.js';
7
+ import type { Options as ObserverOptions } from './observer/top_observer.js';
8
+ import type { Options as SanitizerOptions } from './sanitizer.js';
9
+ import type { Options as LoggerOptions } from './logger.js';
10
+ import type { Options as WebworkerOptions } from '../common/webworker.js';
11
11
  export interface StartOptions {
12
12
  userID?: string;
13
13
  metadata?: Record<string, string>;
@@ -68,7 +68,7 @@ export default class App {
68
68
  private readonly options;
69
69
  private readonly revID;
70
70
  private activityState;
71
- private version;
71
+ private readonly version;
72
72
  private readonly worker?;
73
73
  constructor(projectKey: string, sessionToken: string | null | undefined, options: Partial<Options>);
74
74
  private _debug;
@@ -77,7 +77,7 @@ export default class App {
77
77
  safe<T extends (...args: any[]) => void>(fn: T): T;
78
78
  attachCommitCallback(cb: CommitCallback): void;
79
79
  attachStartCallback(cb: StartCallback): void;
80
- attachStopCallback(cb: Function): void;
80
+ attachStopCallback(cb: () => any): void;
81
81
  attachEventListener(target: EventTarget, type: string, listener: EventListener, useSafe?: boolean, useCapture?: boolean): void;
82
82
  checkRequiredVersion(version: string): boolean;
83
83
  private getStartInfo;
@@ -88,12 +88,14 @@ export default class App {
88
88
  timestamp: number;
89
89
  trackerVersion: string;
90
90
  isSnippet: boolean;
91
- sessionID: string | null;
91
+ sessionID: string | undefined;
92
92
  metadata: Record<string, string>;
93
93
  userID: string | null;
94
+ projectID?: string | undefined;
94
95
  };
95
96
  getSessionToken(): string | undefined;
96
97
  getSessionID(): string | undefined;
98
+ getSessionURL(): string | undefined;
97
99
  getHost(): string;
98
100
  getProjectKey(): string;
99
101
  getBaseHref(): string;