@newrelic/browser-agent 1.232.0 → 1.233.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 (273) hide show
  1. package/dist/cjs/cdn/polyfills.js +5 -2
  2. package/dist/cjs/common/config/state/configurable.js +15 -26
  3. package/dist/cjs/common/config/state/info.js +1 -1
  4. package/dist/cjs/common/config/state/init.js +101 -56
  5. package/dist/cjs/common/config/state/loader-config.js +1 -1
  6. package/dist/cjs/common/config/state/runtime.js +1 -5
  7. package/dist/cjs/common/constants/env.cdn.js +1 -1
  8. package/dist/cjs/common/constants/env.npm.js +1 -1
  9. package/dist/cjs/common/drain/drain.js +1 -1
  10. package/dist/cjs/common/harvest/harvest-scheduler.js +30 -10
  11. package/dist/cjs/common/harvest/harvest.js +119 -55
  12. package/dist/cjs/common/session/session-entity.js +35 -22
  13. package/dist/cjs/common/session/session-entity.test.js +73 -49
  14. package/dist/cjs/common/timer/interaction-timer.js +9 -12
  15. package/dist/cjs/common/url/canonicalize-url.js +32 -0
  16. package/dist/cjs/common/url/canonicalize-url.test.js +42 -0
  17. package/dist/cjs/common/url/clean-url.js +10 -3
  18. package/dist/cjs/common/url/protocol.test.js +0 -1
  19. package/dist/cjs/common/util/feature-flags.js +2 -1
  20. package/dist/cjs/common/util/global-scope.js +4 -2
  21. package/dist/cjs/common/util/submit-data.js +57 -18
  22. package/dist/cjs/common/wrap/wrap-fetch.js +1 -3
  23. package/dist/cjs/common/wrap/wrap-function.js +1 -3
  24. package/dist/cjs/common/wrap/wrap-promise.js +1 -1
  25. package/dist/cjs/features/ajax/aggregate/index.js +2 -2
  26. package/dist/cjs/features/ajax/instrument/index.js +1 -1
  27. package/dist/cjs/features/jserrors/aggregate/canonical-function-name.js +12 -4
  28. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +93 -10
  29. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +164 -38
  30. package/dist/cjs/features/jserrors/aggregate/index.js +29 -48
  31. package/dist/cjs/features/jserrors/instrument/index.js +0 -2
  32. package/dist/cjs/features/metrics/aggregate/framework-detection.js +67 -0
  33. package/dist/cjs/features/metrics/aggregate/framework-detection.test.js +137 -0
  34. package/dist/cjs/features/metrics/aggregate/index.js +7 -3
  35. package/dist/cjs/features/metrics/aggregate/polyfill-detection.es5.js +14 -0
  36. package/dist/cjs/features/metrics/aggregate/polyfill-detection.es5.test.js +17 -0
  37. package/dist/cjs/features/metrics/aggregate/polyfill-detection.js +53 -0
  38. package/dist/cjs/features/metrics/aggregate/polyfill-detection.test.js +165 -0
  39. package/dist/cjs/features/page_action/aggregate/index.js +2 -2
  40. package/dist/cjs/features/page_view_event/aggregate/index.js +6 -3
  41. package/dist/cjs/features/page_view_timing/aggregate/index.js +2 -2
  42. package/dist/cjs/features/session_replay/aggregate/index.js +333 -0
  43. package/dist/cjs/features/session_replay/constants.js +9 -0
  44. package/dist/cjs/features/session_replay/index.js +12 -0
  45. package/dist/cjs/features/session_replay/instrument/index.js +29 -0
  46. package/dist/cjs/features/session_trace/aggregate/index.js +163 -164
  47. package/dist/cjs/features/session_trace/constants.js +2 -9
  48. package/dist/cjs/features/session_trace/instrument/index.js +24 -66
  49. package/dist/cjs/features/spa/aggregate/index.js +2 -2
  50. package/dist/cjs/features/utils/agent-session.js +1 -2
  51. package/dist/cjs/features/utils/aggregate-base.js +64 -0
  52. package/dist/cjs/features/utils/feature-base.js +0 -31
  53. package/dist/cjs/features/utils/handler-cache.js +3 -4
  54. package/dist/cjs/features/utils/instrument-base.js +42 -10
  55. package/dist/cjs/features/utils/{lazy-loader.js → lazy-feature-loader.js} +4 -2
  56. package/dist/cjs/loaders/agent.js +1 -1
  57. package/dist/cjs/loaders/api/apiAsync.js +3 -1
  58. package/dist/cjs/loaders/configure/configure.js +3 -3
  59. package/dist/cjs/loaders/features/featureDependencies.js +0 -12
  60. package/dist/cjs/loaders/features/features.js +3 -1
  61. package/dist/cjs/loaders/micro-agent.js +6 -6
  62. package/dist/esm/cdn/polyfills.js +5 -2
  63. package/dist/esm/common/config/state/configurable.js +14 -24
  64. package/dist/esm/common/config/state/info.js +2 -2
  65. package/dist/esm/common/config/state/init.js +102 -57
  66. package/dist/esm/common/config/state/loader-config.js +2 -2
  67. package/dist/esm/common/config/state/runtime.js +2 -4
  68. package/dist/esm/common/constants/env.cdn.js +1 -1
  69. package/dist/esm/common/constants/env.npm.js +1 -1
  70. package/dist/esm/common/drain/drain.js +1 -1
  71. package/dist/esm/common/harvest/harvest-scheduler.js +30 -10
  72. package/dist/esm/common/harvest/harvest.js +121 -56
  73. package/dist/esm/common/session/session-entity.js +35 -22
  74. package/dist/esm/common/session/session-entity.test.js +73 -49
  75. package/dist/esm/common/timer/interaction-timer.js +9 -12
  76. package/dist/esm/common/url/canonicalize-url.js +27 -0
  77. package/dist/esm/common/url/canonicalize-url.test.js +38 -0
  78. package/dist/esm/common/url/clean-url.js +10 -3
  79. package/dist/esm/common/url/protocol.test.js +0 -1
  80. package/dist/esm/common/util/feature-flags.js +2 -1
  81. package/dist/esm/common/util/global-scope.js +1 -0
  82. package/dist/esm/common/util/submit-data.js +57 -18
  83. package/dist/esm/common/wrap/wrap-fetch.js +1 -2
  84. package/dist/esm/common/wrap/wrap-function.js +1 -2
  85. package/dist/esm/common/wrap/wrap-promise.js +1 -1
  86. package/dist/esm/features/ajax/aggregate/index.js +2 -2
  87. package/dist/esm/features/ajax/instrument/index.js +1 -1
  88. package/dist/esm/features/jserrors/aggregate/canonical-function-name.js +12 -4
  89. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +93 -10
  90. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +149 -25
  91. package/dist/esm/features/jserrors/aggregate/index.js +30 -48
  92. package/dist/esm/features/jserrors/instrument/index.js +0 -1
  93. package/dist/esm/features/metrics/aggregate/framework-detection.js +61 -0
  94. package/dist/esm/features/metrics/aggregate/framework-detection.test.js +133 -0
  95. package/dist/esm/features/metrics/aggregate/index.js +7 -3
  96. package/dist/esm/features/metrics/aggregate/polyfill-detection.es5.js +8 -0
  97. package/dist/esm/features/metrics/aggregate/polyfill-detection.es5.test.js +15 -0
  98. package/dist/esm/features/metrics/aggregate/polyfill-detection.js +47 -0
  99. package/dist/esm/features/metrics/aggregate/polyfill-detection.test.js +163 -0
  100. package/dist/esm/features/page_action/aggregate/index.js +2 -2
  101. package/dist/esm/features/page_view_event/aggregate/index.js +6 -3
  102. package/dist/esm/features/page_view_timing/aggregate/index.js +2 -2
  103. package/dist/esm/features/session_replay/aggregate/index.js +327 -0
  104. package/dist/esm/features/session_replay/constants.js +2 -0
  105. package/dist/esm/features/session_replay/index.js +12 -0
  106. package/dist/esm/features/session_replay/instrument/index.js +21 -0
  107. package/dist/esm/features/session_trace/aggregate/index.js +163 -163
  108. package/dist/esm/features/session_trace/constants.js +1 -5
  109. package/dist/esm/features/session_trace/instrument/index.js +24 -66
  110. package/dist/esm/features/spa/aggregate/index.js +2 -2
  111. package/dist/esm/features/utils/agent-session.js +1 -2
  112. package/dist/esm/features/utils/aggregate-base.js +57 -0
  113. package/dist/esm/features/utils/feature-base.js +1 -32
  114. package/dist/esm/features/utils/handler-cache.js +3 -4
  115. package/dist/esm/features/utils/instrument-base.js +42 -10
  116. package/dist/esm/features/utils/{lazy-loader.js → lazy-feature-loader.js} +3 -1
  117. package/dist/esm/loaders/agent.js +1 -1
  118. package/dist/esm/loaders/api/apiAsync.js +3 -1
  119. package/dist/esm/loaders/configure/configure.js +3 -3
  120. package/dist/esm/loaders/features/featureDependencies.js +0 -11
  121. package/dist/esm/loaders/features/features.js +3 -1
  122. package/dist/esm/loaders/micro-agent.js +6 -6
  123. package/dist/types/common/config/state/configurable.d.ts +1 -3
  124. package/dist/types/common/config/state/configurable.d.ts.map +1 -1
  125. package/dist/types/common/config/state/init.d.ts.map +1 -1
  126. package/dist/types/common/config/state/runtime.d.ts.map +1 -1
  127. package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
  128. package/dist/types/common/harvest/harvest.d.ts +37 -34
  129. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  130. package/dist/types/common/session/session-entity.d.ts +6 -3
  131. package/dist/types/common/session/session-entity.d.ts.map +1 -1
  132. package/dist/types/common/timer/interaction-timer.d.ts +2 -1
  133. package/dist/types/common/timer/interaction-timer.d.ts.map +1 -1
  134. package/dist/types/common/url/canonicalize-url.d.ts +9 -0
  135. package/dist/types/common/url/canonicalize-url.d.ts.map +1 -0
  136. package/dist/types/common/url/clean-url.d.ts +7 -1
  137. package/dist/types/common/url/clean-url.d.ts.map +1 -1
  138. package/dist/types/common/util/feature-flags.d.ts.map +1 -1
  139. package/dist/types/common/util/global-scope.d.ts +1 -0
  140. package/dist/types/common/util/global-scope.d.ts.map +1 -1
  141. package/dist/types/common/util/submit-data.d.ts +40 -14
  142. package/dist/types/common/util/submit-data.d.ts.map +1 -1
  143. package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
  144. package/dist/types/common/wrap/wrap-function.d.ts.map +1 -1
  145. package/dist/types/features/ajax/aggregate/index.d.ts +2 -2
  146. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  147. package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts +8 -1
  148. package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts.map +1 -1
  149. package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts +48 -19
  150. package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts.map +1 -1
  151. package/dist/types/features/jserrors/aggregate/index.d.ts +14 -5
  152. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  153. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  154. package/dist/types/features/metrics/aggregate/framework-detection.d.ts.map +1 -0
  155. package/dist/types/features/metrics/aggregate/index.d.ts +2 -2
  156. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  157. package/dist/types/features/metrics/aggregate/polyfill-detection.d.ts +6 -0
  158. package/dist/types/features/metrics/aggregate/polyfill-detection.d.ts.map +1 -0
  159. package/dist/types/features/metrics/aggregate/polyfill-detection.es5.d.ts +7 -0
  160. package/dist/types/features/metrics/aggregate/polyfill-detection.es5.d.ts.map +1 -0
  161. package/dist/types/features/page_action/aggregate/index.d.ts +3 -3
  162. package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -1
  163. package/dist/types/features/page_view_event/aggregate/index.d.ts +2 -2
  164. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  165. package/dist/types/features/page_view_timing/aggregate/index.d.ts +2 -2
  166. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  167. package/dist/types/features/session_replay/aggregate/index.d.ts +96 -0
  168. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -0
  169. package/dist/types/features/session_replay/constants.d.ts +2 -0
  170. package/dist/types/features/session_replay/constants.d.ts.map +1 -0
  171. package/dist/types/features/session_replay/index.d.ts +2 -0
  172. package/dist/types/features/session_replay/index.d.ts.map +1 -0
  173. package/dist/types/features/session_replay/instrument/index.d.ts +6 -0
  174. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -0
  175. package/dist/types/features/session_trace/aggregate/index.d.ts +8 -57
  176. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  177. package/dist/types/features/session_trace/constants.d.ts +0 -3
  178. package/dist/types/features/session_trace/constants.d.ts.map +1 -1
  179. package/dist/types/features/session_trace/instrument/index.d.ts +1 -3
  180. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  181. package/dist/types/features/spa/aggregate/index.d.ts +2 -2
  182. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  183. package/dist/types/features/utils/agent-session.d.ts.map +1 -1
  184. package/dist/types/features/utils/aggregate-base.d.ts +11 -0
  185. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -0
  186. package/dist/types/features/utils/feature-base.d.ts +0 -5
  187. package/dist/types/features/utils/feature-base.d.ts.map +1 -1
  188. package/dist/types/features/utils/handler-cache.d.ts.map +1 -1
  189. package/dist/types/features/utils/instrument-base.d.ts +3 -1
  190. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  191. package/dist/types/features/utils/{lazy-loader.d.ts → lazy-feature-loader.d.ts} +2 -2
  192. package/dist/types/features/utils/lazy-feature-loader.d.ts.map +1 -0
  193. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  194. package/dist/types/loaders/features/featureDependencies.d.ts +0 -1
  195. package/dist/types/loaders/features/featureDependencies.d.ts.map +1 -1
  196. package/dist/types/loaders/features/features.d.ts +1 -0
  197. package/dist/types/loaders/features/features.d.ts.map +1 -1
  198. package/package.json +31 -22
  199. package/src/cdn/polyfills.js +4 -1
  200. package/src/common/config/state/configurable.js +18 -24
  201. package/src/common/config/state/info.js +2 -2
  202. package/src/common/config/state/init.js +62 -28
  203. package/src/common/config/state/loader-config.js +2 -2
  204. package/src/common/config/state/runtime.js +2 -4
  205. package/src/common/drain/drain.js +1 -1
  206. package/src/common/harvest/harvest-scheduler.js +35 -10
  207. package/src/common/harvest/harvest.js +73 -50
  208. package/src/common/session/session-entity.js +34 -23
  209. package/src/common/session/session-entity.test.js +57 -51
  210. package/src/common/timer/interaction-timer.js +9 -12
  211. package/src/common/url/canonicalize-url.js +28 -0
  212. package/src/common/url/canonicalize-url.test.js +34 -0
  213. package/src/common/url/clean-url.js +10 -3
  214. package/src/common/url/protocol.test.js +0 -1
  215. package/src/common/util/feature-flags.js +2 -2
  216. package/src/common/util/global-scope.js +2 -0
  217. package/src/common/util/submit-data.js +28 -17
  218. package/src/common/wrap/wrap-fetch.js +1 -2
  219. package/src/common/wrap/wrap-function.js +1 -2
  220. package/src/common/wrap/wrap-promise.js +1 -1
  221. package/src/features/ajax/aggregate/index.js +2 -2
  222. package/src/features/ajax/instrument/index.js +1 -1
  223. package/src/features/jserrors/aggregate/canonical-function-name.js +12 -4
  224. package/src/features/jserrors/aggregate/compute-stack-trace.js +85 -11
  225. package/src/features/jserrors/aggregate/compute-stack-trace.test.js +141 -24
  226. package/src/features/jserrors/aggregate/index.js +28 -52
  227. package/src/features/jserrors/instrument/index.js +0 -1
  228. package/src/features/metrics/aggregate/framework-detection.js +73 -0
  229. package/src/features/metrics/aggregate/framework-detection.test.js +201 -0
  230. package/src/features/metrics/aggregate/index.js +8 -3
  231. package/src/features/metrics/aggregate/polyfill-detection.es5.js +9 -0
  232. package/src/features/metrics/aggregate/polyfill-detection.es5.test.js +16 -0
  233. package/src/features/metrics/aggregate/polyfill-detection.js +48 -0
  234. package/src/features/metrics/aggregate/polyfill-detection.test.js +163 -0
  235. package/src/features/page_action/aggregate/index.js +2 -2
  236. package/src/features/page_view_event/aggregate/index.js +5 -5
  237. package/src/features/page_view_timing/aggregate/index.js +2 -2
  238. package/src/features/session_replay/aggregate/index.js +314 -0
  239. package/src/features/session_replay/constants.js +3 -0
  240. package/src/features/session_replay/index.js +12 -0
  241. package/src/features/session_replay/instrument/index.js +22 -0
  242. package/src/features/session_trace/aggregate/index.js +148 -188
  243. package/src/features/session_trace/constants.js +0 -4
  244. package/src/features/session_trace/instrument/index.js +17 -69
  245. package/src/features/spa/aggregate/index.js +2 -2
  246. package/src/features/utils/agent-session.js +1 -2
  247. package/src/features/utils/aggregate-base.js +51 -0
  248. package/src/features/utils/feature-base.js +1 -31
  249. package/src/features/utils/handler-cache.js +3 -4
  250. package/src/features/utils/instrument-base.js +40 -8
  251. package/src/features/utils/{lazy-loader.js → lazy-feature-loader.js} +3 -1
  252. package/src/loaders/agent.js +1 -1
  253. package/src/loaders/api/apiAsync.js +1 -1
  254. package/src/loaders/configure/configure.js +4 -3
  255. package/src/loaders/features/featureDependencies.js +0 -12
  256. package/src/loaders/features/features.js +3 -1
  257. package/src/loaders/micro-agent.js +4 -4
  258. package/dist/cjs/common/metrics/framework-detection.js +0 -72
  259. package/dist/cjs/common/util/user-agent.js +0 -57
  260. package/dist/cjs/common/window/supports-performance-observer.js +0 -15
  261. package/dist/esm/common/metrics/framework-detection.js +0 -66
  262. package/dist/esm/common/util/user-agent.js +0 -48
  263. package/dist/esm/common/window/supports-performance-observer.js +0 -9
  264. package/dist/types/common/metrics/framework-detection.d.ts.map +0 -1
  265. package/dist/types/common/util/user-agent.d.ts +0 -5
  266. package/dist/types/common/util/user-agent.d.ts.map +0 -1
  267. package/dist/types/common/window/supports-performance-observer.d.ts +0 -2
  268. package/dist/types/common/window/supports-performance-observer.d.ts.map +0 -1
  269. package/dist/types/features/utils/lazy-loader.d.ts.map +0 -1
  270. package/src/common/metrics/framework-detection.js +0 -71
  271. package/src/common/util/user-agent.js +0 -56
  272. package/src/common/window/supports-performance-observer.js +0 -10
  273. /package/dist/types/{common/metrics → features/metrics/aggregate}/framework-detection.d.ts +0 -0
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+
3
+ var _faker = require("@faker-js/faker");
4
+ var _frameworkDetection = require("./framework-detection");
5
+ 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); }
6
+ 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; }
7
+ jest.mock('../../../common/util/global-scope', () => ({
8
+ isBrowserScope: true
9
+ }));
10
+ afterEach(() => {
11
+ document.body.innerHTML = '';
12
+ });
13
+ test('framework detection should not happen in non-browser scope', async () => {
14
+ global.React = {};
15
+ jest.resetModules();
16
+ jest.doMock('../../../common/util/global-scope', () => ({
17
+ isBrowserScope: false
18
+ }));
19
+ const frameworkDetector = await Promise.resolve().then(() => _interopRequireWildcard(require('./framework-detection')));
20
+ expect(frameworkDetector.getFrameworks()).toEqual([]);
21
+ delete global.React;
22
+ });
23
+ test('should detect react from global React property', () => {
24
+ global.React = {};
25
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['React']);
26
+ delete global.React;
27
+ });
28
+ test('should detect react from global ReactDOM property', () => {
29
+ global.ReactDOM = {};
30
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['React']);
31
+ delete global.ReactDOM;
32
+ });
33
+ test('should detect react from global ReactRedux property', () => {
34
+ global.ReactRedux = {};
35
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['React']);
36
+ delete global.ReactRedux;
37
+ });
38
+ test('should detect react from html [data-reactroot] property', () => {
39
+ document.body.innerHTML = '<div data-reactroot=""></div>';
40
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['React']);
41
+ });
42
+ test('should detect react from html [data-reactid] property', () => {
43
+ document.body.innerHTML = '<div data-reactid=""></div>';
44
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['React']);
45
+ });
46
+ test('should detect react from element _reactRootContainer property', () => {
47
+ const element = document.createElement('div');
48
+ element._reactRootContainer = {};
49
+ document.body.innerHTML = '<html><body></body></html>';
50
+ document.body.appendChild(element);
51
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['React']);
52
+ });
53
+ test('should detect angularjs from global angular property', () => {
54
+ global.angular = {};
55
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
56
+ delete global.angular;
57
+ });
58
+ test('should detect angularjs from html .ng-binding property', () => {
59
+ document.body.innerHTML = '<div class="ng-binding"></div>';
60
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
61
+ });
62
+ test('should detect angularjs from html [ng-app] property', () => {
63
+ document.body.innerHTML = '<div ng-app=""></div>';
64
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
65
+ });
66
+ test('should detect angularjs from html [data-ng-app] property', () => {
67
+ document.body.innerHTML = '<div data-ng-app=""></div>';
68
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
69
+ });
70
+ test('should detect angularjs from html [ng-controller] property', () => {
71
+ document.body.innerHTML = '<div ng-controller=""></div>';
72
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
73
+ });
74
+ test('should detect angularjs from html [data-ng-controller] property', () => {
75
+ document.body.innerHTML = '<div data-ng-controller=""></div>';
76
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
77
+ });
78
+ test('should detect angularjs from html [ng-repeat] property', () => {
79
+ document.body.innerHTML = '<div ng-repeat=""></div>';
80
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
81
+ });
82
+ test('should detect angularjs from html [data-ng-repeat] property', () => {
83
+ document.body.innerHTML = '<div data-ng-repeat=""></div>';
84
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
85
+ });
86
+ test('should detect angularjs from angular.js script element', () => {
87
+ document.body.innerHTML = "<script src=\"".concat(_faker.faker.internet.url(), "/angular.js\"></script>");
88
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
89
+ });
90
+ test('should detect angularjs from angular.min.js script element', () => {
91
+ document.body.innerHTML = "<script src=\"".concat(_faker.faker.internet.url(), "/angular.min.js\"></script>");
92
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
93
+ });
94
+ test('should detect angular from global ng property', () => {
95
+ global.ng = {};
96
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Angular']);
97
+ delete global.ng;
98
+ });
99
+ test('should detect angular from html [ng-version] property', () => {
100
+ document.body.innerHTML = '<div ng-version=""></div>';
101
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Angular']);
102
+ });
103
+ test('should detect backbone from global Backbone property', () => {
104
+ global.Backbone = {};
105
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Backbone']);
106
+ delete global.Backbone;
107
+ });
108
+ test('should detect ember from global Ember property', () => {
109
+ global.Ember = {};
110
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Ember']);
111
+ delete global.Ember;
112
+ });
113
+ test('should detect vue from global Vue property', () => {
114
+ global.Vue = {};
115
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Vue']);
116
+ delete global.Vue;
117
+ });
118
+ test('should detect meteor from global Meteor property', () => {
119
+ global.Meteor = {};
120
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Meteor']);
121
+ delete global.Meteor;
122
+ });
123
+ test('should detect zepto from global Zepto property', () => {
124
+ global.Zepto = {};
125
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Zepto']);
126
+ delete global.Zepto;
127
+ });
128
+ test('should detect jquery from global jQuery property', () => {
129
+ global.jQuery = {};
130
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Jquery']);
131
+ delete global.jQuery;
132
+ });
133
+ test('should detect mootools from global MooTools property', () => {
134
+ global.MooTools = {};
135
+ expect((0, _frameworkDetection.getFrameworks)()).toEqual(['MooTools']);
136
+ delete global.MooTools;
137
+ });
@@ -9,16 +9,17 @@ var _registerHandler = require("../../../common/event-emitter/register-handler")
9
9
  var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
10
10
  var _constants = require("../constants");
11
11
  var _drain = require("../../../common/drain/drain");
12
- var _frameworkDetection = require("../../../common/metrics/framework-detection");
12
+ var _frameworkDetection = require("./framework-detection");
13
+ var _polyfillDetection = require("./polyfill-detection");
13
14
  var _protocol = require("../../../common/url/protocol");
14
15
  var _obfuscate = require("../../../common/util/obfuscate");
15
16
  var _env = require("../../../common/constants/env.npm");
16
17
  var _load = require("../../../common/window/load");
17
18
  var _eventListenerOpts = require("../../../common/event-listener/event-listener-opts");
18
19
  var _globalScope = require("../../../common/util/global-scope");
19
- var _featureBase = require("../../utils/feature-base");
20
+ var _aggregateBase = require("../../utils/aggregate-base");
20
21
  var _stringify = require("../../../common/util/stringify");
21
- class Aggregate extends _featureBase.FeatureBase {
22
+ class Aggregate extends _aggregateBase.AggregateBase {
22
23
  static featureName = _constants.FEATURE_NAME;
23
24
  constructor(agentIdentifier, aggregator) {
24
25
  super(agentIdentifier, aggregator, _constants.FEATURE_NAME);
@@ -82,6 +83,9 @@ class Aggregate extends _featureBase.FeatureBase {
82
83
  });
83
84
  });
84
85
  }
86
+ (0, _polyfillDetection.getPolyfills)().forEach(polyfill => {
87
+ this.storeSupportabilityMetrics('Polyfill/' + polyfill + '/Detected');
88
+ });
85
89
 
86
90
  // file protocol detection
87
91
  if ((0, _protocol.isFileProtocol)()) {
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getPolyfills = getPolyfills;
7
+ /**
8
+ * This file is used as a replacement for the polyfill-detection.es5.js
9
+ * file when running the polyfills webpack build.
10
+ * @returns {string[]} an empty array
11
+ */
12
+ function getPolyfills() {
13
+ return [];
14
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ var _polyfillDetection = require("./polyfill-detection.es5");
4
+ afterEach(() => {
5
+ jest.resetAllMocks();
6
+ });
7
+ test('should always return an empty array', () => {
8
+ const originalFn = Array.from;
9
+ Array.from = jest.fn(function () {
10
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
11
+ args[_key] = arguments[_key];
12
+ }
13
+ return originalFn.apply(this, args);
14
+ });
15
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual([]);
16
+ Array.from = originalFn;
17
+ });
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getPolyfills = getPolyfills;
7
+ const detectionRegex = /\{ \[native code\] \}/;
8
+ const POLYFILLS = {
9
+ FUNCTION_BIND: 'Function.bind',
10
+ FUNCTION_APPLY: 'Function.apply',
11
+ FUNCTION_CALL: 'Function.call',
12
+ ARRAY_INCLUDES: 'Array.includes',
13
+ ARRAY_FROM: 'Array.from',
14
+ ARRAY_FIND: 'Array.find',
15
+ ARRAY_FLAT: 'Array.flat',
16
+ ARRAY_FLATMAP: 'Array.flatMap',
17
+ OBJECT_ASSIGN: 'Object.assign',
18
+ OBJECT_ENTRIES: 'Object.entries',
19
+ OBJECT_VALUES: 'Object.values',
20
+ MAP: 'Map',
21
+ SET: 'Set',
22
+ WEAK_MAP: 'WeakMap',
23
+ WEAK_SET: 'WeakSet'
24
+ };
25
+
26
+ /**
27
+ * Checks for native globals to see if they have been polyfilled by customer code.
28
+ * @returns {string[]} Array of methods that were detected to have been polyfilled
29
+ */
30
+ function getPolyfills() {
31
+ const polyfills = [];
32
+ const mockFunction = function () {/* noop */};
33
+ try {
34
+ if (typeof mockFunction.bind === 'function' && !detectionRegex.test(mockFunction.bind.toString())) polyfills.push(POLYFILLS.FUNCTION_BIND);
35
+ if (typeof mockFunction.apply === 'function' && !detectionRegex.test(mockFunction.apply.toString())) polyfills.push(POLYFILLS.FUNCTION_APPLY);
36
+ if (typeof mockFunction.call === 'function' && !detectionRegex.test(mockFunction.call.toString())) polyfills.push(POLYFILLS.FUNCTION_CALL);
37
+ if (typeof [].includes === 'function' && !detectionRegex.test([].includes.toString())) polyfills.push(POLYFILLS.ARRAY_INCLUDES);
38
+ if (typeof Array.from === 'function' && !detectionRegex.test(Array.from.toString())) polyfills.push(POLYFILLS.ARRAY_FROM);
39
+ if (typeof [].find === 'function' && !detectionRegex.test([].find.toString())) polyfills.push(POLYFILLS.ARRAY_FIND);
40
+ if (typeof [].flat === 'function' && !detectionRegex.test([].flat.toString())) polyfills.push(POLYFILLS.ARRAY_FLAT);
41
+ if (typeof [].flatMap === 'function' && !detectionRegex.test([].flatMap.toString())) polyfills.push(POLYFILLS.ARRAY_FLATMAP);
42
+ if (typeof Object.assign === 'function' && !detectionRegex.test(Object.assign.toString())) polyfills.push(POLYFILLS.OBJECT_ASSIGN);
43
+ if (typeof Object.entries === 'function' && !detectionRegex.test(Object.entries.toString())) polyfills.push(POLYFILLS.OBJECT_ENTRIES);
44
+ if (typeof Object.values === 'function' && !detectionRegex.test(Object.values.toString())) polyfills.push(POLYFILLS.OBJECT_VALUES);
45
+ if (typeof Map === 'function' && !detectionRegex.test(Map.toString())) polyfills.push(POLYFILLS.MAP);
46
+ if (typeof Set === 'function' && !detectionRegex.test(Set.toString())) polyfills.push(POLYFILLS.SET);
47
+ if (typeof WeakMap === 'function' && !detectionRegex.test(WeakMap.toString())) polyfills.push(POLYFILLS.WEAK_MAP);
48
+ if (typeof WeakSet === 'function' && !detectionRegex.test(WeakSet.toString())) polyfills.push(POLYFILLS.WEAK_SET);
49
+ } catch (err) {
50
+ // Possibly not supported
51
+ }
52
+ return polyfills;
53
+ }
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+
3
+ var _polyfillDetection = require("./polyfill-detection");
4
+ /* eslint-disable no-global-assign */
5
+ /* eslint-disable no-extend-native */
6
+
7
+ // DO NOT test Function.prototype.apply, it causes recursion in Jest
8
+
9
+ test('should return an empty array when nothing is polyfilled', () => {
10
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual([]);
11
+ });
12
+ test('should indicate Function.prototype.bind is polyfilled', () => {
13
+ const originalFn = Function.prototype.bind;
14
+ Function.prototype.bind = jest.fn(function () {
15
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
16
+ args[_key] = arguments[_key];
17
+ }
18
+ return originalFn.apply(this, args);
19
+ });
20
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Function.bind']);
21
+ Function.prototype.bind = originalFn;
22
+ });
23
+ test('should indicate Function.prototype.call is polyfilled', () => {
24
+ const originalFn = Function.prototype.call;
25
+ Function.prototype.call = jest.fn(function () {
26
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
27
+ args[_key2] = arguments[_key2];
28
+ }
29
+ return originalFn.apply(this, args);
30
+ });
31
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Function.call']);
32
+ Function.prototype.call = originalFn;
33
+ });
34
+ test('should indicate Array.prototype.includes is polyfilled', () => {
35
+ const originalFn = Array.prototype.includes;
36
+ Array.prototype.includes = jest.fn(function () {
37
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
38
+ args[_key3] = arguments[_key3];
39
+ }
40
+ return originalFn.apply(this, args);
41
+ });
42
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Array.includes']);
43
+ Array.prototype.includes = originalFn;
44
+ });
45
+ test('should indicate Array.from is polyfilled', () => {
46
+ const originalFn = Array.from;
47
+ Array.from = jest.fn(function () {
48
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
49
+ args[_key4] = arguments[_key4];
50
+ }
51
+ return originalFn.apply(this, args);
52
+ });
53
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Array.from']);
54
+ Array.from = originalFn;
55
+ });
56
+ test('should indicate Array.prototype.find is polyfilled', () => {
57
+ const originalFn = Array.prototype.find;
58
+ Array.prototype.find = jest.fn(function () {
59
+ for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
60
+ args[_key5] = arguments[_key5];
61
+ }
62
+ return originalFn.apply(this, args);
63
+ });
64
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Array.find']);
65
+ Array.prototype.find = originalFn;
66
+ });
67
+ test('should indicate Array.prototype.flat is polyfilled', () => {
68
+ const originalFn = Array.prototype.flat;
69
+ Array.prototype.flat = jest.fn(function () {
70
+ for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
71
+ args[_key6] = arguments[_key6];
72
+ }
73
+ return originalFn.apply(this, args);
74
+ });
75
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Array.flat']);
76
+ Array.prototype.flat = originalFn;
77
+ });
78
+ test('should indicate Array.prototype.flatMap is polyfilled', () => {
79
+ const originalFn = Array.prototype.flatMap;
80
+ Array.prototype.flatMap = jest.fn(function () {
81
+ for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
82
+ args[_key7] = arguments[_key7];
83
+ }
84
+ return originalFn.apply(this, args);
85
+ });
86
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Array.flatMap']);
87
+ Array.prototype.flatMap = originalFn;
88
+ });
89
+ test('should indicate Object.assign is polyfilled', () => {
90
+ const originalFn = Object.assign;
91
+ Object.assign = jest.fn(function () {
92
+ for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
93
+ args[_key8] = arguments[_key8];
94
+ }
95
+ return originalFn.apply(this, args);
96
+ });
97
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Object.assign']);
98
+ Object.assign = originalFn;
99
+ });
100
+ test('should indicate Object.entries is polyfilled', () => {
101
+ const originalFn = Object.entries;
102
+ Object.entries = jest.fn(function () {
103
+ for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
104
+ args[_key9] = arguments[_key9];
105
+ }
106
+ return originalFn.apply(this, args);
107
+ });
108
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Object.entries']);
109
+ Object.entries = originalFn;
110
+ });
111
+ test('should indicate Object.values is polyfilled', () => {
112
+ const originalFn = Object.values;
113
+ Object.values = jest.fn(function () {
114
+ for (var _len10 = arguments.length, args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
115
+ args[_key10] = arguments[_key10];
116
+ }
117
+ return originalFn.apply(this, args);
118
+ });
119
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Object.values']);
120
+ Object.values = originalFn;
121
+ });
122
+ test('should indicate Map constructor is polyfilled', () => {
123
+ const originalFn = Map;
124
+ Map = jest.fn(function () {
125
+ for (var _len11 = arguments.length, args = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
126
+ args[_key11] = arguments[_key11];
127
+ }
128
+ return originalFn.apply(this, args);
129
+ });
130
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Map']);
131
+ Map = originalFn;
132
+ });
133
+ test('should indicate Set constructor is polyfilled', () => {
134
+ const originalFn = Set;
135
+ Set = jest.fn(function () {
136
+ for (var _len12 = arguments.length, args = new Array(_len12), _key12 = 0; _key12 < _len12; _key12++) {
137
+ args[_key12] = arguments[_key12];
138
+ }
139
+ return originalFn.apply(this, args);
140
+ });
141
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Set']);
142
+ Set = originalFn;
143
+ });
144
+ test('should indicate WeakMap constructor is polyfilled', () => {
145
+ const originalFn = WeakMap;
146
+ WeakMap = jest.fn(function () {
147
+ for (var _len13 = arguments.length, args = new Array(_len13), _key13 = 0; _key13 < _len13; _key13++) {
148
+ args[_key13] = arguments[_key13];
149
+ }
150
+ return originalFn.apply(this, args);
151
+ });
152
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual(['WeakMap']);
153
+ WeakMap = originalFn;
154
+ });
155
+ test('should indicate WeakSet constructor is polyfilled', () => {
156
+ const originalFn = WeakSet;
157
+ WeakSet = jest.fn(function () {
158
+ for (var _len14 = arguments.length, args = new Array(_len14), _key14 = 0; _key14 < _len14; _key14++) {
159
+ args[_key14] = arguments[_key14];
160
+ }
161
+ return originalFn.apply(this, args);
162
+ });
163
+ expect((0, _polyfillDetection.getPolyfills)()).toEqual(['WeakSet']);
164
+ WeakSet = originalFn;
165
+ });
@@ -13,13 +13,13 @@ var _config = require("../../../common/config/config");
13
13
  var _constants = require("../constants");
14
14
  var _drain = require("../../../common/drain/drain");
15
15
  var _globalScope = require("../../../common/util/global-scope");
16
- var _featureBase = require("../../utils/feature-base");
16
+ var _aggregateBase = require("../../utils/aggregate-base");
17
17
  /*
18
18
  * Copyright 2020 New Relic Corporation. All rights reserved.
19
19
  * SPDX-License-Identifier: Apache-2.0
20
20
  */
21
21
 
22
- class Aggregate extends _featureBase.FeatureBase {
22
+ class Aggregate extends _aggregateBase.AggregateBase {
23
23
  static featureName = _constants.FEATURE_NAME;
24
24
  constructor(agentIdentifier, aggregator) {
25
25
  var _this;
@@ -20,11 +20,11 @@ var CONSTANTS = _interopRequireWildcard(require("../constants"));
20
20
  var _initializedFeatures = require("./initialized-features");
21
21
  var _globalScope = require("../../../common/util/global-scope");
22
22
  var _drain = require("../../../common/drain/drain");
23
- var _featureBase = require("../../utils/feature-base");
23
+ var _aggregateBase = require("../../utils/aggregate-base");
24
24
  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
25
  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
26
  const jsonp = 'NREUM.setToken';
27
- class Aggregate extends _featureBase.FeatureBase {
27
+ class Aggregate extends _aggregateBase.AggregateBase {
28
28
  static featureName = CONSTANTS.FEATURE_NAME;
29
29
  constructor(agentIdentifier, aggregator) {
30
30
  super(agentIdentifier, aggregator, CONSTANTS.FEATURE_NAME);
@@ -142,7 +142,10 @@ class Aggregate extends _featureBase.FeatureBase {
142
142
 
143
143
  // Capture query bytes sent to RUM call endpoint (currently `1`) as a supportability metric. See metrics aggregator (on unload).
144
144
  agentRuntime.queryBytesSent[protocol] = (agentRuntime.queryBytesSent[protocol] || 0) + queryString?.length || 0;
145
- const isValidJsonp = _submitData.submitData.jsonp(this.getScheme() + '://' + info.beacon + '/' + protocol + '/' + info.licenseKey + queryString, jsonp);
145
+ const isValidJsonp = _submitData.submitData.jsonp({
146
+ url: this.getScheme() + '://' + info.beacon + '/' + protocol + '/' + info.licenseKey + '?' + queryString,
147
+ jsonp
148
+ });
146
149
  // Usually `drain` is invoked automatically after processing feature flags contained in the JSONP callback from
147
150
  // ingest (see `activateFeatures`), so when JSONP cannot execute (as with module workers), we drain manually.
148
151
  if (!isValidJsonp) (0, _drain.drain)(this.agentIdentifier, CONSTANTS.FEATURE_NAME);
@@ -18,13 +18,13 @@ var _config = require("../../../common/config/config");
18
18
  var _constants = require("../constants");
19
19
  var _drain = require("../../../common/drain/drain");
20
20
  var _features = require("../../../loaders/features/features");
21
- var _featureBase = require("../../utils/feature-base");
21
+ var _aggregateBase = require("../../utils/aggregate-base");
22
22
  /*
23
23
  * Copyright 2020 New Relic Corporation. All rights reserved.
24
24
  * SPDX-License-Identifier: Apache-2.0
25
25
  */
26
26
 
27
- class Aggregate extends _featureBase.FeatureBase {
27
+ class Aggregate extends _aggregateBase.AggregateBase {
28
28
  static featureName = _constants.FEATURE_NAME;
29
29
  constructor(agentIdentifier, aggregator) {
30
30
  var _this;