@openreplay/tracker 3.5.17-beta.0 → 3.6.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/.eslintignore +1 -1
  2. package/.prettierignore +1 -0
  3. package/cjs/app/guards.d.ts +2 -1
  4. package/cjs/app/guards.js +5 -1
  5. package/cjs/app/index.d.ts +12 -10
  6. package/cjs/app/index.js +38 -44
  7. package/cjs/app/messages.d.ts +52 -0
  8. package/cjs/app/messages.gen.d.ts +57 -0
  9. package/cjs/app/messages.gen.js +494 -0
  10. package/cjs/app/messages.js +235 -0
  11. package/cjs/app/nodes.js +2 -0
  12. package/cjs/app/observer/iframe_observer.js +2 -2
  13. package/cjs/app/observer/observer.d.ts +1 -2
  14. package/cjs/app/observer/observer.js +40 -39
  15. package/cjs/app/observer/shadow_root_observer.js +2 -2
  16. package/cjs/app/observer/top_observer.d.ts +9 -0
  17. package/cjs/app/observer/top_observer.js +40 -12
  18. package/cjs/app/session.d.ts +17 -1
  19. package/cjs/app/session.js +51 -3
  20. package/cjs/common/{webworker.d.ts → interaction.d.ts} +3 -3
  21. package/cjs/common/{types.js → interaction.js} +0 -0
  22. package/cjs/common/messages.gen.d.ts +382 -0
  23. package/cjs/common/messages.gen.js +62 -0
  24. package/cjs/index.d.ts +3 -3
  25. package/cjs/index.js +15 -10
  26. package/cjs/modules/adoptedStyleSheets.d.ts +2 -0
  27. package/cjs/modules/adoptedStyleSheets.js +127 -0
  28. package/cjs/modules/connection.js +2 -2
  29. package/cjs/modules/console.js +6 -20
  30. package/cjs/modules/cssrules.js +16 -12
  31. package/cjs/modules/exception.d.ts +2 -2
  32. package/cjs/modules/exception.js +18 -14
  33. package/cjs/modules/img.js +31 -21
  34. package/cjs/modules/input.js +6 -6
  35. package/cjs/modules/mouse.js +42 -33
  36. package/cjs/modules/performance.js +2 -2
  37. package/cjs/modules/scroll.js +16 -7
  38. package/cjs/modules/timing.js +4 -4
  39. package/cjs/modules/viewport.js +4 -4
  40. package/lib/app/guards.d.ts +2 -1
  41. package/lib/app/guards.js +3 -0
  42. package/lib/app/index.d.ts +12 -10
  43. package/lib/app/index.js +39 -45
  44. package/lib/app/messages.d.ts +52 -0
  45. package/lib/app/messages.gen.d.ts +57 -0
  46. package/lib/app/messages.gen.js +435 -0
  47. package/lib/app/messages.js +182 -0
  48. package/lib/app/nodes.js +2 -0
  49. package/lib/app/observer/iframe_observer.js +1 -1
  50. package/lib/app/observer/observer.d.ts +1 -2
  51. package/lib/app/observer/observer.js +40 -39
  52. package/lib/app/observer/shadow_root_observer.js +1 -1
  53. package/lib/app/observer/top_observer.d.ts +9 -0
  54. package/lib/app/observer/top_observer.js +40 -12
  55. package/lib/app/session.d.ts +17 -1
  56. package/lib/app/session.js +51 -3
  57. package/lib/common/{webworker.d.ts → interaction.d.ts} +3 -3
  58. package/lib/common/{types.js → interaction.js} +0 -0
  59. package/lib/common/messages.gen.d.ts +382 -0
  60. package/lib/common/messages.gen.js +59 -0
  61. package/lib/common/tsconfig.tsbuildinfo +1 -1
  62. package/lib/index.d.ts +3 -3
  63. package/lib/index.js +15 -10
  64. package/lib/modules/adoptedStyleSheets.d.ts +2 -0
  65. package/lib/modules/adoptedStyleSheets.js +124 -0
  66. package/lib/modules/connection.js +2 -2
  67. package/lib/modules/console.js +6 -20
  68. package/lib/modules/cssrules.js +16 -12
  69. package/lib/modules/exception.d.ts +2 -2
  70. package/lib/modules/exception.js +18 -14
  71. package/lib/modules/img.js +31 -21
  72. package/lib/modules/input.js +6 -6
  73. package/lib/modules/mouse.js +43 -34
  74. package/lib/modules/performance.js +2 -2
  75. package/lib/modules/scroll.js +17 -8
  76. package/lib/modules/timing.js +4 -4
  77. package/lib/modules/viewport.js +4 -4
  78. package/package.json +1 -1
  79. package/cjs/common/messages.d.ts +0 -444
  80. package/cjs/common/messages.js +0 -794
  81. package/cjs/common/types.d.ts +0 -9
  82. package/cjs/common/webworker.js +0 -2
  83. package/cjs/modules/longtasks.d.ts +0 -2
  84. package/cjs/modules/longtasks.js +0 -34
  85. package/lib/common/messages.d.ts +0 -444
  86. package/lib/common/messages.js +0 -790
  87. package/lib/common/types.d.ts +0 -9
  88. package/lib/common/webworker.js +0 -1
  89. package/lib/modules/longtasks.d.ts +0 -2
  90. package/lib/modules/longtasks.js +0 -31
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const messages_gen_js_1 = require("../app/messages.gen.js");
4
+ const guards_js_1 = require("../app/guards.js");
5
+ function hasAdoptedSS(node) {
6
+ return ((0, guards_js_1.isRootNode)(node) &&
7
+ // @ts-ignore
8
+ typeof node.adoptedStyleSheets !== 'undefined');
9
+ }
10
+ function default_1(app) {
11
+ if (app === null) {
12
+ return;
13
+ }
14
+ if (!hasAdoptedSS(document)) {
15
+ app.attachStartCallback(() => {
16
+ // MBTODO: pre-start sendQueue app
17
+ app.send((0, messages_gen_js_1.TechnicalInfo)('no_adopted_stylesheets', ''));
18
+ });
19
+ return;
20
+ }
21
+ let nextID = 0xf;
22
+ const styleSheetIDMap = new Map();
23
+ const adoptedStyleSheetsOwnings = new Map();
24
+ const updateAdoptedStyleSheets = (root) => {
25
+ let nodeID = app.nodes.getID(root);
26
+ if (root === document) {
27
+ nodeID = 0; // main document doesn't have nodeID. ID count starts from the documentElement
28
+ }
29
+ if (!nodeID) {
30
+ return;
31
+ }
32
+ let pastOwning = adoptedStyleSheetsOwnings.get(nodeID);
33
+ if (!pastOwning) {
34
+ pastOwning = [];
35
+ }
36
+ const nowOwning = [];
37
+ const styleSheets = root.adoptedStyleSheets;
38
+ for (const s of styleSheets) {
39
+ let sheetID = styleSheetIDMap.get(s);
40
+ const init = !sheetID;
41
+ if (!sheetID) {
42
+ sheetID = ++nextID;
43
+ }
44
+ nowOwning.push(sheetID);
45
+ if (!pastOwning.includes(sheetID)) {
46
+ app.send((0, messages_gen_js_1.AdoptedSSAddOwner)(sheetID, nodeID));
47
+ }
48
+ if (init) {
49
+ const rules = s.cssRules;
50
+ for (let i = 0; i < rules.length; i++) {
51
+ app.send((0, messages_gen_js_1.AdoptedSSInsertRuleURLBased)(sheetID, rules[i].cssText, i, app.getBaseHref()));
52
+ }
53
+ }
54
+ }
55
+ for (const sheetID of pastOwning) {
56
+ if (!nowOwning.includes(sheetID)) {
57
+ app.send((0, messages_gen_js_1.AdoptedSSRemoveOwner)(sheetID, nodeID));
58
+ }
59
+ }
60
+ adoptedStyleSheetsOwnings.set(nodeID, nowOwning);
61
+ };
62
+ function patchAdoptedStyleSheets(prototype) {
63
+ const nativeAdoptedStyleSheetsDescriptor = Object.getOwnPropertyDescriptor(prototype, 'adoptedStyleSheets');
64
+ if (nativeAdoptedStyleSheetsDescriptor) {
65
+ Object.defineProperty(prototype, 'adoptedStyleSheets', Object.assign(Object.assign({}, nativeAdoptedStyleSheetsDescriptor), { set: function (value) {
66
+ // @ts-ignore
67
+ const retVal = nativeAdoptedStyleSheetsDescriptor.set.call(this, value);
68
+ updateAdoptedStyleSheets(this);
69
+ return retVal;
70
+ } }));
71
+ }
72
+ }
73
+ const patchContext = (context) => {
74
+ patchAdoptedStyleSheets(context.Document.prototype);
75
+ patchAdoptedStyleSheets(context.ShadowRoot.prototype);
76
+ //@ts-ignore TODO: configure ts (use necessary lib)
77
+ const { insertRule, deleteRule, replace, replaceSync } = context.CSSStyleSheet.prototype;
78
+ //@ts-ignore
79
+ context.CSSStyleSheet.prototype.replace = function (text) {
80
+ return replace.call(this, text).then((sheet) => {
81
+ const sheetID = styleSheetIDMap.get(this);
82
+ if (sheetID) {
83
+ app.send((0, messages_gen_js_1.AdoptedSSReplaceURLBased)(sheetID, text, app.getBaseHref()));
84
+ }
85
+ return sheet;
86
+ });
87
+ };
88
+ //@ts-ignore
89
+ context.CSSStyleSheet.prototype.replaceSync = function (text) {
90
+ const sheetID = styleSheetIDMap.get(this);
91
+ if (sheetID) {
92
+ app.send((0, messages_gen_js_1.AdoptedSSReplaceURLBased)(sheetID, text, app.getBaseHref()));
93
+ }
94
+ return replaceSync.call(this, text);
95
+ };
96
+ context.CSSStyleSheet.prototype.insertRule = function (rule, index = 0) {
97
+ const sheetID = styleSheetIDMap.get(this);
98
+ if (sheetID) {
99
+ app.send((0, messages_gen_js_1.AdoptedSSInsertRuleURLBased)(sheetID, rule, index, app.getBaseHref()));
100
+ }
101
+ return insertRule.call(this, rule, index);
102
+ };
103
+ context.CSSStyleSheet.prototype.deleteRule = function (index) {
104
+ const sheetID = styleSheetIDMap.get(this);
105
+ if (sheetID) {
106
+ app.send((0, messages_gen_js_1.AdoptedSSDeleteRule)(sheetID, index));
107
+ }
108
+ return deleteRule.call(this, index);
109
+ };
110
+ };
111
+ patchContext(window);
112
+ app.observer.attachContextCallback(patchContext);
113
+ app.attachStopCallback(() => {
114
+ styleSheetIDMap.clear();
115
+ adoptedStyleSheetsOwnings.clear();
116
+ });
117
+ // So far main Document is not triggered with nodeCallbacks
118
+ app.attachStartCallback(() => {
119
+ updateAdoptedStyleSheets(document);
120
+ });
121
+ app.nodes.attachNodeCallback((node) => {
122
+ if (hasAdoptedSS(node)) {
123
+ updateAdoptedStyleSheets(node);
124
+ }
125
+ });
126
+ }
127
+ exports.default = default_1;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const messages_js_1 = require("../common/messages.js");
3
+ const messages_gen_js_1 = require("../app/messages.gen.js");
4
4
  function default_1(app) {
5
5
  const connection = navigator.connection ||
6
6
  navigator.mozConnection ||
@@ -8,7 +8,7 @@ function default_1(app) {
8
8
  if (connection === undefined) {
9
9
  return;
10
10
  }
11
- const sendConnectionInformation = () => app.send(new messages_js_1.ConnectionInformation(Math.round(connection.downlink * 1000), connection.type || 'unknown'));
11
+ const sendConnectionInformation = () => app.send((0, messages_gen_js_1.ConnectionInformation)(Math.round(connection.downlink * 1000), connection.type || 'unknown'));
12
12
  sendConnectionInformation();
13
13
  connection.addEventListener('change', sendConnectionInformation);
14
14
  }
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const guards_js_1 = require("../app/guards.js");
4
3
  const utils_js_1 = require("../utils.js");
5
- const messages_js_1 = require("../common/messages.js");
4
+ const messages_gen_js_1 = require("../app/messages.gen.js");
6
5
  const printError = utils_js_1.IN_BROWSER && 'InstallTrigger' in window // detect Firefox
7
6
  ? (e) => e.message + '\n' + e.stack
8
7
  : (e) => e.stack || e.message;
@@ -92,7 +91,7 @@ function default_1(app, opts) {
92
91
  if (!Array.isArray(options.consoleMethods) || options.consoleMethods.length === 0) {
93
92
  return;
94
93
  }
95
- const sendConsoleLog = app.safe((level, args) => app.send(new messages_js_1.ConsoleLog(level, printf(args))));
94
+ const sendConsoleLog = app.safe((level, args) => app.send((0, messages_gen_js_1.ConsoleLog)(level, printf(args))));
96
95
  let n;
97
96
  const reset = () => {
98
97
  n = 0;
@@ -101,7 +100,7 @@ function default_1(app, opts) {
101
100
  app.ticker.attach(reset, 33, false);
102
101
  const patchConsole = (console) => options.consoleMethods.forEach((method) => {
103
102
  if (consoleMethods.indexOf(method) === -1) {
104
- console.error(`OpenReplay: unsupported console method "${method}"`);
103
+ app.debug.error(`OpenReplay: unsupported console method "${method}"`);
105
104
  return;
106
105
  }
107
106
  const fn = console[method];
@@ -113,21 +112,8 @@ function default_1(app, opts) {
113
112
  sendConsoleLog(method, args);
114
113
  };
115
114
  });
116
- patchConsole(window.console);
117
- app.nodes.attachNodeCallback(app.safe((node) => {
118
- if ((0, guards_js_1.hasTag)(node, 'IFRAME')) {
119
- // TODO: newContextCallback
120
- let context = node.contentWindow;
121
- if (context) {
122
- patchConsole(context.console);
123
- }
124
- app.attachEventListener(node, 'load', () => {
125
- if (node.contentWindow !== context) {
126
- context = node.contentWindow;
127
- patchConsole(context.console);
128
- }
129
- });
130
- }
131
- }));
115
+ const patchContext = app.safe((context) => patchConsole(context.console));
116
+ patchContext(window);
117
+ app.observer.attachContextCallback(patchContext);
132
118
  }
133
119
  exports.default = default_1;
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const messages_js_1 = require("../common/messages.js");
3
+ const messages_gen_js_1 = require("../app/messages.gen.js");
4
4
  const guards_js_1 = require("../app/guards.js");
5
5
  function default_1(app) {
6
6
  if (app === null) {
7
7
  return;
8
8
  }
9
9
  if (!window.CSSStyleSheet) {
10
- app.send(new messages_js_1.TechnicalInfo('no_stylesheet_prototype_in_window', ''));
10
+ app.send((0, messages_gen_js_1.TechnicalInfo)('no_stylesheet_prototype_in_window', ''));
11
11
  return;
12
12
  }
13
13
  const processOperation = app.safe((stylesheet, index, rule) => {
14
14
  const sendMessage = typeof rule === 'string'
15
- ? (nodeID) => app.send(new messages_js_1.CSSInsertRuleURLBased(nodeID, rule, index, app.getBaseHref()))
16
- : (nodeID) => app.send(new messages_js_1.CSSDeleteRule(nodeID, index));
15
+ ? (nodeID) => app.send((0, messages_gen_js_1.CSSInsertRuleURLBased)(nodeID, rule, index, app.getBaseHref()))
16
+ : (nodeID) => app.send((0, messages_gen_js_1.CSSDeleteRule)(nodeID, index));
17
17
  // TODO: Extend messages to maintain nested rules (CSSGroupingRule prototype, as well as CSSKeyframesRule)
18
18
  if (stylesheet.ownerNode == null) {
19
19
  throw new Error('Owner Node not found');
@@ -23,15 +23,19 @@ function default_1(app) {
23
23
  sendMessage(nodeID);
24
24
  } // else error?
25
25
  });
26
- const { insertRule, deleteRule } = CSSStyleSheet.prototype;
27
- CSSStyleSheet.prototype.insertRule = function (rule, index = 0) {
28
- processOperation(this, index, rule);
29
- return insertRule.call(this, rule, index);
30
- };
31
- CSSStyleSheet.prototype.deleteRule = function (index) {
32
- processOperation(this, index);
33
- return deleteRule.call(this, index);
26
+ const patchContext = (context) => {
27
+ const { insertRule, deleteRule } = context.CSSStyleSheet.prototype;
28
+ context.CSSStyleSheet.prototype.insertRule = function (rule, index = 0) {
29
+ processOperation(this, index, rule);
30
+ return insertRule.call(this, rule, index);
31
+ };
32
+ context.CSSStyleSheet.prototype.deleteRule = function (index) {
33
+ processOperation(this, index);
34
+ return deleteRule.call(this, index);
35
+ };
34
36
  };
37
+ patchContext(window);
38
+ app.observer.attachContextCallback(patchContext);
35
39
  app.nodes.attachNodeCallback((node) => {
36
40
  if (!(0, guards_js_1.hasTag)(node, 'STYLE') || !node.sheet) {
37
41
  return;
@@ -1,5 +1,5 @@
1
1
  import type App from '../app/index.js';
2
- import type Message from '../common/messages.js';
2
+ import type Message from '../app/messages.gen.js';
3
3
  export interface Options {
4
4
  captureExceptions: boolean;
5
5
  }
@@ -11,6 +11,6 @@ interface StackFrame {
11
11
  source?: string;
12
12
  }
13
13
  export declare function getExceptionMessage(error: Error, fallbackStack: Array<StackFrame>): Message;
14
- export declare function getExceptionMessageFromEvent(e: ErrorEvent | PromiseRejectionEvent): Message | null;
14
+ export declare function getExceptionMessageFromEvent(e: ErrorEvent | PromiseRejectionEvent, context?: typeof globalThis): Message | null;
15
15
  export default function (app: App, opts: Partial<Options>): void;
16
16
  export {};
@@ -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 messages_js_1 = require("../common/messages.js");
4
+ const messages_gen_js_1 = require("../app/messages.gen.js");
5
5
  const error_stack_parser_1 = require("error-stack-parser");
6
6
  function getDefaultStack(e) {
7
7
  return [
@@ -20,10 +20,10 @@ function getExceptionMessage(error, fallbackStack) {
20
20
  stack = error_stack_parser_1.default.parse(error);
21
21
  }
22
22
  catch (e) { }
23
- return new messages_js_1.JSException(error.name, error.message, JSON.stringify(stack));
23
+ return (0, messages_gen_js_1.JSException)(error.name, error.message, JSON.stringify(stack));
24
24
  }
25
25
  exports.getExceptionMessage = getExceptionMessage;
26
- function getExceptionMessageFromEvent(e) {
26
+ function getExceptionMessageFromEvent(e, context = window) {
27
27
  if (e instanceof ErrorEvent) {
28
28
  if (e.error instanceof Error) {
29
29
  return getExceptionMessage(e.error, getDefaultStack(e));
@@ -34,10 +34,10 @@ function getExceptionMessageFromEvent(e) {
34
34
  name = 'Error';
35
35
  message = e.message;
36
36
  }
37
- return new messages_js_1.JSException(name, message, JSON.stringify(getDefaultStack(e)));
37
+ return (0, messages_gen_js_1.JSException)(name, message, JSON.stringify(getDefaultStack(e)));
38
38
  }
39
39
  }
40
- else if ('PromiseRejectionEvent' in window && e instanceof PromiseRejectionEvent) {
40
+ else if ('PromiseRejectionEvent' in context && e instanceof context.PromiseRejectionEvent) {
41
41
  if (e.reason instanceof Error) {
42
42
  return getExceptionMessage(e.reason, []);
43
43
  }
@@ -49,7 +49,7 @@ function getExceptionMessageFromEvent(e) {
49
49
  catch (_) {
50
50
  message = String(e.reason);
51
51
  }
52
- return new messages_js_1.JSException('Unhandled Promise Rejection', message, '[]');
52
+ return (0, messages_gen_js_1.JSException)('Unhandled Promise Rejection', message, '[]');
53
53
  }
54
54
  }
55
55
  return null;
@@ -60,14 +60,18 @@ function default_1(app, opts) {
60
60
  captureExceptions: true,
61
61
  }, opts);
62
62
  if (options.captureExceptions) {
63
- const handler = (e) => {
64
- const msg = getExceptionMessageFromEvent(e);
65
- if (msg != null) {
66
- app.send(msg);
67
- }
68
- };
69
- app.attachEventListener(window, 'unhandledrejection', (e) => handler(e));
70
- app.attachEventListener(window, 'error', (e) => handler(e));
63
+ function patchContext(context) {
64
+ const handler = (e) => {
65
+ const msg = getExceptionMessageFromEvent(e, context);
66
+ if (msg != null) {
67
+ app.send(msg);
68
+ }
69
+ };
70
+ app.attachEventListener(context, 'unhandledrejection', handler);
71
+ app.attachEventListener(context, 'error', handler);
72
+ }
73
+ app.observer.attachContextCallback(patchContext);
74
+ patchContext(window);
71
75
  }
72
76
  }
73
77
  exports.default = default_1;
@@ -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_js_1 = require("../common/messages.js");
4
+ const messages_gen_js_1 = require("../app/messages.gen.js");
5
5
  const guards_js_1 = require("../app/guards.js");
6
6
  function resolveURL(url, location = document.location) {
7
7
  url = url.trim();
@@ -21,16 +21,31 @@ function resolveURL(url, location = document.location) {
21
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(new messages_js_1.SetNodeAttribute(id, 'src', PLACEHOLDER_SRC));
24
+ app.send((0, messages_gen_js_1.SetNodeAttribute)(id, 'src', PLACEHOLDER_SRC));
25
25
  const { width, height } = node.getBoundingClientRect();
26
26
  if (!node.hasAttribute('width')) {
27
- app.send(new messages_js_1.SetNodeAttribute(id, 'width', String(width)));
27
+ app.send((0, messages_gen_js_1.SetNodeAttribute)(id, 'width', String(width)));
28
28
  }
29
29
  if (!node.hasAttribute('height')) {
30
- app.send(new messages_js_1.SetNodeAttribute(id, 'height', String(height)));
30
+ app.send((0, messages_gen_js_1.SetNodeAttribute)(id, 'height', String(height)));
31
31
  }
32
32
  }
33
- const sendImgSrc = app.safe(function () {
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 () {
34
49
  const id = app.nodes.getID(this);
35
50
  if (id === undefined) {
36
51
  return;
@@ -42,21 +57,15 @@ function default_1(app) {
42
57
  const resolvedSrc = resolveURL(src || ''); // Src type is null sometimes. - is it true?
43
58
  if (naturalWidth === 0 && naturalHeight === 0) {
44
59
  if ((0, utils_js_1.isURL)(resolvedSrc)) {
45
- app.send(new messages_js_1.ResourceTiming((0, utils_js_1.timestamp)(), 0, 0, 0, 0, 0, resolvedSrc, 'img'));
60
+ app.send((0, messages_gen_js_1.ResourceTiming)((0, utils_js_1.timestamp)(), 0, 0, 0, 0, 0, resolvedSrc, 'img'));
46
61
  }
47
62
  }
48
63
  else if (resolvedSrc.length >= 1e5 || app.sanitizer.isMasked(id)) {
49
64
  sendPlaceholder(id, this);
50
65
  }
51
66
  else {
52
- app.send(new messages_js_1.SetNodeAttribute(id, 'src', resolvedSrc));
53
- if (srcset) {
54
- const resolvedSrcset = srcset
55
- .split(',')
56
- .map((str) => resolveURL(str))
57
- .join(',');
58
- app.send(new messages_js_1.SetNodeAttribute(id, 'srcset', resolvedSrcset));
59
- }
67
+ sendSrc(id, this);
68
+ sendSrcset(id, this);
60
69
  }
61
70
  });
62
71
  const observer = new MutationObserver((mutations) => {
@@ -68,23 +77,24 @@ function default_1(app) {
68
77
  return;
69
78
  }
70
79
  if (mutation.attributeName === 'src') {
71
- const src = target.src;
72
- app.send(new messages_js_1.SetNodeAttributeURLBased(id, 'src', src, app.getBaseHref()));
80
+ sendSrc(id, target);
73
81
  }
74
82
  if (mutation.attributeName === 'srcset') {
75
- const srcset = target.srcset;
76
- app.send(new messages_js_1.SetNodeAttribute(id, 'srcset', srcset));
83
+ sendSrcset(id, target);
77
84
  }
78
85
  }
79
86
  }
80
87
  });
88
+ app.attachStopCallback(() => {
89
+ observer.disconnect();
90
+ });
81
91
  app.nodes.attachNodeCallback((node) => {
82
92
  if (!(0, guards_js_1.hasTag)(node, 'IMG')) {
83
93
  return;
84
94
  }
85
- app.nodes.attachElementListener('error', node, sendImgSrc);
86
- app.nodes.attachElementListener('load', node, sendImgSrc);
87
- sendImgSrc.call(node);
95
+ app.nodes.attachElementListener('error', node, sendImgAttrs.bind(node));
96
+ app.nodes.attachElementListener('load', node, sendImgAttrs.bind(node));
97
+ sendImgAttrs.call(node);
88
98
  observer.observe(node, { attributes: true, attributeFilter: ['src', 'srcset'] });
89
99
  });
90
100
  }
@@ -3,7 +3,7 @@ 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_js_1 = require("../common/messages.js");
6
+ const messages_gen_js_1 = require("../app/messages.gen.js");
7
7
  const INPUT_TYPES = ['text', 'password', 'email', 'search', 'number', 'range', 'date'];
8
8
  function isTextEditable(node) {
9
9
  if ((0, guards_js_1.hasTag)(node, 'TEXTAREA')) {
@@ -43,7 +43,7 @@ const labelElementFor = utils_js_1.IN_BROWSER && 'labels' in HTMLInputElement.pr
43
43
  }
44
44
  const id = node.id;
45
45
  if (id) {
46
- const labels = document.querySelectorAll('label[for="' + id + '"]');
46
+ const labels = node.ownerDocument.querySelectorAll('label[for="' + id + '"]');
47
47
  if (labels !== null && labels.length === 1) {
48
48
  return labels[0];
49
49
  }
@@ -74,7 +74,7 @@ function default_1(app, opts) {
74
74
  function sendInputTarget(id, node) {
75
75
  const label = getInputLabel(node);
76
76
  if (label !== '') {
77
- app.send(new messages_js_1.SetInputTarget(id, label));
77
+ app.send((0, messages_gen_js_1.SetInputTarget)(id, label));
78
78
  }
79
79
  }
80
80
  function sendInputValue(id, node) {
@@ -101,7 +101,7 @@ function default_1(app, opts) {
101
101
  value = '';
102
102
  break;
103
103
  }
104
- app.send(new messages_js_1.SetInputValue(id, value, mask));
104
+ app.send((0, messages_gen_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(new messages_js_1.SetInputChecked(id, node.checked));
142
+ app.send((0, messages_gen_js_1.SetInputChecked)(id, node.checked));
143
143
  }
144
144
  });
145
145
  });
@@ -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(new messages_js_1.SetInputChecked(id, node.checked));
166
+ app.send((0, messages_gen_js_1.SetInputChecked)(id, node.checked));
167
167
  return;
168
168
  }
169
169
  }));
@@ -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_js_1 = require("../common/messages.js");
5
+ const messages_gen_js_1 = require("../app/messages.gen.js");
6
6
  const input_js_1 = require("./input.js");
7
- function _getSelector(target) {
7
+ function _getSelector(target, document) {
8
8
  let el = target;
9
9
  let selector = null;
10
10
  do {
@@ -34,16 +34,16 @@ function isClickable(element) {
34
34
  element.onclick != null ||
35
35
  element.getAttribute('role') === 'button');
36
36
  //|| element.className.includes("btn")
37
- // MBTODO: intersect addEventListener
37
+ // MBTODO: intersept addEventListener
38
38
  }
39
- //TODO: fix (typescript doesn't allow work when the guard is inside the function)
40
- function getTarget(target) {
39
+ //TODO: fix (typescript is not sure about target variable after assignation of svg)
40
+ function getTarget(target, document) {
41
41
  if (target instanceof Element) {
42
- return _getTarget(target);
42
+ return _getTarget(target, document);
43
43
  }
44
44
  return null;
45
45
  }
46
- function _getTarget(target) {
46
+ function _getTarget(target, document) {
47
47
  let element = target;
48
48
  while (element !== null && element !== document.documentElement) {
49
49
  if ((0, utils_js_1.hasOpenreplayAttribute)(element, 'masked')) {
@@ -106,38 +106,47 @@ function default_1(app) {
106
106
  });
107
107
  const sendMouseMove = () => {
108
108
  if (mousePositionChanged) {
109
- app.send(new messages_js_1.MouseMove(mousePositionX, mousePositionY));
109
+ app.send((0, messages_gen_js_1.MouseMove)(mousePositionX, mousePositionY));
110
110
  mousePositionChanged = false;
111
111
  }
112
112
  };
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();
122
- }
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;
113
+ const patchDocument = (document) => {
114
+ const selectorMap = {};
115
+ function getSelector(id, target) {
116
+ return (selectorMap[id] = selectorMap[id] || _getSelector(target, document));
133
117
  }
134
- const id = app.nodes.getID(target);
135
- if (id !== undefined) {
136
- sendMouseMove();
137
- app.send(new messages_js_1.MouseClick(id, mouseTarget === target ? Math.round(performance.now() - mouseTargetTime) : 0, getTargetLabel(target), getSelector(id, target)), true);
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);
138
147
  }
139
- mouseTarget = null;
140
148
  });
149
+ patchDocument(document);
141
150
  app.ticker.attach(sendMouseMove, 10);
142
151
  }
143
152
  exports.default = default_1;
@@ -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_js_1 = require("../common/messages.js");
5
+ const messages_gen_js_1 = require("../app/messages.gen.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 messages_js_1.PerformanceTrack(frames, ticks, perf.memory.totalJSHeapSize || 0, perf.memory.usedJSHeapSize || 0));
37
+ app.send((0, messages_gen_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(() => {