@openreplay/tracker 11.0.6 → 12.0.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 (113) hide show
  1. package/CHANGELOG.md +4 -2
  2. package/cjs/app/index.d.ts +84 -6
  3. package/cjs/app/index.js +427 -58
  4. package/cjs/app/logger.d.ts +7 -17
  5. package/cjs/app/logger.js +11 -19
  6. package/cjs/app/messages.gen.d.ts +2 -0
  7. package/cjs/app/messages.gen.js +20 -1
  8. package/cjs/app/observer/iframe_observer.js +4 -1
  9. package/cjs/app/observer/shadow_root_observer.js +4 -1
  10. package/cjs/app/observer/top_observer.js +7 -4
  11. package/cjs/common/interaction.d.ts +5 -2
  12. package/cjs/common/messages.gen.d.ts +17 -2
  13. package/cjs/index.d.ts +45 -2
  14. package/cjs/index.js +237 -106
  15. package/cjs/modules/Network/beaconProxy.js +4 -1
  16. package/cjs/modules/Network/fetchProxy.js +24 -1
  17. package/cjs/modules/Network/index.js +6 -3
  18. package/cjs/modules/Network/xhrProxy.js +24 -1
  19. package/cjs/modules/conditionsManager.d.ts +84 -0
  20. package/cjs/modules/conditionsManager.js +343 -0
  21. package/cjs/modules/exception.js +4 -1
  22. package/cjs/modules/featureFlags.d.ts +1 -1
  23. package/cjs/modules/featureFlags.js +36 -46
  24. package/cjs/modules/network.js +5 -2
  25. package/cjs/modules/tagWatcher.d.ts +21 -0
  26. package/cjs/modules/tagWatcher.js +77 -0
  27. package/cjs/modules/userTesting/index.js +30 -4
  28. package/cjs/modules/userTesting/recorder.js +71 -88
  29. package/coverage/clover.xml +577 -544
  30. package/coverage/coverage-final.json +8 -8
  31. package/coverage/lcov-report/index.html +28 -28
  32. package/coverage/lcov-report/main/app/canvas.ts.html +97 -46
  33. package/coverage/lcov-report/main/app/guards.ts.html +1 -1
  34. package/coverage/lcov-report/main/app/index.html +19 -19
  35. package/coverage/lcov-report/main/app/index.ts.html +62 -35
  36. package/coverage/lcov-report/main/app/logger.ts.html +1 -1
  37. package/coverage/lcov-report/main/app/messages.gen.ts.html +32 -5
  38. package/coverage/lcov-report/main/app/nodes.ts.html +17 -5
  39. package/coverage/lcov-report/main/app/observer/iframe_observer.ts.html +1 -1
  40. package/coverage/lcov-report/main/app/observer/iframe_offsets.ts.html +1 -1
  41. package/coverage/lcov-report/main/app/observer/index.html +1 -1
  42. package/coverage/lcov-report/main/app/observer/shadow_root_observer.ts.html +1 -1
  43. package/coverage/lcov-report/main/app/observer/top_observer.ts.html +1 -1
  44. package/coverage/lcov-report/main/app/sanitizer.ts.html +1 -1
  45. package/coverage/lcov-report/main/app/session.ts.html +1 -1
  46. package/coverage/lcov-report/main/app/ticker.ts.html +1 -1
  47. package/coverage/lcov-report/main/index.html +9 -9
  48. package/coverage/lcov-report/main/index.ts.html +27 -6
  49. package/coverage/lcov-report/main/modules/Network/beaconProxy.ts.html +1 -1
  50. package/coverage/lcov-report/main/modules/Network/fetchProxy.ts.html +1 -1
  51. package/coverage/lcov-report/main/modules/Network/index.html +1 -1
  52. package/coverage/lcov-report/main/modules/Network/index.ts.html +1 -1
  53. package/coverage/lcov-report/main/modules/Network/networkMessage.ts.html +1 -1
  54. package/coverage/lcov-report/main/modules/Network/utils.ts.html +1 -1
  55. package/coverage/lcov-report/main/modules/Network/xhrProxy.ts.html +1 -1
  56. package/coverage/lcov-report/main/modules/attributeSender.ts.html +1 -1
  57. package/coverage/lcov-report/main/modules/axiosSpy.ts.html +1 -1
  58. package/coverage/lcov-report/main/modules/conditionsManager.ts.html +92 -38
  59. package/coverage/lcov-report/main/modules/connection.ts.html +1 -1
  60. package/coverage/lcov-report/main/modules/console.ts.html +1 -1
  61. package/coverage/lcov-report/main/modules/constructedStyleSheets.ts.html +1 -1
  62. package/coverage/lcov-report/main/modules/cssrules.ts.html +1 -1
  63. package/coverage/lcov-report/main/modules/exception.ts.html +1 -1
  64. package/coverage/lcov-report/main/modules/featureFlags.ts.html +1 -1
  65. package/coverage/lcov-report/main/modules/focus.ts.html +1 -1
  66. package/coverage/lcov-report/main/modules/fonts.ts.html +1 -1
  67. package/coverage/lcov-report/main/modules/img.ts.html +1 -1
  68. package/coverage/lcov-report/main/modules/index.html +21 -21
  69. package/coverage/lcov-report/main/modules/input.ts.html +1 -1
  70. package/coverage/lcov-report/main/modules/mouse.ts.html +1 -1
  71. package/coverage/lcov-report/main/modules/network.ts.html +1 -1
  72. package/coverage/lcov-report/main/modules/performance.ts.html +1 -1
  73. package/coverage/lcov-report/main/modules/scroll.ts.html +1 -1
  74. package/coverage/lcov-report/main/modules/selection.ts.html +1 -1
  75. package/coverage/lcov-report/main/modules/tabs.ts.html +1 -1
  76. package/coverage/lcov-report/main/modules/tagWatcher.ts.html +54 -27
  77. package/coverage/lcov-report/main/modules/timing.ts.html +1 -1
  78. package/coverage/lcov-report/main/modules/userTesting/SignalManager.ts.html +1 -1
  79. package/coverage/lcov-report/main/modules/userTesting/dnd.ts.html +1 -1
  80. package/coverage/lcov-report/main/modules/userTesting/index.html +1 -1
  81. package/coverage/lcov-report/main/modules/userTesting/index.ts.html +1 -1
  82. package/coverage/lcov-report/main/modules/userTesting/recorder.ts.html +1 -1
  83. package/coverage/lcov-report/main/modules/userTesting/styles.ts.html +1 -1
  84. package/coverage/lcov-report/main/modules/userTesting/utils.ts.html +1 -1
  85. package/coverage/lcov-report/main/modules/viewport.ts.html +1 -1
  86. package/coverage/lcov-report/main/utils.ts.html +1 -1
  87. package/coverage/lcov-report/webworker/BatchWriter.ts.html +1 -1
  88. package/coverage/lcov-report/webworker/MessageEncoder.gen.ts.html +17 -5
  89. package/coverage/lcov-report/webworker/PrimitiveEncoder.ts.html +1 -1
  90. package/coverage/lcov-report/webworker/QueueSender.ts.html +1 -1
  91. package/coverage/lcov-report/webworker/index.html +7 -7
  92. package/coverage/lcov-report/webworker/index.ts.html +1 -1
  93. package/coverage/lcov.info +1100 -1033
  94. package/lib/app/index.d.ts +84 -6
  95. package/lib/app/index.js +387 -44
  96. package/lib/app/logger.d.ts +7 -17
  97. package/lib/app/logger.js +11 -19
  98. package/lib/app/messages.gen.d.ts +2 -0
  99. package/lib/app/messages.gen.js +17 -0
  100. package/lib/common/interaction.d.ts +5 -2
  101. package/lib/common/messages.gen.d.ts +17 -2
  102. package/lib/common/tsconfig.tsbuildinfo +1 -1
  103. package/lib/index.d.ts +45 -2
  104. package/lib/index.js +191 -86
  105. package/lib/modules/conditionsManager.d.ts +84 -0
  106. package/lib/modules/conditionsManager.js +340 -0
  107. package/lib/modules/featureFlags.d.ts +1 -1
  108. package/lib/modules/featureFlags.js +36 -46
  109. package/lib/modules/tagWatcher.d.ts +21 -0
  110. package/lib/modules/tagWatcher.js +74 -0
  111. package/lib/modules/userTesting/recorder.js +71 -88
  112. package/package.json +1 -1
  113. package/tsconfig-base.json +3 -2
package/cjs/index.js CHANGED
@@ -1,33 +1,58 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
2
28
  Object.defineProperty(exports, "__esModule", { value: true });
3
29
  exports.SanitizeLevel = exports.Messages = exports.App = void 0;
4
- const index_js_1 = require("./app/index.js");
30
+ const index_js_1 = __importStar(require("./app/index.js"));
5
31
  var index_js_2 = require("./app/index.js");
6
- Object.defineProperty(exports, "App", { enumerable: true, get: function () { return index_js_2.default; } });
32
+ Object.defineProperty(exports, "App", { enumerable: true, get: function () { return __importDefault(index_js_2).default; } });
7
33
  const messages_gen_js_1 = require("./app/messages.gen.js");
8
- const _Messages = require("./app/messages.gen.js");
34
+ const _Messages = __importStar(require("./app/messages.gen.js"));
9
35
  exports.Messages = _Messages;
10
36
  var sanitizer_js_1 = require("./app/sanitizer.js");
11
37
  Object.defineProperty(exports, "SanitizeLevel", { enumerable: true, get: function () { return sanitizer_js_1.SanitizeLevel; } });
12
- const connection_js_1 = require("./modules/connection.js");
13
- const console_js_1 = require("./modules/console.js");
14
- const exception_js_1 = require("./modules/exception.js");
15
- const img_js_1 = require("./modules/img.js");
16
- const input_js_1 = require("./modules/input.js");
17
- const mouse_js_1 = require("./modules/mouse.js");
18
- const timing_js_1 = require("./modules/timing.js");
19
- const performance_js_1 = require("./modules/performance.js");
20
- const scroll_js_1 = require("./modules/scroll.js");
21
- const viewport_js_1 = require("./modules/viewport.js");
22
- const cssrules_js_1 = require("./modules/cssrules.js");
23
- const focus_js_1 = require("./modules/focus.js");
24
- const fonts_js_1 = require("./modules/fonts.js");
25
- const network_js_1 = require("./modules/network.js");
26
- const constructedStyleSheets_js_1 = require("./modules/constructedStyleSheets.js");
27
- const selection_js_1 = require("./modules/selection.js");
28
- const tabs_js_1 = require("./modules/tabs.js");
38
+ const connection_js_1 = __importDefault(require("./modules/connection.js"));
39
+ const console_js_1 = __importDefault(require("./modules/console.js"));
40
+ const exception_js_1 = __importStar(require("./modules/exception.js"));
41
+ const img_js_1 = __importDefault(require("./modules/img.js"));
42
+ const input_js_1 = __importDefault(require("./modules/input.js"));
43
+ const mouse_js_1 = __importDefault(require("./modules/mouse.js"));
44
+ const timing_js_1 = __importDefault(require("./modules/timing.js"));
45
+ const performance_js_1 = __importDefault(require("./modules/performance.js"));
46
+ const scroll_js_1 = __importDefault(require("./modules/scroll.js"));
47
+ const viewport_js_1 = __importDefault(require("./modules/viewport.js"));
48
+ const cssrules_js_1 = __importDefault(require("./modules/cssrules.js"));
49
+ const focus_js_1 = __importDefault(require("./modules/focus.js"));
50
+ const fonts_js_1 = __importDefault(require("./modules/fonts.js"));
51
+ const network_js_1 = __importDefault(require("./modules/network.js"));
52
+ const constructedStyleSheets_js_1 = __importDefault(require("./modules/constructedStyleSheets.js"));
53
+ const selection_js_1 = __importDefault(require("./modules/selection.js"));
54
+ const tabs_js_1 = __importDefault(require("./modules/tabs.js"));
29
55
  const utils_js_1 = require("./utils.js");
30
- const featureFlags_js_1 = require("./modules/featureFlags.js");
31
56
  const DOCS_SETUP = '/installation/javascript-sdk';
32
57
  function processOptions(obj) {
33
58
  if (obj == null) {
@@ -58,8 +83,28 @@ function processOptions(obj) {
58
83
  }
59
84
  class API {
60
85
  constructor(options) {
86
+ var _a;
61
87
  this.options = options;
62
88
  this.app = null;
89
+ this.checkDoNotTrack = () => {
90
+ return (this.options.respectDoNotTrack &&
91
+ (navigator.doNotTrack == '1' ||
92
+ // @ts-ignore
93
+ window.doNotTrack == '1'));
94
+ };
95
+ this.signalStartIssue = (reason, missingApi) => {
96
+ const doNotTrack = this.checkDoNotTrack();
97
+ const req = new XMLHttpRequest();
98
+ const orig = this.options.ingestPoint || index_js_1.DEFAULT_INGEST_POINT;
99
+ req.open('POST', orig + '/v1/web/not-started');
100
+ req.send(JSON.stringify({
101
+ trackerVersion: '12.0.0',
102
+ projectKey: this.options.projectKey,
103
+ doNotTrack,
104
+ reason,
105
+ missingApi,
106
+ }));
107
+ };
63
108
  this.restartCanvasTracking = () => {
64
109
  if (this.app === null) {
65
110
  return;
@@ -93,105 +138,118 @@ class API {
93
138
  console.error('OpenReplay: Your website must be publicly accessible and running on SSL in order for OpenReplay to properly capture and replay the user session. You can disable this check by setting `__DISABLE_SECURE_MODE` option to `true` if you are testing in localhost. Keep in mind, that asset files on a local machine are not available to the outside world. This might affect tracking if you use css files.');
94
139
  return;
95
140
  }
96
- const doNotTrack = options.respectDoNotTrack &&
97
- (navigator.doNotTrack == '1' ||
98
- // @ts-ignore
99
- window.doNotTrack == '1');
100
- const app = (this.app =
101
- doNotTrack ||
102
- !('Map' in window) ||
103
- !('Set' in window) ||
104
- !('MutationObserver' in window) ||
105
- !('performance' in window) ||
106
- !('timing' in performance) ||
107
- !('startsWith' in String.prototype) ||
108
- !('Blob' in window) ||
109
- !('Worker' in window)
110
- ? null
111
- : new index_js_1.default(options.projectKey, options.sessionToken, options));
112
- if (app !== null) {
113
- (0, viewport_js_1.default)(app);
114
- (0, cssrules_js_1.default)(app);
115
- (0, constructedStyleSheets_js_1.default)(app);
116
- (0, connection_js_1.default)(app);
117
- (0, console_js_1.default)(app, options);
118
- (0, exception_js_1.default)(app, options);
119
- (0, img_js_1.default)(app);
120
- (0, input_js_1.default)(app, options);
121
- (0, mouse_js_1.default)(app, options.mouse);
122
- (0, timing_js_1.default)(app, options);
123
- (0, performance_js_1.default)(app, options);
124
- (0, scroll_js_1.default)(app);
125
- (0, focus_js_1.default)(app);
126
- (0, fonts_js_1.default)(app);
127
- (0, network_js_1.default)(app, options.network);
128
- (0, selection_js_1.default)(app);
129
- (0, tabs_js_1.default)(app);
130
- this.featureFlags = new featureFlags_js_1.default(app);
131
- window.__OPENREPLAY__ = this;
132
- app.attachStartCallback(() => {
133
- var _a;
134
- if ((_a = options.flags) === null || _a === void 0 ? void 0 : _a.onFlagsLoad) {
135
- this.onFlagsLoad(options.flags.onFlagsLoad);
141
+ const doNotTrack = this.checkDoNotTrack();
142
+ const failReason = [];
143
+ const conditions = [
144
+ 'Map',
145
+ 'Set',
146
+ 'MutationObserver',
147
+ 'performance',
148
+ 'timing',
149
+ 'startsWith',
150
+ 'Blob',
151
+ 'Worker',
152
+ ];
153
+ if (doNotTrack) {
154
+ failReason.push('doNotTrack');
155
+ }
156
+ else {
157
+ for (const condition of conditions) {
158
+ if (condition === 'timing') {
159
+ if ('performance' in window && !(condition in performance)) {
160
+ failReason.push(condition);
161
+ break;
162
+ }
163
+ }
164
+ else if (condition === 'startsWith') {
165
+ if (!(condition in String.prototype)) {
166
+ failReason.push(condition);
167
+ break;
168
+ }
169
+ }
170
+ else {
171
+ if (!(condition in window)) {
172
+ failReason.push(condition);
173
+ break;
174
+ }
136
175
  }
137
- void this.featureFlags.reloadFlags();
138
- });
139
- const wOpen = window.open;
140
- if (options.autoResetOnWindowOpen || options.resetTabOnWindowOpen) {
141
- app.attachStartCallback(() => {
142
- var _a;
143
- const tabId = app.getTabId();
144
- const sessStorage = (_a = app.sessionStorage) !== null && _a !== void 0 ? _a : window.sessionStorage;
145
- // @ts-ignore ?
146
- window.open = function (...args) {
147
- if (options.autoResetOnWindowOpen) {
148
- app.resetNextPageSession(true);
149
- }
150
- if (options.resetTabOnWindowOpen) {
151
- sessStorage.removeItem(options.session_tabid_key || '__openreplay_tabid');
152
- }
153
- wOpen.call(window, ...args);
154
- app.resetNextPageSession(false);
155
- sessStorage.setItem(options.session_tabid_key || '__openreplay_tabid', tabId);
156
- };
157
- });
158
- app.attachStopCallback(() => {
159
- window.open = wOpen;
160
- });
161
176
  }
162
177
  }
163
- else {
164
- console.log("OpenReplay: browser doesn't support API required for tracking or doNotTrack is set to 1.");
165
- const req = new XMLHttpRequest();
166
- const orig = options.ingestPoint || index_js_1.DEFAULT_INGEST_POINT;
167
- req.open('POST', orig + '/v1/web/not-started');
168
- // no-cors issue only with text/plain or not-set Content-Type
169
- // req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
170
- req.send(JSON.stringify({
171
- trackerVersion: '11.0.6',
172
- projectKey: options.projectKey,
173
- doNotTrack,
174
- // TODO: add precise reason (an exact API missing)
175
- }));
178
+ if (failReason.length > 0) {
179
+ const missingApi = failReason.join(',');
180
+ console.error(`OpenReplay: browser doesn't support API required for tracking or doNotTrack is set to 1. Reason: ${missingApi}`);
181
+ this.signalStartIssue('missing_api', failReason);
182
+ return;
183
+ }
184
+ const app = new index_js_1.default(options.projectKey, options.sessionToken, options, this.signalStartIssue);
185
+ this.app = app;
186
+ (0, viewport_js_1.default)(app);
187
+ (0, cssrules_js_1.default)(app);
188
+ (0, constructedStyleSheets_js_1.default)(app);
189
+ (0, connection_js_1.default)(app);
190
+ (0, console_js_1.default)(app, options);
191
+ (0, exception_js_1.default)(app, options);
192
+ (0, img_js_1.default)(app);
193
+ (0, input_js_1.default)(app, options);
194
+ (0, mouse_js_1.default)(app, options.mouse);
195
+ (0, timing_js_1.default)(app, options);
196
+ (0, performance_js_1.default)(app, options);
197
+ (0, scroll_js_1.default)(app);
198
+ (0, focus_js_1.default)(app);
199
+ (0, fonts_js_1.default)(app);
200
+ (0, network_js_1.default)(app, options.network);
201
+ (0, selection_js_1.default)(app);
202
+ (0, tabs_js_1.default)(app);
203
+ window.__OPENREPLAY__ = this;
204
+ if ((_a = options.flags) === null || _a === void 0 ? void 0 : _a.onFlagsLoad) {
205
+ this.onFlagsLoad(options.flags.onFlagsLoad);
206
+ }
207
+ const wOpen = window.open;
208
+ if (options.autoResetOnWindowOpen || options.resetTabOnWindowOpen) {
209
+ app.attachStartCallback(() => {
210
+ var _a;
211
+ const tabId = app.getTabId();
212
+ const sessStorage = (_a = app.sessionStorage) !== null && _a !== void 0 ? _a : window.sessionStorage;
213
+ // @ts-ignore ?
214
+ window.open = function (...args) {
215
+ if (options.autoResetOnWindowOpen) {
216
+ app.resetNextPageSession(true);
217
+ }
218
+ if (options.resetTabOnWindowOpen) {
219
+ sessStorage.removeItem(options.session_tabid_key || '__openreplay_tabid');
220
+ }
221
+ wOpen.call(window, ...args);
222
+ app.resetNextPageSession(false);
223
+ sessStorage.setItem(options.session_tabid_key || '__openreplay_tabid', tabId);
224
+ };
225
+ });
226
+ app.attachStopCallback(() => {
227
+ window.open = wOpen;
228
+ });
176
229
  }
177
230
  }
178
231
  isFlagEnabled(flagName) {
179
232
  return this.featureFlags.isFlagEnabled(flagName);
180
233
  }
181
234
  onFlagsLoad(callback) {
182
- this.featureFlags.onFlagsLoad(callback);
235
+ var _a;
236
+ (_a = this.app) === null || _a === void 0 ? void 0 : _a.featureFlags.onFlagsLoad(callback);
183
237
  }
184
238
  clearPersistFlags() {
185
- this.featureFlags.clearPersistFlags();
239
+ var _a;
240
+ (_a = this.app) === null || _a === void 0 ? void 0 : _a.featureFlags.clearPersistFlags();
186
241
  }
187
242
  reloadFlags() {
188
- return this.featureFlags.reloadFlags();
243
+ var _a;
244
+ return (_a = this.app) === null || _a === void 0 ? void 0 : _a.featureFlags.reloadFlags();
189
245
  }
190
246
  getFeatureFlag(flagName) {
191
- return this.featureFlags.getFeatureFlag(flagName);
247
+ var _a;
248
+ return (_a = this.app) === null || _a === void 0 ? void 0 : _a.featureFlags.getFeatureFlag(flagName);
192
249
  }
193
250
  getAllFeatureFlags() {
194
- return this.featureFlags.flags;
251
+ var _a;
252
+ return (_a = this.app) === null || _a === void 0 ? void 0 : _a.featureFlags.flags;
195
253
  }
196
254
  use(fn) {
197
255
  return fn(this.app, this.options);
@@ -202,16 +260,89 @@ class API {
202
260
  }
203
261
  return this.app.active();
204
262
  }
263
+ /**
264
+ * Creates a named hook that expects event name, data string and msg direction (up/down),
265
+ * it will skip any message bigger than 5 mb or event name bigger than 255 symbols
266
+ * msg direction is "down" (incoming) by default
267
+ *
268
+ * @returns {(msgType: string, data: string, dir: 'up' | 'down') => void}
269
+ * */
270
+ trackWs(channelName) {
271
+ if (this.app === null) {
272
+ return;
273
+ }
274
+ return this.app.trackWs(channelName);
275
+ }
205
276
  start(startOpts) {
277
+ if (this.browserEnvCheck()) {
278
+ if (this.app === null) {
279
+ return Promise.reject("Browser doesn't support required api, or doNotTrack is active.");
280
+ }
281
+ return this.app.start(startOpts);
282
+ }
283
+ else {
284
+ return Promise.reject('Trying to start not in browser.');
285
+ }
286
+ }
287
+ browserEnvCheck() {
206
288
  if (!utils_js_1.IN_BROWSER) {
207
289
  console.error(`OpenReplay: you are trying to start Tracker on a node.js environment. If you want to use OpenReplay with SSR, please, use componentDidMount or useEffect API for placing the \`tracker.start()\` line. Check documentation on ${utils_js_1.DOCS_HOST}${DOCS_SETUP}`);
290
+ return false;
291
+ }
292
+ return true;
293
+ }
294
+ /**
295
+ * start buffering messages without starting the actual session, which gives user 30 seconds to "activate" and record
296
+ * session by calling start() on conditional trigger and we will then send buffered batch, so it won't get lost
297
+ * */
298
+ coldStart(startOpts, conditional) {
299
+ if (this.browserEnvCheck()) {
300
+ if (this.app === null) {
301
+ return Promise.reject('Tracker not initialized');
302
+ }
303
+ void this.app.coldStart(startOpts, conditional);
304
+ }
305
+ else {
208
306
  return Promise.reject('Trying to start not in browser.');
209
307
  }
308
+ }
309
+ /**
310
+ * Starts offline session recording. Keep in mind that only user device time will be used for timestamps.
311
+ * (no backend delay sync)
312
+ *
313
+ * @param {Object} startOpts - options for session start, same as .start()
314
+ * @param {Function} onSessionSent - callback that will be called once session is fully sent
315
+ * @returns methods to manipulate buffer:
316
+ *
317
+ * saveBuffer - to save it in localStorage
318
+ *
319
+ * getBuffer - returns current buffer
320
+ *
321
+ * setBuffer - replaces current buffer with given
322
+ * */
323
+ startOfflineRecording(startOpts, onSessionSent) {
324
+ if (this.browserEnvCheck()) {
325
+ if (this.app === null) {
326
+ return Promise.reject('Tracker not initialized');
327
+ }
328
+ return this.app.offlineRecording(startOpts, onSessionSent);
329
+ }
330
+ else {
331
+ return Promise.reject('Trying to start not in browser.');
332
+ }
333
+ }
334
+ /**
335
+ * Uploads the stored session buffer to backend
336
+ * @returns promise that resolves once messages are loaded, it has to be awaited
337
+ * so the session can be uploaded properly
338
+ * @resolve - if messages were loaded into service worker successfully
339
+ * @reject {string} - error message
340
+ * */
341
+ uploadOfflineRecording() {
210
342
  if (this.app === null) {
211
- return Promise.reject("Browser doesn't support required api, or doNotTrack is active.");
343
+ return;
212
344
  }
213
- // TODO: check argument type
214
- return this.app.start(startOpts);
345
+ return this.app.uploadOfflineRecording();
215
346
  }
216
347
  stop() {
217
348
  if (this.app === null) {
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  var _a;
3
6
  Object.defineProperty(exports, "__esModule", { value: true });
4
7
  exports.BeaconProxyHandler = void 0;
5
- const networkMessage_js_1 = require("./networkMessage.js");
8
+ const networkMessage_js_1 = __importDefault(require("./networkMessage.js"));
6
9
  const utils_js_1 = require("./utils.js");
7
10
  // https://fetch.spec.whatwg.org/#concept-bodyinit-extract
8
11
  const getContentType = (data) => {
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.FetchProxyHandler = exports.ResponseProxyHandler = void 0;
4
27
  /**
@@ -8,7 +31,7 @@ exports.FetchProxyHandler = exports.ResponseProxyHandler = void 0;
8
31
  * we can intercept the network requests
9
32
  * in not-so-hacky way
10
33
  * */
11
- const networkMessage_js_1 = require("./networkMessage.js");
34
+ const networkMessage_js_1 = __importStar(require("./networkMessage.js"));
12
35
  const utils_js_1 = require("./utils.js");
13
36
  class ResponseProxyHandler {
14
37
  constructor(resp, item) {
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const fetchProxy_js_1 = require("./fetchProxy.js");
4
- const xhrProxy_js_1 = require("./xhrProxy.js");
5
- const beaconProxy_js_1 = require("./beaconProxy.js");
6
+ const fetchProxy_js_1 = __importDefault(require("./fetchProxy.js"));
7
+ const xhrProxy_js_1 = __importDefault(require("./xhrProxy.js"));
8
+ const beaconProxy_js_1 = __importDefault(require("./beaconProxy.js"));
6
9
  const getWarning = (api) => console.warn(`Openreplay: Can't find ${api} in global context.
7
10
  If you're using serverside rendering in your app, make sure that tracker is loaded dynamically, otherwise ${api} won't be tracked.`);
8
11
  function setProxy(context, ignoredHeaders, setSessionTokenHeader, sanitize, sendMessage, isServiceUrl, tokenUrlMatcher) {
@@ -6,9 +6,32 @@
6
6
  * we can intercept the network requests
7
7
  * in not-so-hacky way
8
8
  * */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
9
32
  Object.defineProperty(exports, "__esModule", { value: true });
10
33
  exports.XHRProxyHandler = void 0;
11
- const networkMessage_js_1 = require("./networkMessage.js");
34
+ const networkMessage_js_1 = __importStar(require("./networkMessage.js"));
12
35
  const utils_js_1 = require("./utils.js");
13
36
  class XHRProxyHandler {
14
37
  constructor(XMLReq, ignoredHeaders, setSessionTokenHeader, sanitize, sendMessage, isServiceUrl, tokenUrlMatcher) {
@@ -0,0 +1,84 @@
1
+ import Message, { CustomEvent, JSException, MouseClick, NetworkRequest, SetPageLocation } from '../common/messages.gen.js';
2
+ import App, { StartOptions } from '../app/index.js';
3
+ import { IFeatureFlag } from './featureFlags.js';
4
+ interface Filter {
5
+ filters: {
6
+ operator: string;
7
+ value: string[];
8
+ type: string;
9
+ source?: string;
10
+ }[];
11
+ operator: string;
12
+ value: string[];
13
+ type: string;
14
+ source?: string;
15
+ }
16
+ export default class ConditionsManager {
17
+ private readonly app;
18
+ private readonly startParams;
19
+ conditions: Condition[];
20
+ hasStarted: boolean;
21
+ constructor(app: App, startParams: StartOptions);
22
+ setConditions(conditions: Condition[]): void;
23
+ fetchConditions(projectId: string, token: string): Promise<void>;
24
+ createConditionFromFilter: (filter: Filter) => Condition | undefined;
25
+ trigger(conditionName: string): void;
26
+ processMessage(message: Message): void;
27
+ processFlags(flag: IFeatureFlag[]): void;
28
+ durationInt: ReturnType<typeof setInterval> | null;
29
+ processDuration(durationMs: number, condName: string): void;
30
+ networkRequest(message: NetworkRequest): void;
31
+ customEvent(message: CustomEvent): void;
32
+ clickEvent(message: MouseClick): void;
33
+ pageLocationEvent(message: SetPageLocation): void;
34
+ jsExceptionEvent(message: JSException): void;
35
+ }
36
+ type CommonCondition = {
37
+ type: 'visited_url' | 'click' | 'custom_event';
38
+ operator: keyof typeof operators;
39
+ value: string[];
40
+ name: string;
41
+ };
42
+ type ExceptionCondition = {
43
+ type: 'exception';
44
+ operator: 'contains' | 'startsWith' | 'endsWith';
45
+ value: string[];
46
+ name: string;
47
+ };
48
+ type FeatureFlagCondition = {
49
+ type: 'feature_flag';
50
+ operator: 'is';
51
+ value: string[];
52
+ name: string;
53
+ };
54
+ type SessionDurationCondition = {
55
+ type: 'session_duration';
56
+ value: number[];
57
+ name: string;
58
+ };
59
+ type SubCondition = {
60
+ type: 'network_request';
61
+ key: 'url' | 'status' | 'method' | 'duration';
62
+ operator: keyof typeof operators;
63
+ value: string[];
64
+ };
65
+ type NetworkRequestCondition = {
66
+ type: 'network_request';
67
+ subConditions: SubCondition[];
68
+ name: string;
69
+ };
70
+ type Condition = CommonCondition | ExceptionCondition | FeatureFlagCondition | SessionDurationCondition | NetworkRequestCondition;
71
+ declare const operators: {
72
+ is: (val: string, target: string[]) => boolean;
73
+ isAny: () => boolean;
74
+ isNot: (val: string, target: string[]) => boolean;
75
+ contains: (val: string, target: string[]) => boolean;
76
+ notContains: (val: string, target: string[]) => boolean;
77
+ startsWith: (val: string, target: string[]) => boolean;
78
+ endsWith: (val: string, target: string[]) => boolean;
79
+ greaterThan: (val: number, target: number) => boolean;
80
+ greaterOrEqual: (val: number, target: number) => boolean;
81
+ lessOrEqual: (val: number, target: number) => boolean;
82
+ lessThan: (val: number, target: number) => boolean;
83
+ };
84
+ export {};