@newrelic/browser-agent 1.243.1 → 1.245.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 (89) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/cdn/polyfills.js +4 -1
  3. package/dist/cjs/common/config/state/init.js +6 -0
  4. package/dist/cjs/common/constants/env.cdn.js +9 -3
  5. package/dist/cjs/common/constants/env.js +8 -2
  6. package/dist/cjs/common/constants/env.npm.js +9 -3
  7. package/dist/cjs/common/url/parse-url.js +9 -8
  8. package/dist/cjs/common/util/console.js +2 -2
  9. package/dist/cjs/common/util/type-check.js +14 -0
  10. package/dist/cjs/features/ajax/aggregate/gql.js +94 -0
  11. package/dist/cjs/features/ajax/aggregate/index.js +12 -1
  12. package/dist/cjs/features/ajax/instrument/index.js +2 -0
  13. package/dist/cjs/features/session_replay/aggregate/index.js +33 -23
  14. package/dist/cjs/features/spa/aggregate/index.js +3 -2
  15. package/dist/cjs/features/spa/aggregate/serializer.js +7 -0
  16. package/dist/cjs/index.js +0 -7
  17. package/dist/cjs/loaders/agent-base.js +3 -3
  18. package/dist/cjs/loaders/agent.js +1 -1
  19. package/dist/cjs/loaders/api/api.js +2 -2
  20. package/dist/esm/cdn/polyfills.js +4 -1
  21. package/dist/esm/common/config/state/init.js +6 -0
  22. package/dist/esm/common/constants/env.cdn.js +7 -2
  23. package/dist/esm/common/constants/env.js +6 -1
  24. package/dist/esm/common/constants/env.npm.js +7 -2
  25. package/dist/esm/common/url/parse-url.js +9 -8
  26. package/dist/esm/common/util/console.js +2 -2
  27. package/dist/esm/common/util/type-check.js +8 -0
  28. package/dist/esm/features/ajax/aggregate/gql.js +89 -0
  29. package/dist/esm/features/ajax/aggregate/index.js +12 -1
  30. package/dist/esm/features/ajax/instrument/index.js +2 -0
  31. package/dist/esm/features/session_replay/aggregate/index.js +31 -21
  32. package/dist/esm/features/spa/aggregate/index.js +3 -2
  33. package/dist/esm/features/spa/aggregate/serializer.js +7 -0
  34. package/dist/esm/index.js +0 -1
  35. package/dist/esm/loaders/agent-base.js +3 -3
  36. package/dist/esm/loaders/agent.js +1 -1
  37. package/dist/esm/loaders/api/api.js +2 -2
  38. package/dist/types/common/config/state/init.d.ts.map +1 -1
  39. package/dist/types/common/constants/env.cdn.d.ts +4 -0
  40. package/dist/types/common/constants/env.cdn.d.ts.map +1 -1
  41. package/dist/types/common/constants/env.d.ts +4 -0
  42. package/dist/types/common/constants/env.d.ts.map +1 -1
  43. package/dist/types/common/constants/env.npm.d.ts +4 -0
  44. package/dist/types/common/constants/env.npm.d.ts.map +1 -1
  45. package/dist/types/common/url/parse-url.d.ts.map +1 -1
  46. package/dist/types/common/util/console.d.ts +3 -3
  47. package/dist/types/common/util/console.d.ts.map +1 -1
  48. package/dist/types/common/util/type-check.d.ts +7 -0
  49. package/dist/types/common/util/type-check.d.ts.map +1 -0
  50. package/dist/types/features/ajax/aggregate/gql.d.ts +29 -0
  51. package/dist/types/features/ajax/aggregate/gql.d.ts.map +1 -0
  52. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  53. package/dist/types/features/session_replay/aggregate/index.d.ts +2 -1
  54. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  55. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  56. package/dist/types/features/spa/aggregate/serializer.d.ts.map +1 -1
  57. package/dist/types/index.d.ts +0 -1
  58. package/dist/types/loaders/agent-base.d.ts +2 -2
  59. package/dist/types/loaders/agent-base.d.ts.map +1 -1
  60. package/package.json +2 -10
  61. package/src/cdn/polyfills.js +3 -0
  62. package/src/common/config/state/init.js +3 -0
  63. package/src/common/constants/__mocks__/env.js +1 -0
  64. package/src/common/constants/env.cdn.js +5 -0
  65. package/src/common/constants/env.js +5 -0
  66. package/src/common/constants/env.npm.js +5 -0
  67. package/src/common/url/parse-url.js +9 -7
  68. package/src/common/util/console.js +2 -2
  69. package/src/common/util/type-check.js +8 -0
  70. package/src/features/ajax/aggregate/gql.js +95 -0
  71. package/src/features/ajax/aggregate/index.js +9 -1
  72. package/src/features/ajax/instrument/index.js +3 -0
  73. package/src/features/session_replay/aggregate/index.js +30 -22
  74. package/src/features/spa/aggregate/index.js +3 -2
  75. package/src/features/spa/aggregate/serializer.js +7 -1
  76. package/src/index.js +0 -1
  77. package/src/loaders/agent-base.js +3 -3
  78. package/src/loaders/agent.js +1 -1
  79. package/src/loaders/api/api.js +2 -2
  80. package/dist/cjs/cdn/worker.js +0 -16
  81. package/dist/cjs/loaders/worker-agent.js +0 -24
  82. package/dist/esm/cdn/worker.js +0 -14
  83. package/dist/esm/loaders/worker-agent.js +0 -18
  84. package/dist/types/cdn/worker.d.ts +0 -2
  85. package/dist/types/cdn/worker.d.ts.map +0 -1
  86. package/dist/types/loaders/worker-agent.d.ts +0 -8
  87. package/dist/types/loaders/worker-agent.d.ts.map +0 -1
  88. package/src/cdn/worker.js +0 -21
  89. package/src/loaders/worker-agent.js +0 -24
package/CHANGELOG.md CHANGED
@@ -3,6 +3,30 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.245.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.244.0...v1.245.0) (2023-10-18)
7
+
8
+
9
+ ### Features
10
+
11
+ * Allow boolean values in setCustomAttribute ([#776](https://github.com/newrelic/newrelic-browser-agent/issues/776)) ([d44f033](https://github.com/newrelic/newrelic-browser-agent/commit/d44f03384655f47c5f8a63db02f7eaac58585a86))
12
+ * Detect GraphQL operation names and types in AJAX calls ([#764](https://github.com/newrelic/newrelic-browser-agent/issues/764)) ([8587afc](https://github.com/newrelic/newrelic-browser-agent/commit/8587afc9dbc18a52048f467c77e5ededc225eb2a))
13
+ * Removing worker build ([#762](https://github.com/newrelic/newrelic-browser-agent/issues/762)) ([15f801b](https://github.com/newrelic/newrelic-browser-agent/commit/15f801b1a48c6e60f8f50f349aa382c77a073480))
14
+
15
+ ## [1.244.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.243.1...v1.244.0) (2023-10-10)
16
+
17
+
18
+ ### Features
19
+
20
+ * Add Session Replay configurations to collect inline assets ([#763](https://github.com/newrelic/newrelic-browser-agent/issues/763)) ([cef08dd](https://github.com/newrelic/newrelic-browser-agent/commit/cef08dd3f0cd99735dbc719e3c075fe83bbc6219))
21
+ * Bump rrweb to 2.0.0.11 and make constant dynamic at build time ([#770](https://github.com/newrelic/newrelic-browser-agent/issues/770)) ([9ea84cf](https://github.com/newrelic/newrelic-browser-agent/commit/9ea84cf247b31af544e2ea7ed0873241ff82eebc))
22
+ * Ensure 15 second minimum error buffer when possible ([#759](https://github.com/newrelic/newrelic-browser-agent/issues/759)) ([8506803](https://github.com/newrelic/newrelic-browser-agent/commit/8506803eaba27b7c603432f8ba0c909b677d3c3b))
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * Fix invalid timestamps ([#771](https://github.com/newrelic/newrelic-browser-agent/issues/771)) ([bc5a57c](https://github.com/newrelic/newrelic-browser-agent/commit/bc5a57c8c42c62c311e24b77f00dc1225a3b5873))
28
+ * Isolate browser interaction node ([#758](https://github.com/newrelic/newrelic-browser-agent/issues/758)) ([b9e8277](https://github.com/newrelic/newrelic-browser-agent/commit/b9e82773c67d710e0f6dc1f892908afc8be004cd))
29
+
6
30
  ## [1.243.1](https://github.com/newrelic/newrelic-browser-agent/compare/v1.243.0...v1.243.1) (2023-10-04)
7
31
 
8
32
 
@@ -10,8 +10,11 @@ require("core-js/stable/array/some");
10
10
  require("core-js/stable/object/assign");
11
11
  require("core-js/stable/object/entries");
12
12
  require("core-js/stable/object/values");
13
+ require("core-js/stable/object/from-entries");
13
14
  require("core-js/stable/map");
14
15
  require("core-js/stable/reflect");
15
16
  require("core-js/stable/set");
16
17
  require("core-js/stable/weak-set");
17
- require("core-js/stable/object/get-own-property-descriptors");
18
+ require("core-js/stable/object/get-own-property-descriptors");
19
+ require("core-js/stable/url");
20
+ require("core-js/stable/url-search-params");
@@ -110,6 +110,12 @@ const model = () => {
110
110
  // float from 0 - 100
111
111
  error_sampling_rate: 50,
112
112
  // float from 0 - 100
113
+ collect_fonts: false,
114
+ // serialize fonts for collection without public asset url, this is currently broken in RRWeb -- https://github.com/rrweb-io/rrweb/issues/1304. When fixed, revisit with test cases
115
+ inline_images: false,
116
+ // serialize images for collection without public asset url
117
+ inline_stylesheet: true,
118
+ // serialize css for collection without public asset url
113
119
  // recording config settings
114
120
  mask_all_inputs: true,
115
121
  // this has a getter/setter to facilitate validation of the selectors
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
6
+ exports.VERSION = exports.RRWEB_VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
7
7
  /**
8
8
  * @file This file exposes CDN build environment variables. These variables will
9
9
  * be overridden with babel.
@@ -12,7 +12,7 @@ exports.VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
12
12
  /**
13
13
  * Exposes the version of the agent
14
14
  */
15
- const VERSION = "1.243.1";
15
+ const VERSION = "1.245.0";
16
16
 
17
17
  /**
18
18
  * Exposes the build type of the agent
@@ -26,4 +26,10 @@ const BUILD_ENV = "CDN";
26
26
  */
27
27
  exports.BUILD_ENV = BUILD_ENV;
28
28
  const DIST_METHOD = 'CDN';
29
- exports.DIST_METHOD = DIST_METHOD;
29
+
30
+ /**
31
+ * Exposes the lib version of rrweb
32
+ */
33
+ exports.DIST_METHOD = DIST_METHOD;
34
+ const RRWEB_VERSION = "2.0.0-alpha.11";
35
+ exports.RRWEB_VERSION = RRWEB_VERSION;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
6
+ exports.VERSION = exports.RRWEB_VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
7
7
  var _package = _interopRequireDefault(require("../../../package.json"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
9
  /**
@@ -29,4 +29,10 @@ const BUILD_ENV = 'NPM';
29
29
  */
30
30
  exports.BUILD_ENV = BUILD_ENV;
31
31
  const DIST_METHOD = 'NPM';
32
- exports.DIST_METHOD = DIST_METHOD;
32
+
33
+ /**
34
+ * Exposes the lib version of rrweb
35
+ */
36
+ exports.DIST_METHOD = DIST_METHOD;
37
+ const RRWEB_VERSION = _package.default.dependencies.rrweb;
38
+ exports.RRWEB_VERSION = RRWEB_VERSION;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
6
+ exports.VERSION = exports.RRWEB_VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
7
7
  /**
8
8
  * @file This file exposes NPM build environment variables. These variables will
9
9
  * be overridden with babel.
@@ -12,7 +12,7 @@ exports.VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
12
12
  /**
13
13
  * Exposes the version of the agent
14
14
  */
15
- const VERSION = "1.243.1";
15
+ const VERSION = "1.245.0";
16
16
 
17
17
  /**
18
18
  * Exposes the build type of the agent
@@ -27,4 +27,10 @@ const BUILD_ENV = 'NPM';
27
27
  */
28
28
  exports.BUILD_ENV = BUILD_ENV;
29
29
  const DIST_METHOD = 'NPM';
30
- exports.DIST_METHOD = DIST_METHOD;
30
+
31
+ /**
32
+ * Exposes the lib version of rrweb
33
+ */
34
+ exports.DIST_METHOD = DIST_METHOD;
35
+ const RRWEB_VERSION = "2.0.0-alpha.11";
36
+ exports.RRWEB_VERSION = RRWEB_VERSION;
@@ -25,18 +25,19 @@ function parseUrl(url) {
25
25
  let urlEl;
26
26
  var location = _runtime.globalScope?.location;
27
27
  var ret = {};
28
- if (_runtime.isBrowserScope) {
29
- // Use an anchor dom element to resolve the url natively.
30
- urlEl = document.createElement('a');
31
- urlEl.href = url;
32
- } else {
33
- try {
34
- urlEl = new URL(url, location.href);
35
- } catch (err) {
28
+ try {
29
+ urlEl = new URL(url, location.href);
30
+ } catch (err) {
31
+ if (_runtime.isBrowserScope) {
32
+ // Use an anchor dom element to resolve the url natively.
33
+ urlEl = document.createElement('a');
34
+ urlEl.href = url;
35
+ } else {
36
36
  return ret;
37
37
  }
38
38
  }
39
39
  ret.port = urlEl.port;
40
+ ret.search = urlEl.search;
40
41
  var firstSplit = urlEl.href.split('://');
41
42
  if (!ret.port && firstSplit[1]) {
42
43
  ret.port = firstSplit[1].split('/')[0].split('@').pop().split(':')[1];
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.warn = warn;
7
7
  /**
8
8
  * A helper method to warn to the console with New Relic: decoration
9
- * @param {string} message - The primary message to warn
10
- * @param {*} secondary - Secondary data to include, usually an error or object
9
+ * @param {string} message The primary message to warn
10
+ * @param {*} [secondary] Secondary data to include, usually an error or object
11
11
  * @returns
12
12
  */
13
13
  function warn(message, secondary) {
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isPureObject = isPureObject;
7
+ /**
8
+ * Tests a passed object to see if it is a pure object or not. All non-primatives in JS
9
+ * are technically objects and would pass a `typeof` check.
10
+ * @param {*} obj Input object to be tested
11
+ **/
12
+ function isPureObject(obj) {
13
+ return obj?.constructor === {}.constructor;
14
+ }
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseGQL = parseGQL;
7
+ var _typeCheck = require("../../../common/util/type-check");
8
+ /**
9
+ * @typedef {object} GQLMetadata
10
+ * @property {string} operationName Name of the operation
11
+ * @property {string} operationType Type of the operation
12
+ * @property {string} operationFramework Framework responsible for the operation
13
+ */
14
+
15
+ /**
16
+ * Parses and returns the graphql metadata from a network request. If the network
17
+ * request is not a graphql call, undefined will be returned.
18
+ * @param {object|string} body Ajax request body
19
+ * @param {string} query Ajax request query param string
20
+ * @returns {GQLMetadata | undefined}
21
+ */
22
+ function parseGQL() {
23
+ let {
24
+ body,
25
+ query
26
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
27
+ if (!body && !query) return;
28
+ try {
29
+ const gqlBody = parseBatchGQL(parseGQLContents(body));
30
+ if (gqlBody) return gqlBody;
31
+ const gqlQuery = parseSingleGQL(parseGQLQueryString(query));
32
+ if (gqlQuery) return gqlQuery;
33
+ } catch (err) {
34
+ // parsing failed, return undefined
35
+ }
36
+ }
37
+
38
+ /**
39
+ * @param {string|Object} gql The GraphQL object body sent to a GQL server
40
+ * @returns {GQLMetadata}
41
+ */
42
+ function parseSingleGQL(contents) {
43
+ if (typeof contents !== 'object' || !contents.query || typeof contents.query !== 'string') return;
44
+
45
+ /** parses gql query string and returns [fullmatch, type match, name match] */
46
+ const matches = contents.query.trim().match(/^(query|mutation|subscription)\s?(\w*)/);
47
+ const operationType = matches?.[1];
48
+ if (!operationType) return;
49
+ const operationName = contents.operationName || matches?.[2] || 'Anonymous';
50
+ return {
51
+ operationName,
52
+ // the operation name of the indiv query
53
+ operationType,
54
+ // query, mutation, or subscription,
55
+ operationFramework: 'GraphQL'
56
+ };
57
+ }
58
+ function parseBatchGQL(contents) {
59
+ if (!contents) return;
60
+ if (!Array.isArray(contents)) contents = [contents];
61
+ const opNames = [];
62
+ const opTypes = [];
63
+ for (let content of contents) {
64
+ const operation = parseSingleGQL(content);
65
+ if (!operation) continue;
66
+ opNames.push(operation.operationName);
67
+ opTypes.push(operation.operationType);
68
+ }
69
+ if (!opTypes.length) return;
70
+ return {
71
+ operationName: opNames.join(','),
72
+ // the operation name of the indiv query -- joined by ',' for batched results
73
+ operationType: opTypes.join(','),
74
+ // query, mutation, or subscription -- joined by ',' for batched results
75
+ operationFramework: 'GraphQL'
76
+ };
77
+ }
78
+ function parseGQLContents(gqlContents) {
79
+ let contents;
80
+ if (!gqlContents || typeof gqlContents !== 'string' && typeof gqlContents !== 'object') return;else if (typeof gqlContents === 'string') contents = JSON.parse(gqlContents);else contents = gqlContents;
81
+ if (!(0, _typeCheck.isPureObject)(contents) && !Array.isArray(contents)) return;
82
+ let isValid = false;
83
+ if (Array.isArray(contents)) isValid = contents.some(x => validateGQLObject(x));else isValid = validateGQLObject(contents);
84
+ if (!isValid) return;
85
+ return contents;
86
+ }
87
+ function parseGQLQueryString(gqlQueryString) {
88
+ if (!gqlQueryString || typeof gqlQueryString !== 'string') return;
89
+ const params = new URLSearchParams(gqlQueryString);
90
+ return parseGQLContents(Object.fromEntries(params));
91
+ }
92
+ function validateGQLObject(obj) {
93
+ return !(typeof obj !== 'object' || !obj.query || typeof obj.query !== 'string');
94
+ }
@@ -15,6 +15,7 @@ var _constants = require("../constants");
15
15
  var _features = require("../../../loaders/features/features");
16
16
  var _constants2 = require("../../metrics/constants");
17
17
  var _aggregateBase = require("../../utils/aggregate-base");
18
+ var _gql = require("./gql");
18
19
  /*
19
20
  * Copyright 2020 New Relic Corporation. All rights reserved.
20
21
  * SPDX-License-Identifier: Apache-2.0
@@ -116,6 +117,12 @@ class Aggregate extends _aggregateBase.AggregateBase {
116
117
  event.spanTimestamp = xhrContext.dt.timestamp;
117
118
  }
118
119
 
120
+ // parsed from the AJAX body, looking for operationName param & parsing query for operationType
121
+ event.gql = params.gql = (0, _gql.parseGQL)({
122
+ body: this.body,
123
+ query: this?.parsedOrigin?.search
124
+ });
125
+
119
126
  // if the ajax happened inside an interaction, hold it until the interaction finishes
120
127
  if (this.spaNode) {
121
128
  var interactionId = this.spaNode.interaction.id;
@@ -205,7 +212,11 @@ class Aggregate extends _aggregateBase.AggregateBase {
205
212
  var insert = '2,';
206
213
 
207
214
  // add custom attributes
208
- var attrParts = (0, _belSerializer.addCustomAttributes)((0, _config.getInfo)(agentIdentifier).jsAttributes || {}, this.addString);
215
+ // gql decorators are added as custom attributes to alleviate need for new BEL schema
216
+ var attrParts = (0, _belSerializer.addCustomAttributes)({
217
+ ...((0, _config.getInfo)(agentIdentifier).jsAttributes || {}),
218
+ ...(event.gql || {})
219
+ }, this.addString);
209
220
  fields.unshift((0, _belSerializer.numeric)(attrParts.length));
210
221
  insert += fields.join(',');
211
222
  if (attrParts && attrParts.length > 0) {
@@ -161,6 +161,7 @@ function subscribeToEvents(agentIdentifier, ee, handler, dt) {
161
161
  if (size) metrics.txSize = size;
162
162
  }
163
163
  this.startTime = (0, _now.now)();
164
+ this.body = data;
164
165
  this.listener = function (evt) {
165
166
  try {
166
167
  if (evt.type === 'abort' && !context.loadCaptureCalled) {
@@ -308,6 +309,7 @@ function subscribeToEvents(agentIdentifier, ee, handler, dt) {
308
309
  addUrl(this, url);
309
310
  var method = ('' + (target && target instanceof origRequest && target.method || opts.method || 'GET')).toUpperCase();
310
311
  this.params.method = method;
312
+ this.body = opts.body;
311
313
  this.txSize = (0, _dataSize.dataSize)(opts.body) || 0;
312
314
  }
313
315
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.RRWEB_VERSION = exports.RRWEB_EVENT_TYPES = exports.MAX_PAYLOAD_SIZE = exports.IDEAL_PAYLOAD_SIZE = exports.Aggregate = exports.AVG_COMPRESSION = void 0;
6
+ exports.RRWEB_EVENT_TYPES = exports.MAX_PAYLOAD_SIZE = exports.IDEAL_PAYLOAD_SIZE = exports.Aggregate = exports.AVG_COMPRESSION = void 0;
7
7
  var _registerHandler = require("../../../common/event-emitter/register-handler");
8
8
  var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
9
9
  var _constants = require("../constants");
@@ -18,6 +18,7 @@ var _runtime = require("../../../common/constants/runtime");
18
18
  var _constants2 = require("../../metrics/constants");
19
19
  var _handle = require("../../../common/event-emitter/handle");
20
20
  var _features = require("../../../loaders/features/features");
21
+ var _env = require("../../../common/constants/env.npm");
21
22
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
22
23
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } /*
23
24
  * Copyright 2023 New Relic Corporation. All rights reserved.
@@ -29,9 +30,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
29
30
  * It is not production ready, and is not intended to be imported or implemented in any build of the browser agent until
30
31
  * functionality is validated and a full user experience is curated.
31
32
  */
32
- // would be better to get this dynamically in some way
33
- const RRWEB_VERSION = '2.0.0-alpha.8';
34
- exports.RRWEB_VERSION = RRWEB_VERSION;
35
33
  const AVG_COMPRESSION = 0.12;
36
34
  exports.AVG_COMPRESSION = AVG_COMPRESSION;
37
35
  const RRWEB_EVENT_TYPES = {
@@ -72,10 +70,10 @@ const MAX_PAYLOAD_SIZE = 1000000;
72
70
  /** Unloading caps around 64kb */
73
71
  exports.MAX_PAYLOAD_SIZE = MAX_PAYLOAD_SIZE;
74
72
  const IDEAL_PAYLOAD_SIZE = 64000;
75
- /** Interval between forcing new full snapshots -- 30 seconds in error mode, 5 minutes in full mode */
73
+ /** Interval between forcing new full snapshots -- 15 seconds in error mode (x2), 5 minutes in full mode */
76
74
  exports.IDEAL_PAYLOAD_SIZE = IDEAL_PAYLOAD_SIZE;
77
75
  const CHECKOUT_MS = {
78
- [_sessionEntity.MODE.ERROR]: 30000,
76
+ [_sessionEntity.MODE.ERROR]: 15000,
79
77
  [_sessionEntity.MODE.FULL]: 300000,
80
78
  [_sessionEntity.MODE.OFF]: 0
81
79
  };
@@ -85,6 +83,8 @@ class Aggregate extends _aggregateBase.AggregateBase {
85
83
  super(agentIdentifier, aggregator, _constants.FEATURE_NAME);
86
84
  /** Each page mutation or event will be stored (raw) in this array. This array will be cleared on each harvest */
87
85
  this.events = [];
86
+ /** Backlog used for a 2-part sliding window to guarantee a 15-30s buffer window */
87
+ this.backloggedEvents = [];
88
88
  /** The interval to harvest at. This gets overridden if the size of the payload exceeds certain thresholds */
89
89
  this.harvestTimeSeconds = (0, _config.getConfigurationValue)(this.agentIdentifier, 'session_replay.harvestTimeSeconds') || 60;
90
90
  /** Set once the recorder has fully initialized after flag checks and sampling */
@@ -254,6 +254,10 @@ class Aggregate extends _aggregateBase.AggregateBase {
254
254
  prepareHarvest() {
255
255
  if (this.events.length === 0 || this.mode !== _sessionEntity.MODE.FULL && !this.blocked) return;
256
256
  const payload = this.getHarvestContents();
257
+ if (!payload.body.length) {
258
+ this.clearBuffer();
259
+ return;
260
+ }
257
261
  if (this.shouldCompress) {
258
262
  payload.body = gzipper(u8((0, _stringify.stringify)(payload.body)));
259
263
  this.scheduler.opts.gzip = true;
@@ -273,6 +277,16 @@ class Aggregate extends _aggregateBase.AggregateBase {
273
277
  getHarvestContents() {
274
278
  const agentRuntime = (0, _config.getRuntime)(this.agentIdentifier);
275
279
  const info = (0, _config.getInfo)(this.agentIdentifier);
280
+ if (this.backloggedEvents.length) this.events = [...this.backloggedEvents, ...this.events];
281
+
282
+ // do not let the first node be a full snapshot node, since this NEEDS to be preceded by a meta node
283
+ // we will manually inject it if this happens
284
+ const payloadStartsWithFullSnapshot = this.events[0]?.type === RRWEB_EVENT_TYPES.FullSnapshot;
285
+ if (payloadStartsWithFullSnapshot && !!this.lastMeta) {
286
+ this.hasMeta = true;
287
+ this.events.unshift(this.lastMeta); // --> pushed the meta from a previous payload into newer payload... but it still has old timestamps
288
+ this.lastMeta = undefined;
289
+ }
276
290
 
277
291
  // do not let the last node be a meta node, since this NEEDS to precede a snapshot
278
292
  // we will manually inject it later if we find a payload that is missing a meta node
@@ -282,16 +296,8 @@ class Aggregate extends _aggregateBase.AggregateBase {
282
296
  this.events = this.events.slice(0, this.events.length - 1);
283
297
  this.hasMeta = !!this.events.find(x => x.type === RRWEB_EVENT_TYPES.Meta);
284
298
  }
285
-
286
- // do not let the first node be a full snapshot node, since this NEEDS to be preceded by a meta node
287
- // we will manually inject it if this happens
288
- const payloadStartsWithFullSnapshot = this.events[0]?.type === RRWEB_EVENT_TYPES.FullSnapshot;
289
- if (payloadStartsWithFullSnapshot) {
290
- this.hasMeta = true;
291
- this.events.unshift(this.lastMeta);
292
- }
293
- const firstEventTimestamp = this.events[0]?.timestamp;
294
- const lastEventTimestamp = this.events[this.events.length - 1]?.timestamp;
299
+ const firstEventTimestamp = this.events[0]?.timestamp; // from rrweb node
300
+ const lastEventTimestamp = this.events[this.events.length - 1]?.timestamp; // from rrweb node
295
301
  const firstTimestamp = firstEventTimestamp || this.cycleTimestamp;
296
302
  const lastTimestamp = lastEventTimestamp || (0, _config.getRuntime)(this.agentIdentifier).offset + _runtime.globalScope.performance.now();
297
303
  return {
@@ -315,7 +321,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
315
321
  hasError: this.hasError,
316
322
  isFirstChunk: agentRuntime.session.state.sessionReplaySentFirstChunk === false,
317
323
  decompressedBytes: this.payloadBytesEstimation,
318
- 'nr.rrweb.version': RRWEB_VERSION
324
+ 'nr.rrweb.version': _env.RRWEB_VERSION
319
325
  }, MAX_PAYLOAD_SIZE - this.payloadBytesEstimation).substring(1) // remove the leading '&'
320
326
  },
321
327
 
@@ -332,6 +338,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
332
338
 
333
339
  /** Clears the buffer (this.events), and resets all payload metadata properties */
334
340
  clearBuffer() {
341
+ if (this.mode === _sessionEntity.MODE.ERROR) this.backloggedEvents = this.events;else this.backloggedEvents = [];
335
342
  this.events = [];
336
343
  this.hasSnapshot = false;
337
344
  this.hasMeta = false;
@@ -346,9 +353,6 @@ class Aggregate extends _aggregateBase.AggregateBase {
346
353
  (0, _console.warn)('Recording library was never imported');
347
354
  return this.abort(ABORT_REASONS.IMPORT);
348
355
  }
349
- this.clearTimestamps();
350
- // set the fallbacks as early as possible
351
- this.setTimestamps();
352
356
  this.recording = true;
353
357
  const {
354
358
  block_class,
@@ -357,7 +361,10 @@ class Aggregate extends _aggregateBase.AggregateBase {
357
361
  block_selector,
358
362
  mask_input_options,
359
363
  mask_text_selector,
360
- mask_all_inputs
364
+ mask_all_inputs,
365
+ inline_images,
366
+ inline_stylesheet,
367
+ collect_fonts
361
368
  } = (0, _config.getConfigurationValue)(this.agentIdentifier, 'session_replay');
362
369
  // set up rrweb configurations for maximum privacy --
363
370
  // https://newrelic.atlassian.net/wiki/spaces/O11Y/pages/2792293280/2023+02+28+Browser+-+Session+Replay#Configuration-options
@@ -370,6 +377,9 @@ class Aggregate extends _aggregateBase.AggregateBase {
370
377
  maskInputOptions: mask_input_options,
371
378
  maskTextSelector: mask_text_selector,
372
379
  maskAllInputs: mask_all_inputs,
380
+ inlineImages: inline_images,
381
+ inlineStylesheet: inline_stylesheet,
382
+ collectFonts: collect_fonts,
373
383
  checkoutEveryNms: CHECKOUT_MS[this.mode]
374
384
  });
375
385
  this.stopRecording = () => {
@@ -393,7 +403,8 @@ class Aggregate extends _aggregateBase.AggregateBase {
393
403
  // Checkout events are flags by the recording lib that indicate a fullsnapshot was taken every n ms. These are important
394
404
  // to help reconstruct the replay later and must be included. While waiting and buffering for errors to come through,
395
405
  // each time we see a new checkout, we can drop the old data.
396
- if (this.mode === _sessionEntity.MODE.ERROR && isCheckout) {
406
+ // we need to check for meta because rrweb will flag it as checkout twice, once for meta, then once for snapshot
407
+ if (this.mode === _sessionEntity.MODE.ERROR && isCheckout && event.type === RRWEB_EVENT_TYPES.Meta) {
397
408
  // we are still waiting for an error to throw, so keep wiping the buffer over time
398
409
  this.clearBuffer();
399
410
  }
@@ -401,7 +412,6 @@ class Aggregate extends _aggregateBase.AggregateBase {
401
412
  // meta event
402
413
  if (event.type === RRWEB_EVENT_TYPES.Meta) {
403
414
  this.hasMeta = true;
404
- this.lastMeta = event;
405
415
  }
406
416
  // snapshot event
407
417
  if (event.type === RRWEB_EVENT_TYPES.FullSnapshot) {
@@ -21,6 +21,7 @@ var _features = require("../../../loaders/features/features");
21
21
  var _aggregateBase = require("../../utils/aggregate-base");
22
22
  var _firstContentfulPaint = require("../../../common/vitals/first-contentful-paint");
23
23
  var _firstPaint = require("../../../common/vitals/first-paint");
24
+ var _bundleId = require("../../../common/ids/bundle-id");
24
25
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
26
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
26
27
  /*
@@ -182,7 +183,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
182
183
  (0, _registerHandler.registerHandler)(FN_START, function (args, eventSource) {
183
184
  var ev = args[0];
184
185
  var evName = ev.type;
185
- var eventNode = ev.__nrNode;
186
+ var eventNode = ev["__nrNode:".concat(_bundleId.bundleId)];
186
187
  if (!state.pageLoaded && evName === 'load' && eventSource === window) {
187
188
  state.pageLoaded = true;
188
189
  // set to null so prevNode is set correctly
@@ -226,7 +227,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
226
227
  }
227
228
  }
228
229
  }
229
- ev.__nrNode = state.currentNode;
230
+ ev["__nrNode:".concat(_bundleId.bundleId)] = state.currentNode;
230
231
  }, this.featureName, eventsEE);
231
232
 
232
233
  /**
@@ -91,6 +91,13 @@ class Serializer extends _sharedContext.SharedContext {
91
91
  break;
92
92
  case 2:
93
93
  fields.push(addString(params.method), (0, _belSerializer.numeric)(params.status), addString(params.host), addString(params.pathname), (0, _belSerializer.numeric)(metrics.txSize), (0, _belSerializer.numeric)(metrics.rxSize), attrs.isFetch ? 1 : attrs.isJSONP ? 2 : '', addString(node.id), (0, _belSerializer.nullable)(node.dt && node.dt.spanId, addString, true) + (0, _belSerializer.nullable)(node.dt && node.dt.traceId, addString, true) + (0, _belSerializer.nullable)(node.dt && node.dt.timestamp, _belSerializer.numeric, false));
94
+
95
+ // add params.gql here
96
+ if (Object.keys(params?.gql || {}).length) {
97
+ var ajaxAttrParts = (0, _belSerializer.addCustomAttributes)(params.gql, addString);
98
+ children = children.concat(ajaxAttrParts);
99
+ attrCount = ajaxAttrParts.length;
100
+ }
94
101
  break;
95
102
  case 4:
96
103
  var tracedTime = attrs.tracedTime;
package/dist/cjs/index.js CHANGED
@@ -69,15 +69,8 @@ Object.defineProperty(exports, "Spa", {
69
69
  return _spa.Spa;
70
70
  }
71
71
  });
72
- Object.defineProperty(exports, "WorkerAgent", {
73
- enumerable: true,
74
- get: function () {
75
- return _workerAgent.WorkerAgent;
76
- }
77
- });
78
72
  var _agent = require("./loaders/agent");
79
73
  var _browserAgent = require("./loaders/browser-agent");
80
- var _workerAgent = require("./loaders/worker-agent");
81
74
  var _microAgent = require("./loaders/micro-agent");
82
75
  var _ajax = require("./features/ajax");
83
76
  var _jserrors = require("./features/jserrors");
@@ -15,7 +15,7 @@ class AgentBase {
15
15
  * @param {object} [attributes] JSON object with one or more key/value pairs. For example: {key:"value"}. The key is reported as its own PageAction attribute with the specified values.
16
16
  */
17
17
  addPageAction(name, attributes) {
18
- (0, _console.warn)('Call to agent api addPageAction failed. The session trace feature is not currently initialized.');
18
+ (0, _console.warn)('Call to agent api addPageAction failed. The page action feature is not currently initialized.');
19
19
  }
20
20
 
21
21
  /**
@@ -95,13 +95,13 @@ class AgentBase {
95
95
  * @param {string} id The ID or version of this release; for example, a version number, build number from your CI environment, GitHub SHA, GUID, or a hash of the contents.
96
96
  */
97
97
  addRelease(name, id) {
98
- (0, _console.warn)('Call to agent api addRelease failed. The agent is not currently initialized.');
98
+ (0, _console.warn)('Call to agent api addRelease failed. The js errors feature is not currently initialized.');
99
99
  }
100
100
 
101
101
  /**
102
102
  * Starts a set of agent features if not running in "autoStart" mode
103
103
  * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/start/}
104
- * @param {string|string[]|undefined} name The feature name(s) to start. If no name(s) are passed, all features will be started
104
+ * @param {string|string[]} [featureNames] The name(s) of the features to start. If no name(s) are passed, all features will be started
105
105
  */
106
106
  start(featureNames) {
107
107
  (0, _console.warn)('Call to agent api addRelease failed. The agent is not currently initialized.');
@@ -112,7 +112,7 @@ class Agent extends _agentBase.AgentBase {
112
112
  * If you are sending the same event object to New Relic as a PageAction, omit the TYPE attribute. (type is a string to describe what type of event you are marking inside of a session trace.) If included, it will override the event type and cause the PageAction event to be sent incorrectly. Instead, use the name attribute for event information.
113
113
  */
114
114
  addToTrace(customAttributes) {
115
- (0, _console.warn)('Call to agent api addToTrace failed. The page action feature is not currently initialized.');
115
+ (0, _console.warn)('Call to agent api addToTrace failed. The session trace feature is not currently initialized.');
116
116
  }
117
117
 
118
118
  /**
@@ -99,8 +99,8 @@ function setAPI(agentIdentifier, forceDrain) {
99
99
  (0, _console.warn)("Failed to execute setCustomAttribute.\nName must be a string type, but a type of <".concat(typeof name, "> was provided."));
100
100
  return;
101
101
  }
102
- if (!(['string', 'number'].includes(typeof value) || value === null)) {
103
- (0, _console.warn)("Failed to execute setCustomAttribute.\nNon-null value must be a string or number type, but a type of <".concat(typeof value, "> was provided."));
102
+ if (!(['string', 'number', 'boolean'].includes(typeof value) || value === null)) {
103
+ (0, _console.warn)("Failed to execute setCustomAttribute.\nNon-null value must be a string, number or boolean type, but a type of <".concat(typeof value, "> was provided."));
104
104
  return;
105
105
  }
106
106
  return appendJsAttribute(name, value, 'setCustomAttribute', persistAttribute);
@@ -13,8 +13,11 @@ import 'core-js/stable/array/some';
13
13
  import 'core-js/stable/object/assign';
14
14
  import 'core-js/stable/object/entries';
15
15
  import 'core-js/stable/object/values';
16
+ import 'core-js/stable/object/from-entries';
16
17
  import 'core-js/stable/map';
17
18
  import 'core-js/stable/reflect';
18
19
  import 'core-js/stable/set';
19
20
  import 'core-js/stable/weak-set';
20
- import 'core-js/stable/object/get-own-property-descriptors';
21
+ import 'core-js/stable/object/get-own-property-descriptors';
22
+ import 'core-js/stable/url';
23
+ import 'core-js/stable/url-search-params';
@@ -102,6 +102,12 @@ const model = () => {
102
102
  // float from 0 - 100
103
103
  error_sampling_rate: 50,
104
104
  // float from 0 - 100
105
+ collect_fonts: false,
106
+ // serialize fonts for collection without public asset url, this is currently broken in RRWeb -- https://github.com/rrweb-io/rrweb/issues/1304. When fixed, revisit with test cases
107
+ inline_images: false,
108
+ // serialize images for collection without public asset url
109
+ inline_stylesheet: true,
110
+ // serialize css for collection without public asset url
105
111
  // recording config settings
106
112
  mask_all_inputs: true,
107
113
  // this has a getter/setter to facilitate validation of the selectors