@openreplay/tracker 3.6.1 → 3.6.2

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 (128) hide show
  1. package/LICENSE +1 -1
  2. package/cjs/app/guards.d.ts +1 -2
  3. package/cjs/app/guards.js +3 -6
  4. package/cjs/app/index.d.ts +23 -28
  5. package/cjs/app/index.js +86 -107
  6. package/cjs/app/logger.js +3 -6
  7. package/cjs/app/nodes.d.ts +1 -1
  8. package/cjs/app/nodes.js +0 -2
  9. package/cjs/app/observer/iframe_observer.d.ts +1 -1
  10. package/cjs/app/observer/iframe_observer.js +3 -3
  11. package/cjs/app/observer/observer.d.ts +3 -2
  12. package/cjs/app/observer/observer.js +52 -50
  13. package/cjs/app/observer/shadow_root_observer.d.ts +1 -1
  14. package/cjs/app/observer/shadow_root_observer.js +3 -3
  15. package/cjs/app/observer/top_observer.d.ts +2 -13
  16. package/cjs/app/observer/top_observer.js +23 -58
  17. package/cjs/app/sanitizer.d.ts +1 -1
  18. package/cjs/app/sanitizer.js +5 -5
  19. package/cjs/app/session.d.ts +2 -20
  20. package/cjs/app/session.js +6 -65
  21. package/cjs/app/ticker.d.ts +1 -1
  22. package/cjs/common/messages.d.ts +444 -0
  23. package/cjs/common/messages.js +794 -0
  24. package/cjs/common/types.d.ts +9 -0
  25. package/cjs/common/{interaction.js → types.js} +0 -0
  26. package/cjs/common/{interaction.d.ts → webworker.d.ts} +5 -5
  27. package/cjs/common/{messages.gen.js → webworker.js} +0 -1
  28. package/cjs/index.d.ts +9 -10
  29. package/cjs/index.js +36 -47
  30. package/cjs/modules/connection.d.ts +1 -1
  31. package/cjs/modules/connection.js +2 -2
  32. package/cjs/modules/console.d.ts +1 -1
  33. package/cjs/modules/console.js +21 -7
  34. package/cjs/modules/cssrules.d.ts +1 -1
  35. package/cjs/modules/cssrules.js +14 -18
  36. package/cjs/modules/exception.d.ts +3 -3
  37. package/cjs/modules/exception.js +18 -23
  38. package/cjs/modules/img.d.ts +1 -1
  39. package/cjs/modules/img.js +26 -39
  40. package/cjs/modules/input.d.ts +1 -1
  41. package/cjs/modules/input.js +21 -21
  42. package/cjs/modules/longtasks.d.ts +2 -0
  43. package/cjs/modules/longtasks.js +26 -0
  44. package/cjs/modules/mouse.d.ts +1 -1
  45. package/cjs/modules/mouse.js +43 -50
  46. package/cjs/modules/performance.d.ts +1 -1
  47. package/cjs/modules/performance.js +2 -2
  48. package/cjs/modules/scroll.d.ts +1 -1
  49. package/cjs/modules/scroll.js +7 -16
  50. package/cjs/modules/timing.d.ts +1 -1
  51. package/cjs/modules/timing.js +26 -14
  52. package/cjs/modules/viewport.d.ts +1 -1
  53. package/cjs/modules/viewport.js +4 -4
  54. package/cjs/utils.js +7 -7
  55. package/cjs/vendors/finder/finder.js +48 -53
  56. package/lib/app/guards.d.ts +1 -2
  57. package/lib/app/guards.js +2 -4
  58. package/lib/app/index.d.ts +23 -28
  59. package/lib/app/index.js +94 -115
  60. package/lib/app/logger.js +3 -6
  61. package/lib/app/nodes.d.ts +1 -1
  62. package/lib/app/nodes.js +0 -2
  63. package/lib/app/observer/iframe_observer.d.ts +1 -1
  64. package/lib/app/observer/iframe_observer.js +3 -3
  65. package/lib/app/observer/observer.d.ts +3 -2
  66. package/lib/app/observer/observer.js +53 -51
  67. package/lib/app/observer/shadow_root_observer.d.ts +1 -1
  68. package/lib/app/observer/shadow_root_observer.js +3 -3
  69. package/lib/app/observer/top_observer.d.ts +2 -13
  70. package/lib/app/observer/top_observer.js +27 -62
  71. package/lib/app/sanitizer.d.ts +1 -1
  72. package/lib/app/sanitizer.js +7 -7
  73. package/lib/app/session.d.ts +2 -20
  74. package/lib/app/session.js +6 -65
  75. package/lib/app/ticker.d.ts +1 -1
  76. package/lib/common/messages.d.ts +444 -0
  77. package/lib/common/messages.js +790 -0
  78. package/lib/common/tsconfig.tsbuildinfo +1 -1
  79. package/lib/common/types.d.ts +9 -0
  80. package/lib/common/{interaction.js → types.js} +0 -0
  81. package/lib/common/{interaction.d.ts → webworker.d.ts} +5 -5
  82. package/lib/common/webworker.js +1 -0
  83. package/lib/index.d.ts +9 -10
  84. package/lib/index.js +49 -60
  85. package/lib/modules/connection.d.ts +1 -1
  86. package/lib/modules/connection.js +2 -2
  87. package/lib/modules/console.d.ts +1 -1
  88. package/lib/modules/console.js +22 -8
  89. package/lib/modules/cssrules.d.ts +1 -1
  90. package/lib/modules/cssrules.js +15 -19
  91. package/lib/modules/exception.d.ts +3 -3
  92. package/lib/modules/exception.js +18 -23
  93. package/lib/modules/img.d.ts +1 -1
  94. package/lib/modules/img.js +28 -41
  95. package/lib/modules/input.d.ts +1 -1
  96. package/lib/modules/input.js +23 -23
  97. package/lib/modules/longtasks.d.ts +2 -0
  98. package/lib/modules/longtasks.js +23 -0
  99. package/lib/modules/mouse.d.ts +1 -1
  100. package/lib/modules/mouse.js +46 -53
  101. package/lib/modules/performance.d.ts +1 -1
  102. package/lib/modules/performance.js +3 -3
  103. package/lib/modules/scroll.d.ts +1 -1
  104. package/lib/modules/scroll.js +8 -17
  105. package/lib/modules/timing.d.ts +1 -1
  106. package/lib/modules/timing.js +28 -16
  107. package/lib/modules/viewport.d.ts +1 -1
  108. package/lib/modules/viewport.js +4 -4
  109. package/lib/utils.js +7 -7
  110. package/lib/vendors/finder/finder.js +48 -53
  111. package/package.json +10 -27
  112. package/.eslintignore +0 -8
  113. package/.prettierignore +0 -1
  114. package/cjs/app/messages.d.ts +0 -52
  115. package/cjs/app/messages.gen.d.ts +0 -57
  116. package/cjs/app/messages.gen.js +0 -493
  117. package/cjs/app/messages.js +0 -234
  118. package/cjs/common/messages.gen.d.ts +0 -382
  119. package/cjs/modules/adoptedStyleSheets.d.ts +0 -2
  120. package/cjs/modules/adoptedStyleSheets.js +0 -127
  121. package/lib/app/messages.d.ts +0 -52
  122. package/lib/app/messages.gen.d.ts +0 -57
  123. package/lib/app/messages.gen.js +0 -434
  124. package/lib/app/messages.js +0 -181
  125. package/lib/common/messages.gen.d.ts +0 -382
  126. package/lib/common/messages.gen.js +0 -2
  127. package/lib/modules/adoptedStyleSheets.d.ts +0 -2
  128. package/lib/modules/adoptedStyleSheets.js +0 -124
@@ -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 messages_gen_js_1 = require("../app/messages.gen.js");
4
+ const messages_js_1 = require("../common/messages.js");
5
5
  const guards_js_1 = require("../app/guards.js");
6
6
  function resolveURL(url, location = document.location) {
7
7
  url = url.trim();
@@ -18,34 +18,19 @@ function resolveURL(url, location = document.location) {
18
18
  return location.origin + location.pathname + url;
19
19
  }
20
20
  }
21
- const PLACEHOLDER_SRC = 'https://static.openreplay.com/tracker/placeholder.jpeg';
21
+ const PLACEHOLDER_SRC = "https://static.openreplay.com/tracker/placeholder.jpeg";
22
22
  function default_1(app) {
23
23
  function sendPlaceholder(id, node) {
24
- app.send((0, messages_gen_js_1.SetNodeAttribute)(id, 'src', PLACEHOLDER_SRC));
24
+ app.send(new messages_js_1.SetNodeAttribute(id, "src", PLACEHOLDER_SRC));
25
25
  const { width, height } = node.getBoundingClientRect();
26
- if (!node.hasAttribute('width')) {
27
- app.send((0, messages_gen_js_1.SetNodeAttribute)(id, 'width', String(width)));
26
+ if (!node.hasAttribute("width")) {
27
+ app.send(new messages_js_1.SetNodeAttribute(id, "width", String(width)));
28
28
  }
29
- if (!node.hasAttribute('height')) {
30
- app.send((0, messages_gen_js_1.SetNodeAttribute)(id, 'height', String(height)));
29
+ if (!node.hasAttribute("height")) {
30
+ app.send(new messages_js_1.SetNodeAttribute(id, "height", String(height)));
31
31
  }
32
32
  }
33
- const sendSrcset = function (id, img) {
34
- const { srcset } = img;
35
- if (!srcset) {
36
- return;
37
- }
38
- const resolvedSrcset = srcset
39
- .split(',')
40
- .map((str) => resolveURL(str))
41
- .join(',');
42
- app.send((0, messages_gen_js_1.SetNodeAttribute)(id, 'srcset', resolvedSrcset));
43
- };
44
- const sendSrc = function (id, img) {
45
- const src = img.src;
46
- app.send((0, messages_gen_js_1.SetNodeAttributeURLBased)(id, 'src', src, app.getBaseHref()));
47
- };
48
- const sendImgAttrs = app.safe(function () {
33
+ const sendImgSrc = app.safe(function () {
49
34
  const id = app.nodes.getID(this);
50
35
  if (id === undefined) {
51
36
  return;
@@ -57,45 +42,47 @@ function default_1(app) {
57
42
  const resolvedSrc = resolveURL(src || ''); // Src type is null sometimes. - is it true?
58
43
  if (naturalWidth === 0 && naturalHeight === 0) {
59
44
  if ((0, utils_js_1.isURL)(resolvedSrc)) {
60
- app.send((0, messages_gen_js_1.ResourceTiming)((0, utils_js_1.timestamp)(), 0, 0, 0, 0, 0, resolvedSrc, 'img'));
45
+ app.send(new messages_js_1.ResourceTiming((0, utils_js_1.timestamp)(), 0, 0, 0, 0, 0, resolvedSrc, 'img'));
61
46
  }
62
47
  }
63
48
  else if (resolvedSrc.length >= 1e5 || app.sanitizer.isMasked(id)) {
64
49
  sendPlaceholder(id, this);
65
50
  }
66
51
  else {
67
- sendSrc(id, this);
68
- sendSrcset(id, this);
52
+ app.send(new messages_js_1.SetNodeAttribute(id, 'src', resolvedSrc));
53
+ if (srcset) {
54
+ const resolvedSrcset = srcset.split(',').map(str => resolveURL(str)).join(',');
55
+ app.send(new messages_js_1.SetNodeAttribute(id, 'srcset', resolvedSrcset));
56
+ }
69
57
  }
70
58
  });
71
59
  const observer = new MutationObserver((mutations) => {
72
60
  for (const mutation of mutations) {
73
- if (mutation.type === 'attributes') {
61
+ if (mutation.type === "attributes") {
74
62
  const target = mutation.target;
75
63
  const id = app.nodes.getID(target);
76
64
  if (id === undefined) {
77
65
  return;
78
66
  }
79
- if (mutation.attributeName === 'src') {
80
- sendSrc(id, target);
67
+ if (mutation.attributeName === "src") {
68
+ const src = target.src;
69
+ app.send(new messages_js_1.SetNodeAttributeURLBased(id, 'src', src, app.getBaseHref()));
81
70
  }
82
- if (mutation.attributeName === 'srcset') {
83
- sendSrcset(id, target);
71
+ if (mutation.attributeName === "srcset") {
72
+ const srcset = target.srcset;
73
+ app.send(new messages_js_1.SetNodeAttribute(id, 'srcset', srcset));
84
74
  }
85
75
  }
86
76
  }
87
77
  });
88
- app.attachStopCallback(() => {
89
- observer.disconnect();
90
- });
91
78
  app.nodes.attachNodeCallback((node) => {
92
- if (!(0, guards_js_1.hasTag)(node, 'IMG')) {
79
+ if (!(0, guards_js_1.hasTag)(node, "IMG")) {
93
80
  return;
94
81
  }
95
- app.nodes.attachElementListener('error', node, sendImgAttrs.bind(node));
96
- app.nodes.attachElementListener('load', node, sendImgAttrs.bind(node));
97
- sendImgAttrs.call(node);
98
- observer.observe(node, { attributes: true, attributeFilter: ['src', 'srcset'] });
82
+ app.nodes.attachElementListener('error', node, sendImgSrc);
83
+ app.nodes.attachElementListener('load', node, sendImgSrc);
84
+ sendImgSrc.call(node);
85
+ observer.observe(node, { attributes: true, attributeFilter: ["src", "srcset"] });
99
86
  });
100
87
  }
101
88
  exports.default = default_1;
@@ -1,4 +1,4 @@
1
- import type App from '../app/index.js';
1
+ import type App from "../app/index.js";
2
2
  declare type TextEditableElement = HTMLInputElement | HTMLTextAreaElement;
3
3
  export declare function getInputLabel(node: TextEditableElement): string;
4
4
  export declare const enum InputMode {
@@ -3,19 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getInputLabel = void 0;
4
4
  const utils_js_1 = require("../utils.js");
5
5
  const guards_js_1 = require("../app/guards.js");
6
- const messages_gen_js_1 = require("../app/messages.gen.js");
6
+ const messages_js_1 = require("../common/messages.js");
7
7
  const INPUT_TYPES = ['text', 'password', 'email', 'search', 'number', 'range', 'date'];
8
8
  function isTextEditable(node) {
9
- if ((0, guards_js_1.hasTag)(node, 'TEXTAREA')) {
9
+ if ((0, guards_js_1.hasTag)(node, "TEXTAREA")) {
10
10
  return true;
11
11
  }
12
- if (!(0, guards_js_1.hasTag)(node, 'INPUT')) {
12
+ if (!(0, guards_js_1.hasTag)(node, "INPUT")) {
13
13
  return false;
14
14
  }
15
15
  return INPUT_TYPES.includes(node.type);
16
16
  }
17
17
  function isCheckable(node) {
18
- if (!(0, guards_js_1.hasTag)(node, 'INPUT')) {
18
+ if (!(0, guards_js_1.hasTag)(node, "INPUT")) {
19
19
  return false;
20
20
  }
21
21
  const type = node.type;
@@ -25,7 +25,7 @@ const labelElementFor = utils_js_1.IN_BROWSER && 'labels' in HTMLInputElement.pr
25
25
  ? (node) => {
26
26
  let p = node;
27
27
  while ((p = p.parentNode) !== null) {
28
- if ((0, guards_js_1.hasTag)(p, 'LABEL')) {
28
+ if ((0, guards_js_1.hasTag)(p, "LABEL")) {
29
29
  return p;
30
30
  }
31
31
  }
@@ -37,13 +37,13 @@ const labelElementFor = utils_js_1.IN_BROWSER && 'labels' in HTMLInputElement.pr
37
37
  : (node) => {
38
38
  let p = node;
39
39
  while ((p = p.parentNode) !== null) {
40
- if ((0, guards_js_1.hasTag)(p, 'LABEL')) {
40
+ if ((0, guards_js_1.hasTag)(p, "LABEL")) {
41
41
  return p;
42
42
  }
43
43
  }
44
44
  const id = node.id;
45
45
  if (id) {
46
- const labels = node.ownerDocument.querySelectorAll('label[for="' + id + '"]');
46
+ const labels = document.querySelectorAll('label[for="' + id + '"]');
47
47
  if (labels !== null && labels.length === 1) {
48
48
  return labels[0];
49
49
  }
@@ -53,13 +53,12 @@ function getInputLabel(node) {
53
53
  let label = (0, utils_js_1.getLabelAttribute)(node);
54
54
  if (label === null) {
55
55
  const labelElement = labelElementFor(node);
56
- label =
57
- (labelElement && labelElement.innerText) ||
58
- node.placeholder ||
59
- node.name ||
60
- node.id ||
61
- node.className ||
62
- node.type;
56
+ label = (labelElement && labelElement.innerText)
57
+ || node.placeholder
58
+ || node.name
59
+ || node.id
60
+ || node.className
61
+ || node.type;
63
62
  }
64
63
  return (0, utils_js_1.normSpaces)(label).slice(0, 100);
65
64
  }
@@ -74,7 +73,7 @@ function default_1(app, opts) {
74
73
  function sendInputTarget(id, node) {
75
74
  const label = getInputLabel(node);
76
75
  if (label !== '') {
77
- app.send((0, messages_gen_js_1.SetInputTarget)(id, label));
76
+ app.send(new messages_js_1.SetInputTarget(id, label));
78
77
  }
79
78
  }
80
79
  function sendInputValue(id, node) {
@@ -87,7 +86,8 @@ function default_1(app, opts) {
87
86
  (inputMode === 0 /* Plain */ &&
88
87
  ((options.obscureInputNumbers && node.type !== 'date' && /\d\d\d\d/.test(value)) ||
89
88
  (options.obscureInputDates && node.type === 'date') ||
90
- (options.obscureInputEmails && (node.type === 'email' || !!~value.indexOf('@')))))) {
89
+ (options.obscureInputEmails &&
90
+ (node.type === 'email' || !!~value.indexOf('@')))))) {
91
91
  inputMode = 1 /* Obscured */;
92
92
  }
93
93
  let mask = 0;
@@ -101,7 +101,7 @@ function default_1(app, opts) {
101
101
  value = '';
102
102
  break;
103
103
  }
104
- app.send((0, messages_gen_js_1.SetInputValue)(id, value, mask));
104
+ app.send(new messages_js_1.SetInputValue(id, value, mask));
105
105
  }
106
106
  const inputValues = new Map();
107
107
  const checkableValues = new Map();
@@ -139,7 +139,7 @@ function default_1(app, opts) {
139
139
  }
140
140
  if (checked !== node.checked) {
141
141
  checkableValues.set(id, node.checked);
142
- app.send((0, messages_gen_js_1.SetInputChecked)(id, node.checked));
142
+ app.send(new messages_js_1.SetInputChecked(id, node.checked));
143
143
  }
144
144
  });
145
145
  });
@@ -150,9 +150,9 @@ function default_1(app, opts) {
150
150
  return;
151
151
  }
152
152
  // TODO: support multiple select (?): use selectedOptions; Need send target?
153
- if ((0, guards_js_1.hasTag)(node, 'SELECT')) {
153
+ if ((0, guards_js_1.hasTag)(node, "SELECT")) {
154
154
  sendInputValue(id, node);
155
- app.attachEventListener(node, 'change', () => {
155
+ app.attachEventListener(node, "change", () => {
156
156
  sendInputValue(id, node);
157
157
  });
158
158
  }
@@ -163,7 +163,7 @@ function default_1(app, opts) {
163
163
  }
164
164
  if (isCheckable(node)) {
165
165
  checkableValues.set(id, node.checked);
166
- app.send((0, messages_gen_js_1.SetInputChecked)(id, node.checked));
166
+ app.send(new messages_js_1.SetInputChecked(id, node.checked));
167
167
  return;
168
168
  }
169
169
  }));
@@ -0,0 +1,2 @@
1
+ import type App from "../app/index.js";
2
+ export default function (app: App): void;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const messages_js_1 = require("../common/messages.js");
4
+ ;
5
+ ;
6
+ function default_1(app) {
7
+ if (!('PerformanceObserver' in window) || !('PerformanceLongTaskTiming' in window)) {
8
+ return;
9
+ }
10
+ const contexts = ["unknown", "self", "same-origin-ancestor", "same-origin-descendant", "same-origin", "cross-origin-ancestor", "cross-origin-descendant", "cross-origin-unreachable", "multiple-contexts"];
11
+ const containerTypes = ["window", "iframe", "embed", "object"];
12
+ function longTask(entry) {
13
+ let type = "", src = "", id = "", name = "";
14
+ const container = entry.attribution[0];
15
+ if (container != null) {
16
+ type = container.containerType;
17
+ name = container.containerName;
18
+ id = container.containerId;
19
+ src = container.containerSrc;
20
+ }
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
+ }
23
+ const observer = new PerformanceObserver((list) => list.getEntries().forEach(longTask));
24
+ observer.observe({ entryTypes: ['longtask'] });
25
+ }
26
+ exports.default = default_1;
@@ -1,2 +1,2 @@
1
- import type App from '../app/index.js';
1
+ import type App from "../app/index.js";
2
2
  export default function (app: App): void;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const guards_js_1 = require("../app/guards.js");
4
4
  const utils_js_1 = require("../utils.js");
5
- const messages_gen_js_1 = require("../app/messages.gen.js");
5
+ const messages_js_1 = require("../common/messages.js");
6
6
  const input_js_1 = require("./input.js");
7
- function _getSelector(target, document) {
7
+ function _getSelector(target) {
8
8
  let el = target;
9
9
  let selector = null;
10
10
  do {
@@ -12,10 +12,9 @@ function _getSelector(target, document) {
12
12
  return `#${el.id}` + (selector ? ` > ${selector}` : '');
13
13
  }
14
14
  selector =
15
- el.className
16
- .split(' ')
17
- .map((cn) => cn.trim())
18
- .filter((cn) => cn !== '')
15
+ el.className.split(' ')
16
+ .map(cn => cn.trim())
17
+ .filter(cn => cn !== '')
19
18
  .reduce((sel, cn) => `${sel}.${cn}`, el.tagName.toLowerCase()) +
20
19
  (selector ? ` > ${selector}` : '');
21
20
  if (el === document.body) {
@@ -27,23 +26,23 @@ function _getSelector(target, document) {
27
26
  }
28
27
  function isClickable(element) {
29
28
  const tag = element.tagName.toUpperCase();
30
- return (tag === 'BUTTON' ||
29
+ return tag === 'BUTTON' ||
31
30
  tag === 'A' ||
32
31
  tag === 'LI' ||
33
32
  tag === 'SELECT' ||
34
33
  element.onclick != null ||
35
- element.getAttribute('role') === 'button');
34
+ element.getAttribute('role') === 'button';
36
35
  //|| element.className.includes("btn")
37
- // MBTODO: intersept addEventListener
36
+ // MBTODO: intersect addEventListener
38
37
  }
39
- //TODO: fix (typescript is not sure about target variable after assignation of svg)
40
- function getTarget(target, document) {
38
+ //TODO: fix (typescript doesn't allow work when the guard is inside the function)
39
+ function getTarget(target) {
41
40
  if (target instanceof Element) {
42
- return _getTarget(target, document);
41
+ return _getTarget(target);
43
42
  }
44
43
  return null;
45
44
  }
46
- function _getTarget(target, document) {
45
+ function _getTarget(target) {
47
46
  let element = target;
48
47
  while (element !== null && element !== document.documentElement) {
49
48
  if ((0, utils_js_1.hasOpenreplayAttribute)(element, 'masked')) {
@@ -67,7 +66,8 @@ function _getTarget(target, document) {
67
66
  if (tag === 'INPUT') {
68
67
  return element;
69
68
  }
70
- if (isClickable(element) || (0, utils_js_1.getLabelAttribute)(element) !== null) {
69
+ if (isClickable(element) ||
70
+ (0, utils_js_1.getLabelAttribute)(element) !== null) {
71
71
  return element;
72
72
  }
73
73
  element = element.parentElement;
@@ -80,7 +80,7 @@ function default_1(app) {
80
80
  if (dl !== null) {
81
81
  return dl;
82
82
  }
83
- if ((0, guards_js_1.hasTag)(target, 'INPUT')) {
83
+ if ((0, guards_js_1.hasTag)(target, "INPUT")) {
84
84
  return (0, input_js_1.getInputLabel)(target);
85
85
  }
86
86
  if (isClickable(target)) {
@@ -106,47 +106,40 @@ function default_1(app) {
106
106
  });
107
107
  const sendMouseMove = () => {
108
108
  if (mousePositionChanged) {
109
- app.send((0, messages_gen_js_1.MouseMove)(mousePositionX, mousePositionY));
109
+ app.send(new messages_js_1.MouseMove(mousePositionX, mousePositionY));
110
110
  mousePositionChanged = false;
111
111
  }
112
112
  };
113
- const patchDocument = (document) => {
114
- const selectorMap = {};
115
- function getSelector(id, target) {
116
- return (selectorMap[id] = selectorMap[id] || _getSelector(target, document));
113
+ const selectorMap = {};
114
+ function getSelector(id, target) {
115
+ return selectorMap[id] = selectorMap[id] || _getSelector(target);
116
+ }
117
+ app.attachEventListener(document.documentElement, 'mouseover', (e) => {
118
+ const target = getTarget(e.target);
119
+ if (target !== mouseTarget) {
120
+ mouseTarget = target;
121
+ mouseTargetTime = performance.now();
117
122
  }
118
- app.attachEventListener(document.documentElement, 'mouseover', (e) => {
119
- const target = getTarget(e.target, document);
120
- if (target !== mouseTarget) {
121
- mouseTarget = target;
122
- mouseTargetTime = performance.now();
123
- }
124
- });
125
- app.attachEventListener(document, 'mousemove', (e) => {
126
- const { top, left } = app.observer.getDocumentOffset(document);
127
- mousePositionX = e.clientX + left;
128
- mousePositionY = e.clientY + top;
129
- mousePositionChanged = true;
130
- }, false);
131
- app.attachEventListener(document, 'click', (e) => {
132
- const target = getTarget(e.target, document);
133
- if ((!e.clientX && !e.clientY) || target === null) {
134
- return;
135
- }
136
- const id = app.nodes.getID(target);
137
- if (id !== undefined) {
138
- sendMouseMove();
139
- app.send((0, messages_gen_js_1.MouseClick)(id, mouseTarget === target ? Math.round(performance.now() - mouseTargetTime) : 0, getTargetLabel(target), getSelector(id, target)), true);
140
- }
141
- mouseTarget = null;
142
- });
143
- };
144
- app.nodes.attachNodeCallback((node) => {
145
- if ((0, guards_js_1.isDocument)(node)) {
146
- patchDocument(node);
123
+ });
124
+ app.attachEventListener(document, 'mousemove', (e) => {
125
+ mousePositionX = e.clientX;
126
+ mousePositionY = e.clientY;
127
+ mousePositionChanged = true;
128
+ }, false);
129
+ app.attachEventListener(document, 'click', (e) => {
130
+ const target = getTarget(e.target);
131
+ if ((!e.clientX && !e.clientY) || target === null) {
132
+ return;
147
133
  }
134
+ const id = app.nodes.getID(target);
135
+ if (id !== undefined) {
136
+ sendMouseMove();
137
+ app.send(new messages_js_1.MouseClick(id, mouseTarget === target
138
+ ? Math.round(performance.now() - mouseTargetTime)
139
+ : 0, getTargetLabel(target), getSelector(id, target)), true);
140
+ }
141
+ mouseTarget = null;
148
142
  });
149
- patchDocument(document);
150
143
  app.ticker.attach(sendMouseMove, 10);
151
144
  }
152
145
  exports.default = default_1;
@@ -1,4 +1,4 @@
1
- import type App from '../app/index.js';
1
+ import type App from "../app/index.js";
2
2
  export declare const deviceMemory: number;
3
3
  export declare const jsHeapSizeLimit: number;
4
4
  export interface Options {
@@ -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 messages_gen_js_1 = require("../app/messages.gen.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((0, messages_gen_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,2 +1,2 @@
1
- import type App from '../app/index.js';
1
+ import type App from "../app/index.js";
2
2
  export default function (app: App): void;
@@ -1,16 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const messages_gen_js_1 = require("../app/messages.gen.js");
3
+ const messages_js_1 = require("../common/messages.js");
4
4
  const guards_js_1 = require("../app/guards.js");
5
5
  function default_1(app) {
6
6
  let documentScroll = false;
7
7
  const nodeScroll = new Map();
8
- function setNodeScroll(target) {
9
- if (target instanceof Element) {
10
- nodeScroll.set(target, [target.scrollLeft, target.scrollTop]);
11
- }
12
- }
13
- const sendSetViewportScroll = app.safe(() => app.send((0, messages_gen_js_1.SetViewportScroll)(window.pageXOffset ||
8
+ const sendSetViewportScroll = app.safe(() => app.send(new messages_js_1.SetViewportScroll(window.pageXOffset ||
14
9
  (document.documentElement && document.documentElement.scrollLeft) ||
15
10
  (document.body && document.body.scrollLeft) ||
16
11
  0, window.pageYOffset ||
@@ -20,7 +15,7 @@ function default_1(app) {
20
15
  const sendSetNodeScroll = app.safe((s, node) => {
21
16
  const id = app.nodes.getID(node);
22
17
  if (id !== undefined) {
23
- app.send((0, messages_gen_js_1.SetNodeScroll)(id, s[0], s[1]));
18
+ app.send(new messages_js_1.SetNodeScroll(id, s[0], s[1]));
24
19
  }
25
20
  });
26
21
  app.attachStartCallback(sendSetViewportScroll);
@@ -32,20 +27,16 @@ function default_1(app) {
32
27
  if (isStart && (0, guards_js_1.isElementNode)(node) && node.scrollLeft + node.scrollTop > 0) {
33
28
  nodeScroll.set(node, [node.scrollLeft, node.scrollTop]);
34
29
  }
35
- else if ((0, guards_js_1.isRootNode)(node)) {
36
- // scroll is not-composed event (https://javascript.info/shadow-dom-events)
37
- app.attachEventListener(node, 'scroll', (e) => {
38
- setNodeScroll(e.target);
39
- });
40
- }
41
30
  });
42
- app.attachEventListener(document, 'scroll', (e) => {
31
+ app.attachEventListener(window, 'scroll', (e) => {
43
32
  const target = e.target;
44
33
  if (target === document) {
45
34
  documentScroll = true;
46
35
  return;
47
36
  }
48
- setNodeScroll(target);
37
+ if (target instanceof Element) {
38
+ nodeScroll.set(target, [target.scrollLeft, target.scrollTop]);
39
+ }
49
40
  });
50
41
  app.ticker.attach(() => {
51
42
  if (documentScroll) {
@@ -1,4 +1,4 @@
1
- import type App from '../app/index.js';
1
+ import type App from "../app/index.js";
2
2
  export interface Options {
3
3
  captureResourceTimings: boolean;
4
4
  capturePageLoadTimings: boolean;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const guards_js_1 = require("../app/guards.js");
4
4
  const utils_js_1 = require("../utils.js");
5
- const messages_gen_js_1 = require("../app/messages.gen.js");
5
+ const messages_js_1 = require("../common/messages.js");
6
6
  function getPaintBlocks(resources) {
7
7
  const paintBlocks = [];
8
8
  const elements = document.getElementsByTagName('*');
@@ -10,7 +10,7 @@ function getPaintBlocks(resources) {
10
10
  for (let i = 0; i < elements.length; i++) {
11
11
  const element = elements[i];
12
12
  let src = '';
13
- if ((0, guards_js_1.hasTag)(element, 'IMG')) {
13
+ if ((0, guards_js_1.hasTag)(element, "IMG")) {
14
14
  src = element.currentSrc || element.src;
15
15
  }
16
16
  if (!src) {
@@ -36,7 +36,9 @@ function getPaintBlocks(resources) {
36
36
  const bottom = Math.min(rect.bottom, window.innerHeight ||
37
37
  (document.documentElement && document.documentElement.clientHeight) ||
38
38
  0);
39
- const right = Math.min(rect.right, window.innerWidth || (document.documentElement && document.documentElement.clientWidth) || 0);
39
+ const right = Math.min(rect.right, window.innerWidth ||
40
+ (document.documentElement && document.documentElement.clientWidth) ||
41
+ 0);
40
42
  if (bottom <= top || right <= left)
41
43
  continue;
42
44
  const area = (bottom - top) * (right - left);
@@ -46,7 +48,8 @@ function getPaintBlocks(resources) {
46
48
  }
47
49
  function calculateSpeedIndex(firstContentfulPaint, paintBlocks) {
48
50
  let a = (Math.max((document.documentElement && document.documentElement.clientWidth) || 0, window.innerWidth || 0) *
49
- Math.max((document.documentElement && document.documentElement.clientHeight) || 0, window.innerHeight || 0)) /
51
+ Math.max((document.documentElement && document.documentElement.clientHeight) ||
52
+ 0, window.innerHeight || 0)) /
50
53
  10;
51
54
  let s = a * firstContentfulPaint;
52
55
  for (let i = 0; i < paintBlocks.length; i++) {
@@ -75,13 +78,16 @@ function default_1(app, opts) {
75
78
  if (resources !== null) {
76
79
  resources[entry.name] = entry.startTime + entry.duration;
77
80
  }
78
- app.send((0, messages_gen_js_1.ResourceTiming)(entry.startTime + performance.timing.navigationStart, entry.duration, entry.responseStart && entry.startTime ? entry.responseStart - entry.startTime : 0, entry.transferSize > entry.encodedBodySize ? entry.transferSize - entry.encodedBodySize : 0, entry.encodedBodySize || 0, entry.decodedBodySize || 0, entry.name, entry.initiatorType));
81
+ app.send(new messages_js_1.ResourceTiming(entry.startTime + performance.timing.navigationStart, entry.duration, entry.responseStart && entry.startTime
82
+ ? entry.responseStart - entry.startTime
83
+ : 0, entry.transferSize > entry.encodedBodySize
84
+ ? entry.transferSize - entry.encodedBodySize
85
+ : 0, entry.encodedBodySize || 0, entry.decodedBodySize || 0, entry.name, entry.initiatorType));
79
86
  }
80
87
  const observer = new PerformanceObserver((list) => list.getEntries().forEach(resourceTiming));
81
88
  let prevSessionID;
82
89
  app.attachStartCallback(function ({ sessionID }) {
83
- if (sessionID !== prevSessionID) {
84
- // Send past page resources on a newly started session
90
+ if (sessionID !== prevSessionID) { // Send past page resources on a newly started session
85
91
  performance.getEntriesByType('resource').forEach(resourceTiming);
86
92
  prevSessionID = sessionID;
87
93
  }
@@ -98,7 +104,9 @@ function default_1(app, opts) {
98
104
  return;
99
105
  }
100
106
  if (firstPaint === 0 || firstContentfulPaint === 0) {
101
- performance.getEntriesByType('paint').forEach((entry) => {
107
+ performance
108
+ .getEntriesByType('paint')
109
+ .forEach((entry) => {
102
110
  const { name, startTime } = entry;
103
111
  switch (name) {
104
112
  case 'first-paint':
@@ -113,7 +121,7 @@ function default_1(app, opts) {
113
121
  if (performance.timing.loadEventEnd || performance.now() > 30000) {
114
122
  pageLoadTimingSent = true;
115
123
  const { navigationStart, requestStart, responseStart, responseEnd, domContentLoadedEventStart, domContentLoadedEventEnd, loadEventStart, loadEventEnd, } = performance.timing;
116
- app.send((0, messages_gen_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));
124
+ 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));
117
125
  }
118
126
  }, 30);
119
127
  }
@@ -136,19 +144,23 @@ function default_1(app, opts) {
136
144
  if (time - interactiveWindowTickTime > 50) {
137
145
  interactiveWindowStartTime = time;
138
146
  }
139
- interactiveWindowTickTime = time - interactiveWindowStartTime > 5000 ? null : time;
147
+ interactiveWindowTickTime =
148
+ time - interactiveWindowStartTime > 5000 ? null : time;
140
149
  }
141
- if ((paintBlocks !== null && interactiveWindowTickTime === null) || time > 30000) {
150
+ if ((paintBlocks !== null && interactiveWindowTickTime === null) ||
151
+ time > 30000) {
142
152
  pageRenderTimingSent = true;
143
153
  resources = null;
144
154
  const speedIndex = paintBlocks === null
145
155
  ? 0
146
156
  : calculateSpeedIndex(firstContentfulPaint || firstPaint, paintBlocks);
147
157
  const timeToInteractive = interactiveWindowTickTime === null
148
- ? Math.max(interactiveWindowStartTime, firstContentfulPaint, performance.timing.domContentLoadedEventEnd - performance.timing.navigationStart ||
149
- 0)
158
+ ? Math.max(interactiveWindowStartTime, firstContentfulPaint, performance.timing.domContentLoadedEventEnd -
159
+ performance.timing.navigationStart || 0)
150
160
  : 0;
151
- app.send((0, messages_gen_js_1.PageRenderTiming)(speedIndex, firstContentfulPaint > visuallyComplete ? firstContentfulPaint : visuallyComplete, timeToInteractive));
161
+ app.send(new messages_js_1.PageRenderTiming(speedIndex, firstContentfulPaint > visuallyComplete
162
+ ? firstContentfulPaint
163
+ : visuallyComplete, timeToInteractive));
152
164
  }
153
165
  });
154
166
  }
@@ -1,2 +1,2 @@
1
- import type App from '../app/index.js';
1
+ import type App from "../app/index.js";
2
2
  export default function (app: App): void;