@openreplay/tracker 12.0.5 → 12.0.7-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 (58) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/cjs/app/canvas.js +1 -2
  3. package/cjs/app/index.js +66 -48
  4. package/cjs/app/observer/iframe_offsets.js +2 -4
  5. package/cjs/app/observer/observer.js +1 -1
  6. package/cjs/index.js +8 -15
  7. package/cjs/modules/Network/beaconProxy.d.ts +2 -2
  8. package/cjs/modules/Network/beaconProxy.js +5 -3
  9. package/cjs/modules/Network/fetchProxy.d.ts +2 -2
  10. package/cjs/modules/Network/fetchProxy.js +9 -6
  11. package/cjs/modules/Network/index.d.ts +1 -1
  12. package/cjs/modules/Network/index.js +1 -2
  13. package/cjs/modules/Network/networkMessage.d.ts +2 -2
  14. package/cjs/modules/Network/networkMessage.js +2 -0
  15. package/cjs/modules/Network/xhrProxy.d.ts +2 -2
  16. package/cjs/modules/Network/xhrProxy.js +14 -5
  17. package/cjs/modules/axiosSpy.js +2 -3
  18. package/cjs/modules/conditionsManager.js +1 -1
  19. package/cjs/modules/constructedStyleSheets.js +5 -2
  20. package/cjs/modules/featureFlags.js +2 -3
  21. package/cjs/modules/mouse.js +4 -4
  22. package/cjs/modules/network.d.ts +1 -1
  23. package/cjs/modules/network.js +2 -2
  24. package/cjs/modules/tagWatcher.js +1 -2
  25. package/cjs/modules/timing.js +1 -2
  26. package/cjs/modules/userTesting/index.js +18 -23
  27. package/cjs/modules/userTesting/recorder.js +3 -4
  28. package/cjs/modules/userTesting/styles.js +17 -2
  29. package/lib/app/canvas.js +1 -2
  30. package/lib/app/index.js +66 -48
  31. package/lib/app/observer/iframe_offsets.js +2 -4
  32. package/lib/app/observer/observer.js +1 -1
  33. package/lib/common/tsconfig.tsbuildinfo +1 -1
  34. package/lib/index.js +8 -15
  35. package/lib/modules/Network/beaconProxy.d.ts +2 -2
  36. package/lib/modules/Network/beaconProxy.js +5 -3
  37. package/lib/modules/Network/fetchProxy.d.ts +2 -2
  38. package/lib/modules/Network/fetchProxy.js +9 -6
  39. package/lib/modules/Network/index.d.ts +1 -1
  40. package/lib/modules/Network/index.js +1 -2
  41. package/lib/modules/Network/networkMessage.d.ts +2 -2
  42. package/lib/modules/Network/networkMessage.js +2 -0
  43. package/lib/modules/Network/xhrProxy.d.ts +2 -2
  44. package/lib/modules/Network/xhrProxy.js +14 -5
  45. package/lib/modules/axiosSpy.js +2 -3
  46. package/lib/modules/conditionsManager.js +1 -1
  47. package/lib/modules/constructedStyleSheets.js +5 -2
  48. package/lib/modules/featureFlags.js +2 -3
  49. package/lib/modules/mouse.js +4 -4
  50. package/lib/modules/network.d.ts +1 -1
  51. package/lib/modules/network.js +2 -2
  52. package/lib/modules/tagWatcher.js +1 -2
  53. package/lib/modules/timing.js +1 -2
  54. package/lib/modules/userTesting/index.js +18 -23
  55. package/lib/modules/userTesting/recorder.js +3 -4
  56. package/lib/modules/userTesting/styles.js +17 -2
  57. package/package.json +1 -1
  58. package/tsconfig-base.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 12.0.6
2
+
3
+ - allow network sanitizer to return null (will ignore network req)
4
+
5
+ # 12.0.5
6
+
7
+ - patch for img.ts srcset detector
8
+
1
9
  # 12.0.4
2
10
 
3
11
  - patch for email sanitizer (supports + now)
package/cjs/app/canvas.js CHANGED
@@ -89,7 +89,6 @@ class CanvasRecorder {
89
89
  }, 500);
90
90
  }
91
91
  sendSnaps(images, canvasId, createdAt) {
92
- var _a;
93
92
  if (Object.keys(this.snapshots).length === 0) {
94
93
  return;
95
94
  }
@@ -106,7 +105,7 @@ class CanvasRecorder {
106
105
  fetch(this.app.options.ingestPoint + '/v1/web/images', {
107
106
  method: 'POST',
108
107
  headers: {
109
- Authorization: `Bearer ${(_a = this.app.session.getSessionToken()) !== null && _a !== void 0 ? _a : ''}`,
108
+ Authorization: `Bearer ${this.app.session.getSessionToken() ?? ''}`,
110
109
  },
111
110
  body: formData,
112
111
  })
package/cjs/app/index.js CHANGED
@@ -49,7 +49,7 @@ const uxtStorageKey = 'or_uxt_active';
49
49
  const bufferStorageKey = 'or_buffer_1';
50
50
  const START_ERROR = ':(';
51
51
  const UnsuccessfulStart = (reason) => ({ reason, success: false });
52
- const SuccessfulStart = (body) => (Object.assign(Object.assign({}, body), { success: true }));
52
+ const SuccessfulStart = (body) => ({ ...body, success: true });
53
53
  var ActivityState;
54
54
  (function (ActivityState) {
55
55
  ActivityState[ActivityState["NotActive"] = 0] = "NotActive";
@@ -68,7 +68,6 @@ function getTimezone() {
68
68
  }
69
69
  class App {
70
70
  constructor(projectKey, sessionToken, options, signalError) {
71
- var _a, _b;
72
71
  this.signalError = signalError;
73
72
  this.messages = [];
74
73
  /**
@@ -81,7 +80,7 @@ class App {
81
80
  this.stopCallbacks = [];
82
81
  this.commitCallbacks = [];
83
82
  this.activityState = ActivityState.NotActive;
84
- this.version = '12.0.5'; // TODO: version compatability check inside each plugin.
83
+ this.version = '12.0.7-beta.0'; // TODO: version compatability check inside each plugin.
85
84
  this.compressionThreshold = 24 * 1000;
86
85
  this.restartAttempts = 0;
87
86
  this.bc = null;
@@ -98,8 +97,7 @@ class App {
98
97
  return;
99
98
  };
100
99
  this.restartCanvasTracking = () => {
101
- var _a;
102
- (_a = this.canvasRecorder) === null || _a === void 0 ? void 0 : _a.restartTracking();
100
+ this.canvasRecorder?.restartTracking();
103
101
  };
104
102
  this.flushBuffer = async (buffer) => {
105
103
  return new Promise((res) => {
@@ -149,8 +147,8 @@ class App {
149
147
  this.bc = (0, utils_js_1.inIframe)() ? null : new BroadcastChannel(`rick_${host}`);
150
148
  }
151
149
  this.revID = this.options.revID;
152
- this.localStorage = (_a = this.options.localStorage) !== null && _a !== void 0 ? _a : window.localStorage;
153
- this.sessionStorage = (_b = this.options.sessionStorage) !== null && _b !== void 0 ? _b : window.sessionStorage;
150
+ this.localStorage = this.options.localStorage ?? window.localStorage;
151
+ this.sessionStorage = this.options.sessionStorage ?? window.sessionStorage;
154
152
  this.sanitizer = new sanitizer_js_1.default(this, options);
155
153
  this.nodes = new nodes_js_1.default(this.options.node_id);
156
154
  this.observer = new top_observer_js_1.default(this, options);
@@ -182,7 +180,6 @@ class App {
182
180
  this._debug('webworker_error', e);
183
181
  };
184
182
  this.worker.onmessage = ({ data }) => {
185
- var _a;
186
183
  if (data === 'restart') {
187
184
  this.stop(false);
188
185
  void this.start({}, true);
@@ -200,18 +197,17 @@ class App {
200
197
  const batchSize = batch.byteLength;
201
198
  if (batchSize > this.compressionThreshold) {
202
199
  (0, fflate_1.gzip)(data.batch, { mtime: 0 }, (err, result) => {
203
- var _a, _b;
204
200
  if (err) {
205
201
  this.debug.error('Openreplay compression error:', err);
206
- (_a = this.worker) === null || _a === void 0 ? void 0 : _a.postMessage({ type: 'uncompressed', batch: batch });
202
+ this.worker?.postMessage({ type: 'uncompressed', batch: batch });
207
203
  }
208
204
  else {
209
- (_b = this.worker) === null || _b === void 0 ? void 0 : _b.postMessage({ type: 'compressed', batch: result });
205
+ this.worker?.postMessage({ type: 'compressed', batch: result });
210
206
  }
211
207
  });
212
208
  }
213
209
  else {
214
- (_a = this.worker) === null || _a === void 0 ? void 0 : _a.postMessage({ type: 'uncompressed', batch: batch });
210
+ this.worker?.postMessage({ type: 'uncompressed', batch: batch });
215
211
  }
216
212
  }
217
213
  else if (data.type === 'queue_empty') {
@@ -291,7 +287,6 @@ class App {
291
287
  this.debug.error('OpenReplay error: ', context, e);
292
288
  }
293
289
  send(message, urgent = false) {
294
- var _a;
295
290
  if (this.activityState === ActivityState.NotActive) {
296
291
  return;
297
292
  }
@@ -310,7 +305,7 @@ class App {
310
305
  if (!this.singleBuffer) {
311
306
  this.bufferedMessages2.push(message);
312
307
  }
313
- (_a = this.conditionsManager) === null || _a === void 0 ? void 0 : _a.processMessage(message);
308
+ this.conditionsManager?.processMessage(message);
314
309
  }
315
310
  else {
316
311
  this.messages.push(message);
@@ -331,11 +326,10 @@ class App {
331
326
  _nCommit() {
332
327
  if (this.worker !== undefined && this.messages.length) {
333
328
  (0, utils_js_1.requestIdleCb)(() => {
334
- var _a;
335
329
  this.messages.unshift((0, messages_gen_js_2.TabData)(this.session.getTabId()));
336
330
  this.messages.unshift((0, messages_gen_js_2.Timestamp)(this.timestamp()));
337
331
  // why I need to add opt chaining?
338
- (_a = this.worker) === null || _a === void 0 ? void 0 : _a.postMessage(this.messages);
332
+ this.worker?.postMessage(this.messages);
339
333
  this.commitCallbacks.forEach((cb) => cb(this.messages));
340
334
  this.messages.length = 0;
341
335
  });
@@ -366,8 +360,7 @@ class App {
366
360
  }
367
361
  }
368
362
  postToWorker(messages) {
369
- var _a;
370
- (_a = this.worker) === null || _a === void 0 ? void 0 : _a.postMessage(messages);
363
+ this.worker?.postMessage(messages);
371
364
  this.commitCallbacks.forEach((cb) => cb(messages));
372
365
  messages.length = 0;
373
366
  }
@@ -439,7 +432,10 @@ class App {
439
432
  };
440
433
  }
441
434
  getSessionInfo() {
442
- return Object.assign(Object.assign({}, this.session.getInfo()), this.getTrackerInfo());
435
+ return {
436
+ ...this.session.getInfo(),
437
+ ...this.getTrackerInfo(),
438
+ };
443
439
  }
444
440
  getSessionToken() {
445
441
  return this.session.getSessionToken();
@@ -457,7 +453,7 @@ class App {
457
453
  const isSaas = /api\.openreplay\.com/.test(ingest);
458
454
  const projectPath = isSaas ? 'https://app.openreplay.com/ingest' : ingest;
459
455
  const url = projectPath.replace(/ingest$/, `${projectID}/session/${sessionID}`);
460
- if (options === null || options === void 0 ? void 0 : options.withCurrentTime) {
456
+ if (options?.withCurrentTime) {
461
457
  const jumpTo = (0, utils_js_1.now)() - timestamp;
462
458
  return `${url}?jumpto=${jumpTo}`;
463
459
  }
@@ -470,7 +466,6 @@ class App {
470
466
  return this.projectKey;
471
467
  }
472
468
  getBaseHref() {
473
- var _a, _b;
474
469
  if (typeof this.options.resourceBaseHref === 'string') {
475
470
  return this.options.resourceBaseHref;
476
471
  }
@@ -481,7 +476,7 @@ class App {
481
476
  return document.baseURI;
482
477
  }
483
478
  // IE only
484
- return (((_b = (_a = document.head) === null || _a === void 0 ? void 0 : _a.getElementsByTagName('base')[0]) === null || _b === void 0 ? void 0 : _b.getAttribute('href')) ||
479
+ return (document.head?.getElementsByTagName('base')[0]?.getAttribute('href') ||
485
480
  location.origin + location.pathname);
486
481
  }
487
482
  resolveResourceURL(resourceURL) {
@@ -516,7 +511,6 @@ class App {
516
511
  * and we will then send buffered batch, so it won't get lost
517
512
  * */
518
513
  async coldStart(startOpts = {}, conditional) {
519
- var _a, _b;
520
514
  this.singleBuffer = false;
521
515
  const second = 1000;
522
516
  if (conditional) {
@@ -529,8 +523,17 @@ class App {
529
523
  headers: {
530
524
  'Content-Type': 'application/json',
531
525
  },
532
- body: JSON.stringify(Object.assign(Object.assign({}, this.getTrackerInfo()), { timestamp: (0, utils_js_1.now)(), doNotRecord: true, bufferDiff: 0, userID: this.session.getInfo().userID, token: undefined, deviceMemory: performance_js_1.deviceMemory,
533
- jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit, timezone: getTimezone() })),
526
+ body: JSON.stringify({
527
+ ...this.getTrackerInfo(),
528
+ timestamp: (0, utils_js_1.now)(),
529
+ doNotRecord: true,
530
+ bufferDiff: 0,
531
+ userID: this.session.getInfo().userID,
532
+ token: undefined,
533
+ deviceMemory: performance_js_1.deviceMemory,
534
+ jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit,
535
+ timezone: getTimezone(),
536
+ }),
534
537
  });
535
538
  const {
536
539
  // this token is needed to fetch conditions and flags,
@@ -547,10 +550,10 @@ class App {
547
550
  });
548
551
  const onStartInfo = { sessionToken: token, userUUID: '', sessionID: '' };
549
552
  this.startCallbacks.forEach((cb) => cb(onStartInfo));
550
- await ((_a = this.conditionsManager) === null || _a === void 0 ? void 0 : _a.fetchConditions(projectID, token));
553
+ await this.conditionsManager?.fetchConditions(projectID, token);
551
554
  await this.featureFlags.reloadFlags(token);
552
555
  await this.tagWatcher.fetchTags(this.options.ingestPoint, token);
553
- (_b = this.conditionsManager) === null || _b === void 0 ? void 0 : _b.processFlags(this.featureFlags.flags);
556
+ this.conditionsManager?.processFlags(this.featureFlags.flags);
554
557
  }
555
558
  const cycle = () => {
556
559
  this.orderNumber += 1;
@@ -665,10 +668,9 @@ class App {
665
668
  * @reject {string} - error message
666
669
  * */
667
670
  async uploadOfflineRecording() {
668
- var _a, _b;
669
671
  this.stop(false);
670
672
  const timestamp = (0, utils_js_1.now)();
671
- (_a = this.worker) === null || _a === void 0 ? void 0 : _a.postMessage({
673
+ this.worker?.postMessage({
672
674
  type: 'start',
673
675
  pageNo: this.session.incPageNo(),
674
676
  ingestPoint: this.options.ingestPoint,
@@ -683,11 +685,20 @@ class App {
683
685
  headers: {
684
686
  'Content-Type': 'application/json',
685
687
  },
686
- body: JSON.stringify(Object.assign(Object.assign({}, this.getTrackerInfo()), { timestamp: timestamp, doNotRecord: false, bufferDiff: timestamp - this.coldStartTs, userID: this.session.getInfo().userID, token: undefined, deviceMemory: performance_js_1.deviceMemory,
687
- jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit, timezone: getTimezone() })),
688
+ body: JSON.stringify({
689
+ ...this.getTrackerInfo(),
690
+ timestamp: timestamp,
691
+ doNotRecord: false,
692
+ bufferDiff: timestamp - this.coldStartTs,
693
+ userID: this.session.getInfo().userID,
694
+ token: undefined,
695
+ deviceMemory: performance_js_1.deviceMemory,
696
+ jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit,
697
+ timezone: getTimezone(),
698
+ }),
688
699
  });
689
700
  const { token, userBrowser, userCity, userCountry, userDevice, userOS, userState, beaconSizeLimit, projectID, } = await r.json();
690
- (_b = this.worker) === null || _b === void 0 ? void 0 : _b.postMessage({
701
+ this.worker?.postMessage({
691
702
  type: 'auth',
692
703
  token,
693
704
  beaconSizeLimit,
@@ -759,8 +770,18 @@ class App {
759
770
  headers: {
760
771
  'Content-Type': 'application/json',
761
772
  },
762
- body: JSON.stringify(Object.assign(Object.assign({}, this.getTrackerInfo()), { timestamp, doNotRecord: false, bufferDiff: timestamp - this.coldStartTs, userID: this.session.getInfo().userID, token: isNewSession ? undefined : sessionToken, deviceMemory: performance_js_1.deviceMemory,
763
- jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit, timezone: getTimezone(), condition: conditionName })),
773
+ body: JSON.stringify({
774
+ ...this.getTrackerInfo(),
775
+ timestamp,
776
+ doNotRecord: false,
777
+ bufferDiff: timestamp - this.coldStartTs,
778
+ userID: this.session.getInfo().userID,
779
+ token: isNewSession ? undefined : sessionToken,
780
+ deviceMemory: performance_js_1.deviceMemory,
781
+ jsHeapSizeLimit: performance_js_1.jsHeapSizeLimit,
782
+ timezone: getTimezone(),
783
+ condition: conditionName,
784
+ }),
764
785
  })
765
786
  .then((r) => {
766
787
  if (r.status === 200) {
@@ -775,7 +796,6 @@ class App {
775
796
  }
776
797
  })
777
798
  .then(async (r) => {
778
- var _a;
779
799
  if (!this.worker) {
780
800
  const reason = 'no worker found after start request (this might not happen)';
781
801
  this.signalError(reason, []);
@@ -839,12 +859,13 @@ class App {
839
859
  this.activityState = ActivityState.Active;
840
860
  if (canvasEnabled && !this.options.disableCanvas) {
841
861
  this.canvasRecorder =
842
- (_a = this.canvasRecorder) !== null && _a !== void 0 ? _a : new canvas_js_1.default(this, {
843
- fps: canvasFPS,
844
- quality: canvasQuality,
845
- isDebug: this.options.__save_canvas_locally,
846
- fixedScaling: this.options.fixedCanvasScaling,
847
- });
862
+ this.canvasRecorder ??
863
+ new canvas_js_1.default(this, {
864
+ fps: canvasFPS,
865
+ quality: canvasQuality,
866
+ isDebug: this.options.__save_canvas_locally,
867
+ fixedScaling: this.options.fixedCanvasScaling,
868
+ });
848
869
  this.canvasRecorder.startTracking();
849
870
  }
850
871
  /** --------------- COLD START BUFFER ------------------*/
@@ -876,7 +897,7 @@ class App {
876
897
  if (savedUxtTag) {
877
898
  uxtId = parseInt(savedUxtTag, 10);
878
899
  }
879
- if (location === null || location === void 0 ? void 0 : location.search) {
900
+ if (location?.search) {
880
901
  const query = new URLSearchParams(location.search);
881
902
  if (query.has('oruxt')) {
882
903
  const qId = query.get('oruxt');
@@ -916,8 +937,7 @@ class App {
916
937
  this.onUxtCb.push(cb);
917
938
  }
918
939
  getUxtId() {
919
- var _a;
920
- return (_a = this.uxtManager) === null || _a === void 0 ? void 0 : _a.getTestId();
940
+ return this.uxtManager?.getTestId();
921
941
  }
922
942
  /**
923
943
  * basically we ask other tabs during constructor
@@ -946,8 +966,7 @@ class App {
946
966
  }
947
967
  }
948
968
  forceFlushBatch() {
949
- var _a;
950
- (_a = this.worker) === null || _a === void 0 ? void 0 : _a.postMessage('forceFlushBatch');
969
+ this.worker?.postMessage('forceFlushBatch');
951
970
  }
952
971
  getTabId() {
953
972
  return this.session.getTabId();
@@ -974,7 +993,6 @@ class App {
974
993
  };
975
994
  }
976
995
  stop(stopWorker = true) {
977
- var _a;
978
996
  if (this.activityState !== ActivityState.NotActive) {
979
997
  try {
980
998
  this.attributeSender.clear();
@@ -988,7 +1006,7 @@ class App {
988
1006
  if (this.worker && stopWorker) {
989
1007
  this.worker.postMessage('stop');
990
1008
  }
991
- (_a = this.canvasRecorder) === null || _a === void 0 ? void 0 : _a.clear();
1009
+ this.canvasRecorder?.clear();
992
1010
  }
993
1011
  finally {
994
1012
  this.activityState = ActivityState.NotActive;
@@ -26,7 +26,6 @@ class IFrameOffsets {
26
26
  return this.calcOffset(state);
27
27
  }
28
28
  observe(iFrame) {
29
- var _a;
30
29
  const doc = iFrame.contentDocument;
31
30
  if (!doc) {
32
31
  return;
@@ -38,9 +37,8 @@ class IFrameOffsets {
38
37
  iFrame,
39
38
  parent: parentState || null,
40
39
  clear: () => {
41
- var _a;
42
40
  parentDoc.removeEventListener('scroll', invalidateOffset);
43
- (_a = parentDoc.defaultView) === null || _a === void 0 ? void 0 : _a.removeEventListener('resize', invalidateOffset);
41
+ parentDoc.defaultView?.removeEventListener('resize', invalidateOffset);
44
42
  },
45
43
  };
46
44
  const invalidateOffset = () => {
@@ -48,7 +46,7 @@ class IFrameOffsets {
48
46
  };
49
47
  // anything more reliable? This does not cover all cases (layout changes are ignored, for ex.)
50
48
  parentDoc.addEventListener('scroll', invalidateOffset);
51
- (_a = parentDoc.defaultView) === null || _a === void 0 ? void 0 : _a.addEventListener('resize', invalidateOffset);
49
+ parentDoc.defaultView?.addEventListener('resize', invalidateOffset);
52
50
  this.states.set(doc, state);
53
51
  }
54
52
  clear() {
@@ -17,7 +17,7 @@ function isIgnored(node) {
17
17
  if (tag === 'LINK') {
18
18
  const rel = node.getAttribute('rel');
19
19
  const as = node.getAttribute('as');
20
- return !((rel === null || rel === void 0 ? void 0 : rel.includes('stylesheet')) || as === 'style' || as === 'font');
20
+ return !(rel?.includes('stylesheet') || as === 'style' || as === 'font');
21
21
  }
22
22
  return (tag === 'SCRIPT' || tag === 'NOSCRIPT' || tag === 'META' || tag === 'TITLE' || tag === 'BASE');
23
23
  }
package/cjs/index.js CHANGED
@@ -83,7 +83,6 @@ function processOptions(obj) {
83
83
  }
84
84
  class API {
85
85
  constructor(options) {
86
- var _a;
87
86
  this.options = options;
88
87
  this.app = null;
89
88
  this.checkDoNotTrack = () => {
@@ -98,7 +97,7 @@ class API {
98
97
  const orig = this.options.ingestPoint || index_js_1.DEFAULT_INGEST_POINT;
99
98
  req.open('POST', orig + '/v1/web/not-started');
100
99
  req.send(JSON.stringify({
101
- trackerVersion: '12.0.5',
100
+ trackerVersion: '12.0.7-beta.0',
102
101
  projectKey: this.options.projectKey,
103
102
  doNotTrack,
104
103
  reason,
@@ -201,15 +200,14 @@ class API {
201
200
  (0, selection_js_1.default)(app);
202
201
  (0, tabs_js_1.default)(app);
203
202
  window.__OPENREPLAY__ = this;
204
- if ((_a = options.flags) === null || _a === void 0 ? void 0 : _a.onFlagsLoad) {
203
+ if (options.flags?.onFlagsLoad) {
205
204
  this.onFlagsLoad(options.flags.onFlagsLoad);
206
205
  }
207
206
  const wOpen = window.open;
208
207
  if (options.autoResetOnWindowOpen || options.resetTabOnWindowOpen) {
209
208
  app.attachStartCallback(() => {
210
- var _a;
211
209
  const tabId = app.getTabId();
212
- const sessStorage = (_a = app.sessionStorage) !== null && _a !== void 0 ? _a : window.sessionStorage;
210
+ const sessStorage = app.sessionStorage ?? window.sessionStorage;
213
211
  // @ts-ignore ?
214
212
  window.open = function (...args) {
215
213
  if (options.autoResetOnWindowOpen) {
@@ -232,24 +230,19 @@ class API {
232
230
  return this.featureFlags.isFlagEnabled(flagName);
233
231
  }
234
232
  onFlagsLoad(callback) {
235
- var _a;
236
- (_a = this.app) === null || _a === void 0 ? void 0 : _a.featureFlags.onFlagsLoad(callback);
233
+ this.app?.featureFlags.onFlagsLoad(callback);
237
234
  }
238
235
  clearPersistFlags() {
239
- var _a;
240
- (_a = this.app) === null || _a === void 0 ? void 0 : _a.featureFlags.clearPersistFlags();
236
+ this.app?.featureFlags.clearPersistFlags();
241
237
  }
242
238
  reloadFlags() {
243
- var _a;
244
- return (_a = this.app) === null || _a === void 0 ? void 0 : _a.featureFlags.reloadFlags();
239
+ return this.app?.featureFlags.reloadFlags();
245
240
  }
246
241
  getFeatureFlag(flagName) {
247
- var _a;
248
- return (_a = this.app) === null || _a === void 0 ? void 0 : _a.featureFlags.getFeatureFlag(flagName);
242
+ return this.app?.featureFlags.getFeatureFlag(flagName);
249
243
  }
250
244
  getAllFeatureFlags() {
251
- var _a;
252
- return (_a = this.app) === null || _a === void 0 ? void 0 : _a.featureFlags.flags;
245
+ return this.app?.featureFlags.flags;
253
246
  }
254
247
  use(fn) {
255
248
  return fn(this.app, this.options);
@@ -6,11 +6,11 @@ export declare class BeaconProxyHandler<T extends typeof navigator.sendBeacon> i
6
6
  private readonly sanitize;
7
7
  private readonly sendMessage;
8
8
  private readonly isServiceUrl;
9
- constructor(ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData, sendMessage: (item: NetworkRequest) => void, isServiceUrl: (url: string) => boolean);
9
+ constructor(ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData | null, sendMessage: (item: NetworkRequest) => void, isServiceUrl: (url: string) => boolean);
10
10
  apply(target: T, thisArg: T, argsList: any[]): any;
11
11
  }
12
12
  export default class BeaconProxy {
13
13
  static origSendBeacon: (url: string | URL, data?: BodyInit | null | undefined) => boolean;
14
14
  static hasSendBeacon(): boolean;
15
- static create(ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData, sendMessage: (item: NetworkRequest) => void, isServiceUrl: (url: string) => boolean): any;
15
+ static create(ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData | null, sendMessage: (item: NetworkRequest) => void, isServiceUrl: (url: string) => boolean): any;
16
16
  }
@@ -2,7 +2,6 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
- var _a;
6
5
  Object.defineProperty(exports, "__esModule", { value: true });
7
6
  exports.BeaconProxyHandler = void 0;
8
7
  const networkMessage_js_1 = __importDefault(require("./networkMessage.js"));
@@ -65,7 +64,10 @@ class BeaconProxyHandler {
65
64
  item.status = 500;
66
65
  item.statusText = 'Unknown';
67
66
  }
68
- this.sendMessage(item.getMessage());
67
+ const msg = item.getMessage();
68
+ if (msg) {
69
+ this.sendMessage(msg);
70
+ }
69
71
  return isSuccess;
70
72
  }
71
73
  }
@@ -82,4 +84,4 @@ class BeaconProxy {
82
84
  }
83
85
  }
84
86
  exports.default = BeaconProxy;
85
- BeaconProxy.origSendBeacon = (_a = window === null || window === void 0 ? void 0 : window.navigator) === null || _a === void 0 ? void 0 : _a.sendBeacon;
87
+ BeaconProxy.origSendBeacon = window?.navigator?.sendBeacon;
@@ -23,12 +23,12 @@ export declare class FetchProxyHandler<T extends typeof fetch> implements ProxyH
23
23
  private readonly sendMessage;
24
24
  private readonly isServiceUrl;
25
25
  private readonly tokenUrlMatcher?;
26
- constructor(ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData, sendMessage: (item: NetworkRequest) => void, isServiceUrl: (url: string) => boolean, tokenUrlMatcher?: ((url: string) => boolean) | undefined);
26
+ constructor(ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData | null, sendMessage: (item: NetworkRequest) => void, isServiceUrl: (url: string) => boolean, tokenUrlMatcher?: ((url: string) => boolean) | undefined);
27
27
  apply(target: T, _: typeof window, argsList: [RequestInfo | URL, RequestInit]): any;
28
28
  protected beforeFetch(item: NetworkMessage, input: RequestInfo | string, init?: RequestInit): void;
29
29
  protected afterFetch(item: NetworkMessage): (resp: Response) => Response;
30
30
  protected handleResponseBody(resp: Response, item: NetworkMessage): Promise<ArrayBuffer> | Promise<string>;
31
31
  }
32
32
  export default class FetchProxy {
33
- static create(ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData, sendMessage: (item: NetworkRequest) => void, isServiceUrl: (url: string) => boolean, tokenUrlMatcher?: (url: string) => boolean): typeof fetch;
33
+ static create(ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData | null, sendMessage: (item: NetworkRequest) => void, isServiceUrl: (url: string) => boolean, tokenUrlMatcher?: (url: string) => boolean): typeof fetch;
34
34
  }
@@ -142,7 +142,7 @@ class FetchProxyHandler {
142
142
  const init = argsList[1];
143
143
  if (!input ||
144
144
  // @ts-ignore
145
- (typeof input !== 'string' && !(input === null || input === void 0 ? void 0 : input.url))) {
145
+ (typeof input !== 'string' && !input?.url)) {
146
146
  return target.apply(window, argsList);
147
147
  }
148
148
  const isORUrl = input instanceof URL || typeof input === 'string'
@@ -166,7 +166,7 @@ class FetchProxyHandler {
166
166
  if (!argsList[1])
167
167
  argsList[1] = {};
168
168
  if (argsList[1].headers === undefined) {
169
- argsList[1] = Object.assign(Object.assign({}, argsList[1]), { headers: {} });
169
+ argsList[1] = { ...argsList[1], headers: {} };
170
170
  }
171
171
  if (argsList[1].headers instanceof Headers) {
172
172
  argsList[1].headers.append(name, value);
@@ -194,9 +194,9 @@ class FetchProxyHandler {
194
194
  // handle `input` content
195
195
  if (typeof input === 'string') {
196
196
  // when `input` is a string
197
- method = (init === null || init === void 0 ? void 0 : init.method) || 'GET';
197
+ method = init?.method || 'GET';
198
198
  url = (0, utils_js_1.getURL)(input);
199
- requestHeader = (init === null || init === void 0 ? void 0 : init.headers) || {};
199
+ requestHeader = init?.headers || {};
200
200
  }
201
201
  else {
202
202
  // when `input` is a `Request` object
@@ -233,7 +233,7 @@ class FetchProxyHandler {
233
233
  }
234
234
  }
235
235
  // save POST data
236
- if (init === null || init === void 0 ? void 0 : init.body) {
236
+ if (init?.body) {
237
237
  item.requestData = (0, utils_js_1.genStringBody)(init.body);
238
238
  }
239
239
  }
@@ -264,7 +264,10 @@ class FetchProxyHandler {
264
264
  typeof responseValue === 'string' ? responseValue.length : responseValue.byteLength;
265
265
  item.responseSizeText = (0, utils_js_1.formatByteSize)(item.responseSize);
266
266
  item.response = (0, utils_js_1.getStringResponseByType)(item.responseType, responseValue);
267
- this.sendMessage(item.getMessage());
267
+ const msg = item.getMessage();
268
+ if (msg) {
269
+ this.sendMessage(msg);
270
+ }
268
271
  });
269
272
  }
270
273
  return new Proxy(resp, new ResponseProxyHandler(resp, item));
@@ -1,3 +1,3 @@
1
1
  import { RequestResponseData } from './types.js';
2
2
  import { NetworkRequest } from '../../common/messages.gen.js';
3
- export default function setProxy(context: typeof globalThis, ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData, sendMessage: (message: NetworkRequest) => void, isServiceUrl: (url: string) => boolean, tokenUrlMatcher?: (url: string) => boolean): void;
3
+ export default function setProxy(context: typeof globalThis, ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData | null, sendMessage: (message: NetworkRequest) => void, isServiceUrl: (url: string) => boolean, tokenUrlMatcher?: (url: string) => boolean): void;
@@ -9,7 +9,6 @@ const beaconProxy_js_1 = __importDefault(require("./beaconProxy.js"));
9
9
  const getWarning = (api) => console.warn(`Openreplay: Can't find ${api} in global context.
10
10
  If you're using serverside rendering in your app, make sure that tracker is loaded dynamically, otherwise ${api} won't be tracked.`);
11
11
  function setProxy(context, ignoredHeaders, setSessionTokenHeader, sanitize, sendMessage, isServiceUrl, tokenUrlMatcher) {
12
- var _a;
13
12
  if (context.XMLHttpRequest) {
14
13
  context.XMLHttpRequest = xhrProxy_js_1.default.create(ignoredHeaders, setSessionTokenHeader, sanitize, sendMessage, isServiceUrl, tokenUrlMatcher);
15
14
  }
@@ -22,7 +21,7 @@ function setProxy(context, ignoredHeaders, setSessionTokenHeader, sanitize, send
22
21
  else {
23
22
  getWarning('fetch');
24
23
  }
25
- if ((_a = context === null || context === void 0 ? void 0 : context.navigator) === null || _a === void 0 ? void 0 : _a.sendBeacon) {
24
+ if (context?.navigator?.sendBeacon) {
26
25
  context.navigator.sendBeacon = beaconProxy_js_1.default.create(ignoredHeaders, setSessionTokenHeader, sanitize, sendMessage, isServiceUrl);
27
26
  }
28
27
  }
@@ -39,8 +39,8 @@ export default class NetworkMessage {
39
39
  [key: string]: string;
40
40
  };
41
41
  requestData: string | null;
42
- constructor(ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData);
43
- getMessage(): import("../../common/messages.gen.js").NetworkRequest;
42
+ constructor(ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData | null);
43
+ getMessage(): import("../../common/messages.gen.js").NetworkRequest | undefined;
44
44
  writeHeaders(): {
45
45
  reqHs: Record<string, string>;
46
46
  resHs: Record<string, string>;
@@ -53,6 +53,8 @@ class NetworkMessage {
53
53
  request,
54
54
  response,
55
55
  });
56
+ if (!messageInfo)
57
+ return;
56
58
  return (0, messages_gen_js_1.NetworkRequest)(this.requestType, messageInfo.method, messageInfo.url, JSON.stringify(messageInfo.request), JSON.stringify(messageInfo.response), messageInfo.status, this.startTime + (0, utils_js_1.getTimeOrigin)(), this.duration, this.responseSize);
57
59
  }
58
60
  writeHeaders() {
@@ -17,7 +17,7 @@ export declare class XHRProxyHandler<T extends XMLHttpRequest> implements ProxyH
17
17
  private readonly tokenUrlMatcher?;
18
18
  XMLReq: XMLHttpRequest;
19
19
  item: NetworkMessage;
20
- constructor(XMLReq: XMLHttpRequest, ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData, sendMessage: (message: NetworkRequest) => void, isServiceUrl: (url: string) => boolean, tokenUrlMatcher?: ((url: string) => boolean) | undefined);
20
+ constructor(XMLReq: XMLHttpRequest, ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData | null, sendMessage: (message: NetworkRequest) => void, isServiceUrl: (url: string) => boolean, tokenUrlMatcher?: ((url: string) => boolean) | undefined);
21
21
  get(target: T, key: string): any;
22
22
  set(target: T, key: string, value: (args: any[]) => any): boolean;
23
23
  onReadyStateChange(): void;
@@ -35,5 +35,5 @@ export declare class XHRProxyHandler<T extends XMLHttpRequest> implements ProxyH
35
35
  protected updateItemByReadyState(): void;
36
36
  }
37
37
  export default class XHRProxy {
38
- static create(ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData, sendMessage: (data: NetworkRequest) => void, isServiceUrl: (url: string) => boolean, tokenUrlMatcher?: (url: string) => boolean): any;
38
+ static create(ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData | null, sendMessage: (data: NetworkRequest) => void, isServiceUrl: (url: string) => boolean, tokenUrlMatcher?: (url: string) => boolean): any;
39
39
  }