@openreplay/tracker 7.0.1-beta.2 → 7.0.1

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.
@@ -1,5 +1,6 @@
1
1
  import { NetworkRequest } from '../app/messages.gen.js';
2
2
  import { getTimeOrigin } from '../utils.js';
3
+ import axiosSpy from './axiosSpy.js';
3
4
  function getXHRRequestDataObject(xhr) {
4
5
  // @ts-ignore this is 3x faster than using Map<XHR, XHRRequestData>
5
6
  if (!xhr.__or_req_data__) {
@@ -18,6 +19,8 @@ export default function (app, opts = {}) {
18
19
  ignoreHeaders: ['Cookie', 'Set-Cookie', 'Authorization'],
19
20
  capturePayload: false,
20
21
  sessionTokenHeader: false,
22
+ captureInIframes: true,
23
+ axiosInstances: undefined,
21
24
  }, opts);
22
25
  const ignoreHeaders = options.ignoreHeaders;
23
26
  const isHIgnored = Array.isArray(ignoreHeaders)
@@ -44,7 +47,7 @@ export default function (app, opts = {}) {
44
47
  try {
45
48
  reqResInfo.response.body = JSON.parse(resBody);
46
49
  }
47
- catch { }
50
+ catch (_a) { }
48
51
  }
49
52
  return options.sanitizer(reqResInfo);
50
53
  }
@@ -55,7 +58,7 @@ export default function (app, opts = {}) {
55
58
  try {
56
59
  r.body = JSON.stringify(r.body);
57
60
  }
58
- catch {
61
+ catch (_a) {
59
62
  r.body = '<unable to stringify>';
60
63
  app.notify.warn("Openreplay fetch couldn't stringify body:", r.body);
61
64
  }
@@ -143,6 +146,8 @@ export default function (app, opts = {}) {
143
146
  /* ====== <> ====== */
144
147
  /* ====== XHR ====== */
145
148
  const nativeOpen = context.XMLHttpRequest.prototype.open;
149
+ const nativeSetRequestHeader = context.XMLHttpRequest.prototype.setRequestHeader;
150
+ const nativeSend = context.XMLHttpRequest.prototype.send;
146
151
  function trackXMLHttpReqOpen(initMethod, url) {
147
152
  const xhr = this;
148
153
  setSessionTokenHeader((name, value) => xhr.setRequestHeader(name, value));
@@ -159,7 +164,7 @@ export default function (app, opts = {}) {
159
164
  .split('\r\n')
160
165
  .map((h) => h.split(':'))
161
166
  .filter((entry) => !isHIgnored(entry[0]))
162
- .reduce((hds, [name, value]) => ({ ...hds, [name]: value }), {})
167
+ .reduce((hds, [name, value]) => (Object.assign(Object.assign({}, hds), { [name]: value })), {})
163
168
  : {};
164
169
  const method = strMethod(initMethod);
165
170
  const reqResInfo = sanitize({
@@ -184,16 +189,12 @@ export default function (app, opts = {}) {
184
189
  //xhr.addEventListener('error', (e) => {})
185
190
  return nativeOpen.apply(this, arguments);
186
191
  }
187
- context.XMLHttpRequest.prototype.open = trackXMLHttpReqOpen;
188
- const nativeSend = context.XMLHttpRequest.prototype.send;
189
192
  function trackXHRSend(body) {
190
193
  const rdo = getXHRRequestDataObject(this);
191
194
  rdo.body = body;
192
195
  // @ts-ignore ??? this -> XMLHttpRequest
193
196
  return nativeSend.apply(this, arguments);
194
197
  }
195
- context.XMLHttpRequest.prototype.send = trackXHRSend;
196
- const nativeSetRequestHeader = context.XMLHttpRequest.prototype.setRequestHeader;
197
198
  function trackSetReqHeader(name, value) {
198
199
  if (!isHIgnored(name)) {
199
200
  const rdo = getXHRRequestDataObject(this);
@@ -201,9 +202,20 @@ export default function (app, opts = {}) {
201
202
  }
202
203
  return nativeSetRequestHeader.apply(this, arguments);
203
204
  }
204
- context.XMLHttpRequest.prototype.setRequestHeader = trackSetReqHeader;
205
+ if (!options.axiosInstances) {
206
+ context.XMLHttpRequest.prototype.open = trackXMLHttpReqOpen;
207
+ context.XMLHttpRequest.prototype.send = trackXHRSend;
208
+ context.XMLHttpRequest.prototype.setRequestHeader = trackSetReqHeader;
209
+ }
205
210
  /* ====== <> ====== */
206
211
  };
207
212
  patchWindow(window);
208
- app.observer.attachContextCallback(app.safe(patchWindow));
213
+ if (options.axiosInstances) {
214
+ options.axiosInstances.forEach((axiosInstance) => {
215
+ axiosSpy(app, axiosInstance, options, sanitize, stringify);
216
+ });
217
+ }
218
+ if (options.captureInIframes) {
219
+ app.observer.attachContextCallback(app.safe(patchWindow));
220
+ }
209
221
  }
package/lib/utils.js CHANGED
@@ -60,8 +60,9 @@ export function hasOpenreplayAttribute(e, attr) {
60
60
  return false;
61
61
  }
62
62
  export function isIframeCrossdomain(e) {
63
+ var _a;
63
64
  try {
64
- return e.contentWindow?.location.href !== window.location.href;
65
+ return ((_a = e.contentWindow) === null || _a === void 0 ? void 0 : _a.location.href) !== window.location.href;
65
66
  }
66
67
  catch (e) {
67
68
  return true;
@@ -24,7 +24,7 @@ export function finder(input, options) {
24
24
  threshold: 1000,
25
25
  maxNumberOfTries: 10000,
26
26
  };
27
- config = { ...defaults, ...options };
27
+ config = Object.assign(Object.assign({}, defaults), options);
28
28
  rootDocument = findRootDocument(config.root, defaults);
29
29
  let path = bottomUpSearch(input, Limit.All, () => bottomUpSearch(input, Limit.Two, () => bottomUpSearch(input, Limit.One)));
30
30
  if (path) {
@@ -267,7 +267,7 @@ const defaultOptions = {
267
267
  wrap: false,
268
268
  };
269
269
  function cssesc(string, opt = {}) {
270
- const options = { ...defaultOptions, ...opt };
270
+ const options = Object.assign(Object.assign({}, defaultOptions), opt);
271
271
  if (options.quotes != 'single' && options.quotes != 'double') {
272
272
  options.quotes = 'single';
273
273
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openreplay/tracker",
3
3
  "description": "The OpenReplay tracker main package",
4
- "version": "7.0.1-beta.2",
4
+ "version": "7.0.1",
5
5
  "keywords": [
6
6
  "logging",
7
7
  "replay"
@@ -40,7 +40,7 @@
40
40
  "lint-staged": "^13.0.3",
41
41
  "prettier": "^2.7.1",
42
42
  "replace-in-files": "^2.0.3",
43
- "rollup": "^2.17.0",
43
+ "rollup": "^2.59.0",
44
44
  "rollup-plugin-terser": "^6.1.0",
45
45
  "semver": "^6.3.0",
46
46
  "ts-jest": "^29.0.3",
@@ -7,8 +7,8 @@
7
7
  "noImplicitThis": true,
8
8
  "strictNullChecks": true,
9
9
  "alwaysStrict": true,
10
- "target": "es2020",
11
- "module": "es2020",
10
+ "target": "es6",
11
+ "module": "es6",
12
12
  "moduleResolution": "nodenext"
13
13
  },
14
14
  "exclude": ["**/*.test.ts"]