@newrelic/browser-agent 1.241.0 → 1.243.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 (132) hide show
  1. package/CHANGELOG.md +1465 -0
  2. package/dist/cjs/cdn/polyfills/lite.js +13 -1
  3. package/dist/cjs/cdn/polyfills/pro.js +17 -1
  4. package/dist/cjs/cdn/polyfills/spa.js +18 -1
  5. package/dist/cjs/common/config/state/init.js +32 -5
  6. package/dist/cjs/common/constants/env.cdn.js +1 -1
  7. package/dist/cjs/common/constants/env.npm.js +1 -1
  8. package/dist/cjs/common/dom/query-selector.js +16 -0
  9. package/dist/cjs/common/session/session-entity.js +20 -2
  10. package/dist/cjs/common/wrap/wrap-function.js +1 -1
  11. package/dist/cjs/features/ajax/aggregate/index.js +1 -1
  12. package/dist/cjs/features/session_replay/aggregate/index.js +84 -50
  13. package/dist/cjs/features/utils/feature-base.js +1 -2
  14. package/dist/cjs/features/utils/instrument-base.js +1 -0
  15. package/dist/cjs/loaders/api/api.js +2 -2
  16. package/dist/cjs/loaders/api/apiAsync.js +0 -37
  17. package/dist/cjs/loaders/configure/configure.js +1 -1
  18. package/dist/cjs/loaders/configure/public-path.js +6 -3
  19. package/dist/esm/cdn/polyfills/lite.js +8 -1
  20. package/dist/esm/cdn/polyfills/pro.js +13 -2
  21. package/dist/esm/cdn/polyfills/spa.js +13 -1
  22. package/dist/esm/common/config/state/init.js +32 -5
  23. package/dist/esm/common/constants/env.cdn.js +1 -1
  24. package/dist/esm/common/constants/env.npm.js +1 -1
  25. package/dist/esm/common/dom/query-selector.js +9 -0
  26. package/dist/esm/common/session/session-entity.js +18 -1
  27. package/dist/esm/common/wrap/wrap-function.js +1 -1
  28. package/dist/esm/features/ajax/aggregate/index.js +1 -1
  29. package/dist/esm/features/session_replay/aggregate/index.js +83 -50
  30. package/dist/esm/features/utils/feature-base.js +1 -2
  31. package/dist/esm/features/utils/instrument-base.js +1 -0
  32. package/dist/esm/loaders/api/api.js +2 -2
  33. package/dist/esm/loaders/api/apiAsync.js +1 -36
  34. package/dist/esm/loaders/configure/configure.js +1 -1
  35. package/dist/esm/loaders/configure/public-path.js +6 -3
  36. package/dist/types/common/config/state/init.d.ts.map +1 -1
  37. package/dist/types/common/dom/query-selector.d.ts +2 -0
  38. package/dist/types/common/dom/query-selector.d.ts.map +1 -0
  39. package/dist/types/common/session/session-entity.d.ts +5 -0
  40. package/dist/types/common/session/session-entity.d.ts.map +1 -1
  41. package/dist/types/features/session_replay/aggregate/index.d.ts +11 -14
  42. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  43. package/dist/types/features/utils/feature-base.d.ts.map +1 -1
  44. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  45. package/dist/types/loaders/api/api.d.ts.map +1 -1
  46. package/dist/types/loaders/api/apiAsync.d.ts.map +1 -1
  47. package/dist/types/loaders/configure/public-path.d.ts +1 -1
  48. package/dist/types/loaders/configure/public-path.d.ts.map +1 -1
  49. package/package.json +2 -2
  50. package/src/cdn/polyfills/lite.js +14 -1
  51. package/src/cdn/polyfills/pro.js +23 -2
  52. package/src/cdn/polyfills/spa.js +24 -1
  53. package/src/common/config/state/init.js +33 -4
  54. package/src/common/dom/query-selector.js +9 -0
  55. package/src/common/session/session-entity.js +20 -1
  56. package/src/common/wrap/wrap-function.js +1 -1
  57. package/src/features/ajax/aggregate/index.js +2 -2
  58. package/src/features/session_replay/aggregate/index.js +82 -34
  59. package/src/features/utils/feature-base.js +1 -2
  60. package/src/features/utils/instrument-base.js +1 -0
  61. package/src/loaders/api/api.js +1 -2
  62. package/src/loaders/api/apiAsync.js +1 -39
  63. package/src/loaders/configure/configure.js +1 -1
  64. package/src/loaders/configure/public-path.js +6 -3
  65. package/src/common/aggregate/aggregator.test.js +0 -107
  66. package/src/common/config/state/configurable.test.js +0 -73
  67. package/src/common/config/state/info.test.js +0 -31
  68. package/src/common/config/state/init.test.js +0 -28
  69. package/src/common/config/state/loader-config.test.js +0 -21
  70. package/src/common/config/state/runtime.test.js +0 -21
  71. package/src/common/constants/env.cdn.test.js +0 -7
  72. package/src/common/constants/env.npm.test.js +0 -7
  73. package/src/common/constants/env.test.js +0 -7
  74. package/src/common/constants/runtime.test.js +0 -176
  75. package/src/common/deny-list/deny-list.test.js +0 -104
  76. package/src/common/drain/drain.test.js +0 -74
  77. package/src/common/event-emitter/contextual-ee.component-test.js +0 -293
  78. package/src/common/event-emitter/handle.test.js +0 -56
  79. package/src/common/event-emitter/register-handler.test.js +0 -61
  80. package/src/common/harvest/harvest-scheduler.test.js +0 -492
  81. package/src/common/harvest/harvest.test.js +0 -813
  82. package/src/common/ids/id.test.js +0 -92
  83. package/src/common/ids/unique-id.test.js +0 -58
  84. package/src/common/session/session-entity.component-test.js +0 -346
  85. package/src/common/storage/local-storage.test.js +0 -17
  86. package/src/common/timer/interaction-timer.component-test.js +0 -212
  87. package/src/common/timer/timer.test.js +0 -99
  88. package/src/common/timing/nav-timing.test.js +0 -161
  89. package/src/common/url/canonicalize-url.test.js +0 -45
  90. package/src/common/url/clean-url.test.js +0 -25
  91. package/src/common/url/encode.test.js +0 -81
  92. package/src/common/url/location.test.js +0 -15
  93. package/src/common/url/parse-url.test.js +0 -110
  94. package/src/common/url/protocol.test.js +0 -17
  95. package/src/common/util/console.test.js +0 -34
  96. package/src/common/util/data-size.test.js +0 -56
  97. package/src/common/util/feature-flags.test.js +0 -94
  98. package/src/common/util/get-or-set.test.js +0 -58
  99. package/src/common/util/invoke.test.js +0 -65
  100. package/src/common/util/map-own.test.js +0 -52
  101. package/src/common/util/obfuscate.component-test.js +0 -173
  102. package/src/common/util/stringify.test.js +0 -49
  103. package/src/common/util/submit-data.test.js +0 -183
  104. package/src/common/util/traverse.test.js +0 -50
  105. package/src/common/vitals/cumulative-layout-shift.test.js +0 -71
  106. package/src/common/vitals/first-contentful-paint.test.js +0 -124
  107. package/src/common/vitals/first-input-delay.test.js +0 -88
  108. package/src/common/vitals/first-paint.test.js +0 -127
  109. package/src/common/vitals/interaction-to-next-paint.test.js +0 -74
  110. package/src/common/vitals/largest-contentful-paint.test.js +0 -94
  111. package/src/common/vitals/long-task.test.js +0 -122
  112. package/src/common/vitals/time-to-first-byte.test.js +0 -147
  113. package/src/common/vitals/vital-metric.test.js +0 -171
  114. package/src/common/wrap/wrap-promise.component-test.js +0 -110
  115. package/src/features/ajax/instrument/distributed-tracing.test.js +0 -375
  116. package/src/features/jserrors/aggregate/canonical-function-name.test.js +0 -13
  117. package/src/features/jserrors/aggregate/compute-stack-trace.test.js +0 -414
  118. package/src/features/jserrors/aggregate/format-stack-trace.test.js +0 -39
  119. package/src/features/jserrors/aggregate/string-hash-code.test.js +0 -12
  120. package/src/features/metrics/aggregate/framework-detection.test.js +0 -332
  121. package/src/features/page_view_timing/aggregate/index.component-test.js +0 -86
  122. package/src/features/session_replay/aggregate/index.component-test.js +0 -317
  123. package/src/features/spa/aggregate/interaction-node.test.js +0 -17
  124. package/src/features/utils/agent-session.test.js +0 -194
  125. package/src/features/utils/aggregate-base.test.js +0 -123
  126. package/src/features/utils/feature-base.test.js +0 -45
  127. package/src/features/utils/handler-cache.test.js +0 -72
  128. package/src/features/utils/instrument-base.test.js +0 -216
  129. package/src/features/utils/lazy-feature-loader.test.js +0 -37
  130. package/src/loaders/api/api.component-test.js +0 -45
  131. package/src/loaders/api/api.test.js +0 -85
  132. package/src/loaders/api/apiAsync.test.js +0 -17
@@ -1,332 +0,0 @@
1
- import { faker } from '@faker-js/faker'
2
- import { getFrameworks } from './framework-detection'
3
-
4
- jest.mock('../../../common/constants/runtime', () => ({
5
- isBrowserScope: true
6
- }))
7
-
8
- afterEach(() => {
9
- document.body.innerHTML = ''
10
- })
11
-
12
- test('framework detection should not happen in non-browser scope', async () => {
13
- global.React = {}
14
-
15
- jest.resetModules()
16
- jest.doMock('../../../common/constants/runtime', () => ({
17
- isBrowserScope: false
18
- }))
19
- const frameworkDetector = await import('./framework-detection')
20
-
21
- expect(frameworkDetector.getFrameworks()).toEqual([])
22
-
23
- delete global.React
24
- })
25
-
26
- describe('react', () => {
27
- test('should detect react from global React property', () => {
28
- global.React = {}
29
-
30
- expect(getFrameworks()).toEqual(['React'])
31
-
32
- delete global.React
33
- })
34
-
35
- test('should detect react from global ReactDOM property', () => {
36
- global.ReactDOM = {}
37
-
38
- expect(getFrameworks()).toEqual(['React'])
39
-
40
- delete global.ReactDOM
41
- })
42
-
43
- test('should detect react from global ReactRedux property', () => {
44
- global.ReactRedux = {}
45
-
46
- expect(getFrameworks()).toEqual(['React'])
47
-
48
- delete global.ReactRedux
49
- })
50
-
51
- test('should detect react from html [data-reactroot] property', () => {
52
- document.body.innerHTML = '<div data-reactroot=""></div>'
53
-
54
- expect(getFrameworks()).toEqual(['React'])
55
- })
56
-
57
- test('should detect react from html [data-reactid] property', () => {
58
- document.body.innerHTML = '<div data-reactid=""></div>'
59
-
60
- expect(getFrameworks()).toEqual(['React'])
61
- })
62
-
63
- test('should detect react from element _reactRootContainer property', () => {
64
- const element = document.createElement('div')
65
- element._reactRootContainer = {}
66
- document.body.innerHTML = '<html><body></body></html>'
67
- document.body.appendChild(element)
68
-
69
- expect(getFrameworks()).toEqual(['React'])
70
- })
71
-
72
- describe('nextjs', () => {
73
- test('should not detect nextjs if react is not detected', () => {
74
- global.next = { version: 'test' }
75
-
76
- expect(getFrameworks()).toEqual([])
77
-
78
- delete global.next
79
- })
80
-
81
- test('should detect nextjs if global is set', () => {
82
- global.React = {}
83
- global.next = { version: 'test' }
84
-
85
- expect(getFrameworks()).toEqual(['React', 'NextJS'])
86
-
87
- delete global.React
88
- delete global.next
89
- })
90
- })
91
- })
92
-
93
- describe('vue', () => {
94
- test('should detect vue from global Vue property', () => {
95
- global.Vue = {}
96
-
97
- expect(getFrameworks()).toEqual(['Vue'])
98
-
99
- delete global.Vue
100
- })
101
-
102
- describe('nuxtjs', () => {
103
- test('should not detect nuxtjs if vue is not detected', () => {
104
- global.$nuxt = { nuxt: {} }
105
-
106
- expect(getFrameworks()).toEqual([])
107
-
108
- delete global.$nuxt
109
- })
110
-
111
- test('should detect nuxtjs if global is set', () => {
112
- global.Vue = {}
113
- global.$nuxt = { nuxt: {} }
114
-
115
- expect(getFrameworks()).toEqual(['Vue', 'NuxtJS'])
116
-
117
- delete global.Vue
118
- delete global.$nuxt
119
- })
120
- })
121
- })
122
-
123
- describe('angular', () => {
124
- test('should detect angular from global ng property', () => {
125
- global.ng = {}
126
-
127
- expect(getFrameworks()).toEqual(['Angular'])
128
-
129
- delete global.ng
130
- })
131
-
132
- test('should detect angular from html [ng-version] property', () => {
133
- document.body.innerHTML = '<div ng-version=""></div>'
134
-
135
- expect(getFrameworks()).toEqual(['Angular'])
136
- })
137
-
138
- describe('angular universal', () => {
139
- test('should not detect angular universal if angular is not detected', () => {
140
- document.body.innerHTML = '<div ng-server-context=""></div>'
141
-
142
- expect(getFrameworks()).toEqual([])
143
- })
144
-
145
- test('should detect nuxtjs if global is set', () => {
146
- document.body.innerHTML = '<div ng-version="" ng-server-context=""></div>'
147
-
148
- expect(getFrameworks()).toEqual(['Angular', 'AngularUniversal'])
149
- })
150
- })
151
- })
152
-
153
- describe('svelte', () => {
154
- test('should detect svelte from global __svelte property', () => {
155
- global.__svelte = {}
156
-
157
- expect(getFrameworks()).toEqual(['Svelte'])
158
-
159
- delete global.__svelte
160
- })
161
-
162
- describe('sveltekit', () => {
163
- test('should not detect sveltekit if svelte is not detected', () => {
164
- global.__sveltekit_1234 = { }
165
-
166
- expect(getFrameworks()).toEqual([])
167
-
168
- delete global.__sveltekit_1234
169
- })
170
-
171
- test('should detect sveltekit if global is set', () => {
172
- global.__svelte = {}
173
- global.__sveltekit_4567 = {}
174
-
175
- expect(getFrameworks()).toEqual(['Svelte', 'SvelteKit'])
176
-
177
- delete global.__svelte
178
- delete global.__sveltekit_4567
179
- })
180
- })
181
- })
182
-
183
- describe('preact', () => {
184
- test('should detect preact from global preact property', () => {
185
- global.preact = {}
186
-
187
- expect(getFrameworks()).toEqual(['Preact'])
188
-
189
- delete global.preact
190
- })
191
-
192
- describe('preact ssr', () => {
193
- test('should not detect preact ssr if preact is not detected', () => {
194
- document.body.innerHTML = '<script type="__PREACT_CLI_DATA__"></div>'
195
-
196
- expect(getFrameworks()).toEqual([])
197
- })
198
-
199
- test('should detect sveltekit if global is set', () => {
200
- global.preact = {}
201
- document.body.innerHTML = '<script type="__PREACT_CLI_DATA__"></div>'
202
-
203
- expect(getFrameworks()).toEqual(['Preact', 'PreactSSR'])
204
-
205
- delete global.preact
206
- })
207
- })
208
- })
209
-
210
- describe('angularjs', () => {
211
- test('should detect angularjs from global angular property', () => {
212
- global.angular = {}
213
-
214
- expect(getFrameworks()).toEqual(['AngularJS'])
215
-
216
- delete global.angular
217
- })
218
-
219
- test('should detect angularjs from html .ng-binding property', () => {
220
- document.body.innerHTML = '<div class="ng-binding"></div>'
221
-
222
- expect(getFrameworks()).toEqual(['AngularJS'])
223
- })
224
-
225
- test('should detect angularjs from html [ng-app] property', () => {
226
- document.body.innerHTML = '<div ng-app=""></div>'
227
-
228
- expect(getFrameworks()).toEqual(['AngularJS'])
229
- })
230
-
231
- test('should detect angularjs from html [data-ng-app] property', () => {
232
- document.body.innerHTML = '<div data-ng-app=""></div>'
233
-
234
- expect(getFrameworks()).toEqual(['AngularJS'])
235
- })
236
-
237
- test('should detect angularjs from html [ng-controller] property', () => {
238
- document.body.innerHTML = '<div ng-controller=""></div>'
239
-
240
- expect(getFrameworks()).toEqual(['AngularJS'])
241
- })
242
-
243
- test('should detect angularjs from html [data-ng-controller] property', () => {
244
- document.body.innerHTML = '<div data-ng-controller=""></div>'
245
-
246
- expect(getFrameworks()).toEqual(['AngularJS'])
247
- })
248
-
249
- test('should detect angularjs from html [ng-repeat] property', () => {
250
- document.body.innerHTML = '<div ng-repeat=""></div>'
251
-
252
- expect(getFrameworks()).toEqual(['AngularJS'])
253
- })
254
-
255
- test('should detect angularjs from html [data-ng-repeat] property', () => {
256
- document.body.innerHTML = '<div data-ng-repeat=""></div>'
257
-
258
- expect(getFrameworks()).toEqual(['AngularJS'])
259
- })
260
-
261
- test('should detect angularjs from angular.js script element', () => {
262
- document.body.innerHTML = `<script src="${faker.internet.url()}/angular.js"></script>`
263
-
264
- expect(getFrameworks()).toEqual(['AngularJS'])
265
- })
266
-
267
- test('should detect angularjs from angular.min.js script element', () => {
268
- document.body.innerHTML = `<script src="${faker.internet.url()}/angular.min.js"></script>`
269
-
270
- expect(getFrameworks()).toEqual(['AngularJS'])
271
- })
272
- })
273
-
274
- test('should detect backbone from global Backbone property', () => {
275
- global.Backbone = {}
276
-
277
- expect(getFrameworks()).toEqual(['Backbone'])
278
-
279
- delete global.Backbone
280
- })
281
-
282
- test('should detect ember from global Ember property', () => {
283
- global.Ember = {}
284
-
285
- expect(getFrameworks()).toEqual(['Ember'])
286
-
287
- delete global.Ember
288
- })
289
-
290
- test('should detect meteor from global Meteor property', () => {
291
- global.Meteor = {}
292
-
293
- expect(getFrameworks()).toEqual(['Meteor'])
294
-
295
- delete global.Meteor
296
- })
297
-
298
- test('should detect zepto from global Zepto property', () => {
299
- global.Zepto = {}
300
-
301
- expect(getFrameworks()).toEqual(['Zepto'])
302
-
303
- delete global.Zepto
304
- })
305
-
306
- test('should detect jquery from global jQuery property', () => {
307
- global.jQuery = {}
308
-
309
- expect(getFrameworks()).toEqual(['Jquery'])
310
-
311
- delete global.jQuery
312
- })
313
-
314
- test('should detect mootools from global MooTools property', () => {
315
- global.MooTools = {}
316
-
317
- expect(getFrameworks()).toEqual(['MooTools'])
318
-
319
- delete global.MooTools
320
- })
321
-
322
- test('should detect electron from user agent', () => {
323
- const currentNavigator = global.navigator
324
- Object.defineProperty(global, 'navigator', {
325
- value: { userAgent: 'This is a test; Electron some version; foobar' },
326
- writable: true
327
- })
328
-
329
- expect(getFrameworks()).toEqual(['Electron'])
330
-
331
- global.navigator = currentNavigator
332
- })
@@ -1,86 +0,0 @@
1
- import { Aggregator } from '../../../common/aggregate/aggregator'
2
- import { ee } from '../../../common/event-emitter/contextual-ee'
3
- import { drain } from '../../../common/drain/drain'
4
- import { setRuntime } from '../../../common/config/config'
5
-
6
- jest.mock('web-vitals', () => ({
7
- __esModule: true,
8
- // eslint-disable-next-line
9
- onFID: jest.fn(cb => cb({
10
- value: 1234,
11
- entries: [{ name: 'pointerdown', startTime: 5 }]
12
- })),
13
- // eslint-disable-next-line
14
- onCLS: jest.fn((cb) => cb({
15
- value: 1,
16
- entries: [{ value: 1 }]
17
- })),
18
- // eslint-disable-next-line
19
- onFCP: jest.fn((cb) => cb({
20
- value: 1,
21
- entries: [{ value: 1 }]
22
- })),
23
- // eslint-disable-next-line
24
- onINP: jest.fn((cb) => cb({
25
- value: 1,
26
- entries: [{ value: 1 }]
27
- })),
28
- // eslint-disable-next-line
29
- onLCP: jest.fn((cb) => cb({
30
- value: 1,
31
- entries: [{ value: 1 }]
32
- }))
33
- })
34
- )
35
-
36
- let pvtAgg, cumulativeLayoutShift
37
- describe('pvt aggregate tests', () => {
38
- beforeEach(async () => {
39
- const { Aggregate } = await import('.')
40
- setRuntime('abcd', {})
41
- pvtAgg = new Aggregate('abcd', new Aggregator({ agentIdentifier: 'abcd', ee }))
42
- pvtAgg.scheduler.harvest.send = jest.fn()
43
- pvtAgg.prepareHarvest = jest.fn(() => ({}))
44
- drain('abcd', 'feature')
45
-
46
- global.navigator.connection = {
47
- type: 'cellular',
48
- effectiveType: '3g',
49
- rtt: 270,
50
- downlink: 700
51
- }
52
-
53
- const { cumulativeLayoutShift: cls } = await import('../../../common/vitals/cumulative-layout-shift')
54
- cumulativeLayoutShift = cls
55
- })
56
- test('LCP event with CLS attribute', () => {
57
- cumulativeLayoutShift.update({ value: 1 })
58
- pvtAgg.addTiming('lcp', 1, { size: 1, startTime: 1 })
59
-
60
- var timing = find(pvtAgg.timings, function (t) {
61
- return t.name === 'lcp'
62
- })
63
-
64
- expect(timing.attrs.cls).toEqual(1) // 'CLS value should be the one present at the time LCP happened'
65
-
66
- function find (arr, fn) {
67
- if (arr.find) {
68
- return arr.find(fn)
69
- }
70
- var match = null
71
- arr.forEach(function (t) {
72
- if (fn(t)) {
73
- match = t
74
- }
75
- })
76
- return match
77
- }
78
- })
79
-
80
- test('sends expected FI attributes when available', () => {
81
- expect(pvtAgg.timings.length).toBeGreaterThanOrEqual(1)
82
- const fiPayload = pvtAgg.timings.find(x => x.name === 'fi')
83
- expect(fiPayload.value).toEqual(5)
84
- expect(fiPayload.attrs).toEqual(expect.objectContaining({ type: 'pointerdown', fid: 1234, cls: 1 }))
85
- })
86
- })