@newrelic/browser-agent 0.1.230 → 1.232.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 (365) hide show
  1. package/README.md +27 -3
  2. package/dist/cjs/common/browser-version/ios-version.js +4 -3
  3. package/dist/cjs/common/config/state/configurable.js +27 -21
  4. package/dist/cjs/common/config/state/info.js +1 -1
  5. package/dist/cjs/common/config/state/init.js +9 -1
  6. package/dist/cjs/common/config/state/loader-config.js +1 -1
  7. package/dist/cjs/common/config/state/runtime.js +26 -28
  8. package/dist/cjs/common/constants/env.cdn.js +29 -0
  9. package/dist/cjs/common/constants/env.js +32 -0
  10. package/dist/cjs/common/constants/env.npm.js +30 -0
  11. package/dist/cjs/common/context/shared-context.js +2 -1
  12. package/dist/cjs/common/event-emitter/contextual-ee.test.js +282 -0
  13. package/dist/cjs/common/event-emitter/handle.test.js +58 -0
  14. package/dist/cjs/common/event-emitter/register-handler.test.js +55 -0
  15. package/dist/cjs/common/event-listener/event-listener-opts.js +4 -2
  16. package/dist/cjs/common/harvest/harvest-scheduler.js +14 -11
  17. package/dist/cjs/common/harvest/harvest.js +5 -3
  18. package/dist/cjs/common/ids/id.js +14 -6
  19. package/dist/cjs/common/ids/id.test.js +85 -0
  20. package/dist/cjs/common/ids/unique-id.js +75 -51
  21. package/dist/cjs/common/ids/unique-id.test.js +49 -0
  22. package/dist/cjs/common/session/constants.js +12 -0
  23. package/dist/cjs/common/session/session-entity.js +278 -0
  24. package/dist/cjs/common/session/session-entity.test.js +436 -0
  25. package/dist/cjs/common/storage/first-party-cookies.js +35 -0
  26. package/dist/cjs/common/storage/local-memory.js +35 -0
  27. package/dist/cjs/common/storage/local-memory.test.js +20 -0
  28. package/dist/cjs/common/storage/local-storage.js +33 -0
  29. package/dist/cjs/common/storage/local-storage.test.js +14 -0
  30. package/dist/cjs/common/timer/interaction-timer.js +78 -0
  31. package/dist/cjs/common/timer/interaction-timer.test.js +216 -0
  32. package/dist/cjs/common/timer/timer.js +32 -0
  33. package/dist/cjs/common/timer/timer.test.js +105 -0
  34. package/dist/cjs/common/timing/nav-timing.js +51 -30
  35. package/dist/cjs/common/timing/nav-timing.test.js +192 -0
  36. package/dist/cjs/common/unload/eol.js +2 -2
  37. package/dist/cjs/common/url/clean-url.test.js +9 -0
  38. package/dist/cjs/common/url/encode.test.js +74 -0
  39. package/dist/cjs/common/url/location.js +4 -0
  40. package/dist/cjs/common/url/location.test.js +13 -0
  41. package/dist/cjs/common/url/parse-url.test.js +111 -0
  42. package/dist/cjs/common/url/protocol.js +2 -12
  43. package/dist/cjs/common/url/protocol.test.js +16 -0
  44. package/dist/cjs/common/util/console.js +1 -1
  45. package/dist/cjs/common/util/data-size.js +6 -0
  46. package/dist/cjs/common/util/data-size.test.js +47 -0
  47. package/dist/cjs/common/util/invoke.js +73 -0
  48. package/dist/cjs/common/util/invoke.test.js +49 -0
  49. package/dist/cjs/common/util/map-own.test.js +3 -3
  50. package/dist/cjs/common/util/obfuscate.js +1 -5
  51. package/dist/cjs/common/window/page-visibility.js +5 -2
  52. package/dist/cjs/common/wrap/index.js +0 -7
  53. package/dist/cjs/common/wrap/wrap-events.js +6 -9
  54. package/dist/cjs/common/wrap/wrap-fetch.js +6 -6
  55. package/dist/cjs/common/wrap/wrap-history.js +7 -6
  56. package/dist/cjs/common/wrap/wrap-jsonp.js +7 -6
  57. package/dist/cjs/common/wrap/wrap-mutation.js +7 -6
  58. package/dist/cjs/common/wrap/wrap-promise.js +7 -6
  59. package/dist/cjs/common/wrap/wrap-promise.test.js +119 -0
  60. package/dist/cjs/common/wrap/wrap-raf.js +6 -6
  61. package/dist/cjs/common/wrap/wrap-timer.js +7 -7
  62. package/dist/cjs/common/wrap/wrap-xhr.js +5 -6
  63. package/dist/cjs/features/ajax/aggregate/index.js +3 -3
  64. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
  65. package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +1 -1
  66. package/dist/cjs/features/jserrors/aggregate/index.js +6 -6
  67. package/dist/cjs/features/jserrors/instrument/index.js +2 -2
  68. package/dist/cjs/features/metrics/aggregate/index.js +19 -9
  69. package/dist/cjs/features/metrics/instrument/index.js +0 -25
  70. package/dist/cjs/features/metrics/instrument/workers-helper.js +5 -5
  71. package/dist/cjs/features/page_action/aggregate/index.js +3 -3
  72. package/dist/cjs/features/page_view_event/aggregate/index.js +23 -9
  73. package/dist/cjs/features/page_view_timing/aggregate/index.js +40 -30
  74. package/dist/cjs/features/session_trace/aggregate/index.js +18 -15
  75. package/dist/cjs/features/spa/aggregate/index.js +6 -5
  76. package/dist/cjs/features/utils/agent-session.js +73 -0
  77. package/dist/cjs/features/utils/feature-base.js +1 -1
  78. package/dist/cjs/features/utils/instrument-base.js +12 -3
  79. package/dist/cjs/features/utils/lazy-loader.js +2 -2
  80. package/dist/cjs/loaders/agent.js +2 -2
  81. package/dist/cjs/loaders/api/api.js +9 -9
  82. package/dist/cjs/loaders/api/apiAsync.js +3 -2
  83. package/dist/cjs/loaders/configure/configure.js +0 -6
  84. package/dist/cjs/loaders/features/enabled-features.js +1 -1
  85. package/dist/cjs/loaders/micro-agent.js +2 -1
  86. package/dist/esm/common/browser-version/ios-version.js +4 -3
  87. package/dist/esm/common/config/state/configurable.js +26 -20
  88. package/dist/esm/common/config/state/info.js +1 -1
  89. package/dist/esm/common/config/state/init.js +9 -1
  90. package/dist/esm/common/config/state/loader-config.js +1 -1
  91. package/dist/esm/common/config/state/runtime.js +26 -28
  92. package/dist/esm/common/constants/env.cdn.js +20 -0
  93. package/dist/esm/common/constants/env.js +23 -0
  94. package/dist/esm/common/constants/env.npm.js +21 -0
  95. package/dist/esm/common/context/shared-context.js +2 -1
  96. package/dist/esm/common/event-emitter/contextual-ee.test.js +278 -0
  97. package/dist/esm/common/event-emitter/handle.test.js +54 -0
  98. package/dist/esm/common/event-emitter/register-handler.test.js +51 -0
  99. package/dist/esm/common/event-listener/event-listener-opts.js +4 -2
  100. package/dist/esm/common/harvest/harvest-scheduler.js +14 -11
  101. package/dist/esm/common/harvest/harvest.js +4 -2
  102. package/dist/esm/common/ids/id.js +16 -6
  103. package/dist/esm/common/ids/id.test.js +81 -0
  104. package/dist/esm/common/ids/unique-id.js +75 -51
  105. package/dist/esm/common/ids/unique-id.test.js +44 -0
  106. package/dist/esm/common/session/constants.js +3 -0
  107. package/dist/esm/common/session/session-entity.js +271 -0
  108. package/dist/esm/common/session/session-entity.test.js +434 -0
  109. package/dist/esm/common/storage/first-party-cookies.js +28 -0
  110. package/dist/esm/common/storage/local-memory.js +28 -0
  111. package/dist/esm/common/storage/local-memory.test.js +18 -0
  112. package/dist/esm/common/storage/local-storage.js +26 -0
  113. package/dist/esm/common/storage/local-storage.test.js +12 -0
  114. package/dist/esm/common/timer/interaction-timer.js +71 -0
  115. package/dist/esm/common/timer/interaction-timer.test.js +214 -0
  116. package/dist/esm/common/timer/timer.js +25 -0
  117. package/dist/esm/common/timer/timer.test.js +103 -0
  118. package/dist/esm/common/timing/nav-timing.js +51 -29
  119. package/dist/esm/common/timing/nav-timing.test.js +190 -0
  120. package/dist/esm/common/unload/eol.js +1 -1
  121. package/dist/esm/common/url/clean-url.test.js +7 -0
  122. package/dist/esm/common/url/encode.test.js +70 -0
  123. package/dist/esm/common/url/location.js +4 -0
  124. package/dist/esm/common/url/location.test.js +11 -0
  125. package/dist/esm/common/url/parse-url.test.js +107 -0
  126. package/dist/esm/common/url/protocol.js +3 -12
  127. package/dist/esm/common/url/protocol.test.js +14 -0
  128. package/dist/esm/common/util/console.js +1 -1
  129. package/dist/esm/common/util/data-size.js +7 -0
  130. package/dist/esm/common/util/data-size.test.js +45 -0
  131. package/dist/esm/common/util/invoke.js +66 -0
  132. package/dist/esm/common/util/invoke.test.js +47 -0
  133. package/dist/esm/common/util/map-own.test.js +3 -3
  134. package/dist/esm/common/util/obfuscate.js +2 -6
  135. package/dist/esm/common/window/page-visibility.js +5 -2
  136. package/dist/esm/common/wrap/index.js +1 -2
  137. package/dist/esm/common/wrap/wrap-events.js +6 -9
  138. package/dist/esm/common/wrap/wrap-fetch.js +6 -6
  139. package/dist/esm/common/wrap/wrap-history.js +7 -6
  140. package/dist/esm/common/wrap/wrap-jsonp.js +7 -6
  141. package/dist/esm/common/wrap/wrap-mutation.js +7 -6
  142. package/dist/esm/common/wrap/wrap-promise.js +7 -6
  143. package/dist/esm/common/wrap/wrap-promise.test.js +115 -0
  144. package/dist/esm/common/wrap/wrap-raf.js +6 -6
  145. package/dist/esm/common/wrap/wrap-timer.js +7 -7
  146. package/dist/esm/common/wrap/wrap-xhr.js +5 -6
  147. package/dist/esm/features/ajax/aggregate/index.js +3 -3
  148. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
  149. package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +1 -1
  150. package/dist/esm/features/jserrors/aggregate/index.js +6 -6
  151. package/dist/esm/features/jserrors/instrument/index.js +2 -2
  152. package/dist/esm/features/metrics/aggregate/index.js +21 -11
  153. package/dist/esm/features/metrics/instrument/index.js +0 -25
  154. package/dist/esm/features/metrics/instrument/workers-helper.js +5 -5
  155. package/dist/esm/features/page_action/aggregate/index.js +3 -3
  156. package/dist/esm/features/page_view_event/aggregate/index.js +23 -9
  157. package/dist/esm/features/page_view_timing/aggregate/index.js +40 -30
  158. package/dist/esm/features/session_trace/aggregate/index.js +18 -15
  159. package/dist/esm/features/spa/aggregate/index.js +6 -5
  160. package/dist/esm/features/utils/agent-session.js +67 -0
  161. package/dist/esm/features/utils/feature-base.js +1 -1
  162. package/dist/esm/features/utils/instrument-base.js +7 -2
  163. package/dist/esm/features/utils/lazy-loader.js +2 -2
  164. package/dist/esm/loaders/agent.js +2 -2
  165. package/dist/esm/loaders/api/api.js +6 -9
  166. package/dist/esm/loaders/api/apiAsync.js +2 -1
  167. package/dist/esm/loaders/configure/configure.js +2 -8
  168. package/dist/esm/loaders/features/enabled-features.js +1 -1
  169. package/dist/types/common/config/state/configurable.d.ts.map +1 -1
  170. package/dist/types/common/config/state/init.d.ts.map +1 -1
  171. package/dist/types/common/config/state/runtime.d.ts.map +1 -1
  172. package/dist/types/common/constants/env.cdn.d.ts +18 -0
  173. package/dist/types/common/constants/env.cdn.d.ts.map +1 -0
  174. package/dist/types/common/constants/env.d.ts +13 -0
  175. package/dist/types/common/constants/env.d.ts.map +1 -0
  176. package/dist/types/common/constants/env.npm.d.ts +19 -0
  177. package/dist/types/common/constants/env.npm.d.ts.map +1 -0
  178. package/dist/types/common/context/shared-context.d.ts.map +1 -1
  179. package/dist/types/common/event-listener/event-listener-opts.d.ts +2 -2
  180. package/dist/types/common/event-listener/event-listener-opts.d.ts.map +1 -1
  181. package/dist/types/common/harvest/harvest-scheduler.d.ts +1 -0
  182. package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
  183. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  184. package/dist/types/common/ids/id.d.ts +11 -1
  185. package/dist/types/common/ids/id.d.ts.map +1 -1
  186. package/dist/types/common/ids/unique-id.d.ts +24 -1
  187. package/dist/types/common/ids/unique-id.d.ts.map +1 -1
  188. package/dist/types/common/session/constants.d.ts +4 -0
  189. package/dist/types/common/session/constants.d.ts.map +1 -0
  190. package/dist/types/common/session/session-entity.d.ts +72 -0
  191. package/dist/types/common/session/session-entity.d.ts.map +1 -0
  192. package/dist/types/common/storage/first-party-cookies.d.ts +8 -0
  193. package/dist/types/common/storage/first-party-cookies.d.ts.map +1 -0
  194. package/dist/types/common/storage/local-memory.d.ts +8 -0
  195. package/dist/types/common/storage/local-memory.d.ts.map +1 -0
  196. package/dist/types/common/storage/local-storage.d.ts +6 -0
  197. package/dist/types/common/storage/local-storage.d.ts.map +1 -0
  198. package/dist/types/common/timer/interaction-timer.d.ts +11 -0
  199. package/dist/types/common/timer/interaction-timer.d.ts.map +1 -0
  200. package/dist/types/common/timer/timer.d.ts +12 -0
  201. package/dist/types/common/timer/timer.d.ts.map +1 -0
  202. package/dist/types/common/timing/nav-timing.d.ts +1 -2
  203. package/dist/types/common/timing/nav-timing.d.ts.map +1 -1
  204. package/dist/types/common/unload/eol.d.ts.map +1 -1
  205. package/dist/types/common/url/location.d.ts +4 -0
  206. package/dist/types/common/url/location.d.ts.map +1 -1
  207. package/dist/types/common/url/parse-url.d.ts.map +1 -1
  208. package/dist/types/common/url/protocol.d.ts +1 -6
  209. package/dist/types/common/url/protocol.d.ts.map +1 -1
  210. package/dist/types/common/util/data-size.d.ts +7 -1
  211. package/dist/types/common/util/data-size.d.ts.map +1 -1
  212. package/dist/types/common/util/global-scope.d.ts.map +1 -1
  213. package/dist/types/common/util/invoke.d.ts +35 -0
  214. package/dist/types/common/util/invoke.d.ts.map +1 -0
  215. package/dist/types/common/util/obfuscate.d.ts.map +1 -1
  216. package/dist/types/common/window/page-visibility.d.ts +1 -1
  217. package/dist/types/common/window/page-visibility.d.ts.map +1 -1
  218. package/dist/types/common/wrap/index.d.ts +1 -2
  219. package/dist/types/common/wrap/index.d.ts.map +1 -1
  220. package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
  221. package/dist/types/common/wrap/wrap-history.d.ts.map +1 -1
  222. package/dist/types/common/wrap/wrap-jsonp.d.ts.map +1 -1
  223. package/dist/types/common/wrap/wrap-mutation.d.ts.map +1 -1
  224. package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -1
  225. package/dist/types/common/wrap/wrap-raf.d.ts.map +1 -1
  226. package/dist/types/common/wrap/wrap-timer.d.ts.map +1 -1
  227. package/dist/types/common/wrap/wrap-xhr.d.ts.map +1 -1
  228. package/dist/types/features/ajax/aggregate/index.d.ts +2 -2
  229. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  230. package/dist/types/features/jserrors/aggregate/index.d.ts +2 -2
  231. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  232. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  233. package/dist/types/features/metrics/aggregate/index.d.ts +2 -2
  234. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  235. package/dist/types/features/metrics/instrument/index.d.ts +0 -1
  236. package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
  237. package/dist/types/features/metrics/instrument/workers-helper.d.ts.map +1 -1
  238. package/dist/types/features/page_action/aggregate/index.d.ts +2 -2
  239. package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -1
  240. package/dist/types/features/page_view_event/aggregate/index.d.ts +2 -2
  241. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  242. package/dist/types/features/page_view_timing/aggregate/index.d.ts +3 -4
  243. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  244. package/dist/types/features/session_trace/aggregate/index.d.ts +3 -3
  245. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  246. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  247. package/dist/types/features/spa/aggregate/index.d.ts +2 -2
  248. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  249. package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
  250. package/dist/types/features/utils/agent-session.d.ts +2 -0
  251. package/dist/types/features/utils/agent-session.d.ts.map +1 -0
  252. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  253. package/dist/types/features/utils/lazy-loader.d.ts +2 -2
  254. package/dist/types/features/utils/lazy-loader.d.ts.map +1 -1
  255. package/dist/types/loaders/api/api.d.ts.map +1 -1
  256. package/dist/types/loaders/api/apiAsync.d.ts.map +1 -1
  257. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  258. package/package.json +12 -32
  259. package/src/common/browser-version/ios-version.js +4 -3
  260. package/src/common/config/state/configurable.js +26 -19
  261. package/src/common/config/state/init.js +7 -0
  262. package/src/common/config/state/runtime.js +7 -10
  263. package/src/common/constants/env.cdn.js +20 -0
  264. package/src/common/constants/env.js +23 -0
  265. package/src/common/constants/env.npm.js +21 -0
  266. package/src/common/context/shared-context.js +2 -1
  267. package/src/common/event-emitter/contextual-ee.test.js +310 -0
  268. package/src/common/event-emitter/handle.test.js +56 -0
  269. package/src/common/event-emitter/register-handler.test.js +61 -0
  270. package/src/common/event-listener/event-listener-opts.js +4 -4
  271. package/src/common/harvest/harvest-scheduler.js +12 -8
  272. package/src/common/harvest/harvest.js +5 -3
  273. package/src/common/ids/id.js +15 -6
  274. package/src/common/ids/id.test.js +92 -0
  275. package/src/common/ids/unique-id.js +77 -54
  276. package/src/common/ids/unique-id.test.js +58 -0
  277. package/src/common/session/constants.js +3 -0
  278. package/src/common/session/session-entity.js +271 -0
  279. package/src/common/session/session-entity.test.js +317 -0
  280. package/src/common/storage/first-party-cookies.js +31 -0
  281. package/src/common/storage/local-memory.js +30 -0
  282. package/src/common/storage/local-memory.test.js +19 -0
  283. package/src/common/storage/local-storage.js +28 -0
  284. package/src/common/storage/local-storage.test.js +17 -0
  285. package/src/common/timer/interaction-timer.js +75 -0
  286. package/src/common/timer/interaction-timer.test.js +167 -0
  287. package/src/common/timer/timer.js +31 -0
  288. package/src/common/timer/timer.test.js +100 -0
  289. package/src/common/timing/nav-timing.js +50 -30
  290. package/src/common/timing/nav-timing.test.js +161 -0
  291. package/src/common/unload/eol.js +2 -3
  292. package/src/common/url/clean-url.test.js +25 -0
  293. package/src/common/url/encode.test.js +80 -0
  294. package/src/common/url/location.js +4 -0
  295. package/src/common/url/location.test.js +15 -0
  296. package/src/common/url/parse-url.js +1 -2
  297. package/src/common/url/parse-url.test.js +110 -0
  298. package/src/common/url/protocol.js +3 -13
  299. package/src/common/url/protocol.test.js +18 -0
  300. package/src/common/util/data-size.js +6 -0
  301. package/src/common/util/data-size.test.js +50 -0
  302. package/src/common/util/global-scope.js +1 -2
  303. package/src/common/util/invoke.js +55 -0
  304. package/src/common/util/invoke.test.js +65 -0
  305. package/src/common/util/obfuscate.js +2 -6
  306. package/src/common/window/page-visibility.js +3 -3
  307. package/src/common/wrap/index.js +1 -2
  308. package/src/common/wrap/wrap-events.js +5 -5
  309. package/src/common/wrap/wrap-fetch.js +4 -3
  310. package/src/common/wrap/wrap-history.js +6 -3
  311. package/src/common/wrap/wrap-jsonp.js +5 -3
  312. package/src/common/wrap/wrap-mutation.js +6 -3
  313. package/src/common/wrap/wrap-promise.js +7 -6
  314. package/src/common/wrap/wrap-promise.test.js +140 -0
  315. package/src/common/wrap/wrap-raf.js +5 -3
  316. package/src/common/wrap/wrap-timer.js +6 -4
  317. package/src/common/wrap/wrap-xhr.js +4 -3
  318. package/src/features/ajax/aggregate/index.js +2 -2
  319. package/src/features/ajax/instrument/index.js +1 -1
  320. package/src/features/jserrors/aggregate/index.js +3 -3
  321. package/src/features/jserrors/instrument/index.js +4 -2
  322. package/src/features/metrics/aggregate/index.js +21 -7
  323. package/src/features/metrics/instrument/index.js +0 -30
  324. package/src/features/metrics/instrument/workers-helper.js +9 -6
  325. package/src/features/page_action/aggregate/index.js +2 -2
  326. package/src/features/page_view_event/aggregate/index.js +21 -9
  327. package/src/features/page_view_timing/aggregate/index.js +40 -29
  328. package/src/features/page_view_timing/long-tasks.js +10 -10
  329. package/src/features/session_trace/aggregate/index.js +17 -14
  330. package/src/features/session_trace/instrument/index.js +3 -2
  331. package/src/features/spa/aggregate/index.js +5 -5
  332. package/src/features/spa/instrument/index.js +4 -2
  333. package/src/features/utils/agent-session.js +68 -0
  334. package/src/features/utils/feature-base.js +1 -1
  335. package/src/features/utils/instrument-base.js +5 -2
  336. package/src/features/utils/lazy-loader.js +1 -1
  337. package/src/loaders/agent.js +1 -1
  338. package/src/loaders/api/api.js +3 -6
  339. package/src/loaders/api/apiAsync.js +2 -1
  340. package/src/loaders/configure/configure.js +2 -7
  341. package/dist/cjs/common/constants/environment-variables.js +0 -20
  342. package/dist/cjs/common/util/single.js +0 -23
  343. package/dist/cjs/common/window/session-storage.js +0 -87
  344. package/dist/cjs/common/wrap/wrap-console.js +0 -54
  345. package/dist/cjs/features/utils/aggregate-base.js +0 -13
  346. package/dist/esm/common/constants/environment-variables.js +0 -11
  347. package/dist/esm/common/util/single.js +0 -16
  348. package/dist/esm/common/window/session-storage.js +0 -77
  349. package/dist/esm/common/wrap/wrap-console.js +0 -46
  350. package/dist/esm/features/utils/aggregate-base.js +0 -6
  351. package/dist/types/common/constants/environment-variables.d.ts +0 -4
  352. package/dist/types/common/constants/environment-variables.d.ts.map +0 -1
  353. package/dist/types/common/util/single.d.ts +0 -2
  354. package/dist/types/common/util/single.d.ts.map +0 -1
  355. package/dist/types/common/window/session-storage.d.ts +0 -18
  356. package/dist/types/common/window/session-storage.d.ts.map +0 -1
  357. package/dist/types/common/wrap/wrap-console.d.ts +0 -16
  358. package/dist/types/common/wrap/wrap-console.d.ts.map +0 -1
  359. package/dist/types/features/utils/aggregate-base.d.ts +0 -4
  360. package/dist/types/features/utils/aggregate-base.d.ts.map +0 -1
  361. package/src/common/constants/environment-variables.js +0 -11
  362. package/src/common/util/single.js +0 -18
  363. package/src/common/window/session-storage.js +0 -75
  364. package/src/common/wrap/wrap-console.js +0 -47
  365. package/src/features/utils/aggregate-base.js +0 -7
@@ -0,0 +1,31 @@
1
+
2
+ export class Timer {
3
+ constructor (opts, ms) {
4
+ if (!opts.onEnd) throw new Error('onEnd handler is required')
5
+ if (!ms) throw new Error('ms duration is required')
6
+ this.onEnd = opts.onEnd
7
+ this.initialMs = ms
8
+ this.startTimestamp = Date.now()
9
+
10
+ this.timer = this.create(this.onEnd, ms)
11
+ }
12
+
13
+ create (cb, ms) {
14
+ if (this.timer) this.clear()
15
+ return setTimeout(() => cb ? cb() : this.onEnd(), ms || this.initialMs)
16
+ }
17
+
18
+ clear () {
19
+ clearTimeout(this.timer)
20
+ this.timer = null
21
+ }
22
+
23
+ end () {
24
+ this.clear()
25
+ this.onEnd()
26
+ }
27
+
28
+ isValid () {
29
+ return this.initialMs - (Date.now() - this.startTimestamp) > 0
30
+ }
31
+ }
@@ -0,0 +1,100 @@
1
+ import { Timer } from './timer'
2
+
3
+ jest.useFakeTimers()
4
+
5
+ let now
6
+
7
+ beforeEach(() => {
8
+ now = Date.now()
9
+ jest.setSystemTime(now)
10
+ })
11
+
12
+ afterEach(() => {
13
+ jest.clearAllMocks()
14
+ })
15
+
16
+ describe('constructor', () => {
17
+ test('appropriate properties are set with valid values -- no refresh', () => {
18
+ const timer = new Timer({ onEnd: jest.fn() }, 100)
19
+ const requiredKeys = ['onEnd', 'initialMs', 'startTimestamp', 'timer']
20
+ expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy()
21
+ })
22
+
23
+ test('appropriate properties are set with valid values -- with refresh', () => {
24
+ const timer = new Timer({ onEnd: jest.fn() }, 100)
25
+ const requiredKeys = ['onEnd', 'initialMs', 'startTimestamp', 'timer']
26
+ expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy()
27
+ })
28
+
29
+ test('required keys are enforced', () => {
30
+ try {
31
+ new Timer({}, 100)
32
+ } catch (e) {
33
+ expect(e).toEqual(new Error('onEnd handler is required'))
34
+ }
35
+
36
+ try {
37
+ new Timer({ onEnd: jest.fn() })
38
+ } catch (e) {
39
+ expect(e).toEqual(new Error('ms duration is required'))
40
+ }
41
+ })
42
+ })
43
+
44
+ describe('create()', () => {
45
+ test('Create sets a timeout that can execute a cb', () => {
46
+ const timer = new Timer({ onEnd: jest.fn() }, 100)
47
+ expect(timer.timer).toBeTruthy()
48
+ expect(timer.onEnd).toHaveBeenCalledTimes(0)
49
+ jest.runOnlyPendingTimers()
50
+ expect(timer.onEnd).toHaveBeenCalledTimes(1)
51
+ })
52
+
53
+ test('Create can fallback to use defaults', () => {
54
+ let called = 0
55
+ const timer1 = new Timer({ onEnd: jest.fn() }, 100)
56
+ timer1.create()
57
+
58
+ const timer2 = new Timer({ onEnd: jest.fn() }, 100)
59
+ timer2.create(timer2.onEnd)
60
+
61
+ const timer3 = new Timer({ onEnd: jest.fn() }, 100)
62
+ timer3.create(undefined, 100)
63
+
64
+ jest.runAllTimers(200)
65
+
66
+ expect(timer1.onEnd).toHaveBeenCalledTimes(1)
67
+ expect(timer2.onEnd).toHaveBeenCalledTimes(1)
68
+ expect(timer3.onEnd).toHaveBeenCalledTimes(1)
69
+ })
70
+ })
71
+
72
+ describe('clear()', () => {
73
+ test('clear prevents the callback from firing and deletes the pointer', () => {
74
+ const timer = new Timer({ onEnd: jest.fn() }, 100)
75
+ expect(timer.onEnd).toHaveBeenCalledTimes(0)
76
+ timer.clear()
77
+ jest.advanceTimersByTime(150)
78
+ expect(timer.onEnd).toHaveBeenCalledTimes(0)
79
+ expect(timer.timer).toEqual(null)
80
+ })
81
+ })
82
+
83
+ describe('end()', () => {
84
+ test('end clears the callback and calls the onEnd callback', () => {
85
+ const timer = new Timer({ onEnd: jest.fn() }, 100)
86
+ expect(timer.onEnd).toHaveBeenCalledTimes(0)
87
+ timer.end()
88
+ expect(timer.onEnd).toHaveBeenCalledTimes(1)
89
+ expect(timer.timer).toEqual(null)
90
+ })
91
+ })
92
+
93
+ describe('isValid', () => {
94
+ test('isValid validates timeStamps', () => {
95
+ const timer = new Timer({ onEnd: jest.fn() }, 100)
96
+ expect(timer.isValid()).toEqual(true)
97
+ timer.startTimestamp -= 100
98
+ expect(timer.isValid()).toEqual(false)
99
+ })
100
+ })
@@ -27,44 +27,64 @@ var DOM_CONTENT_LOAD_EVENT = 'domContentLoadedEvent'
27
27
 
28
28
  export var navTimingValues = []
29
29
 
30
- export function addPT (offset, pt, v) {
30
+ function getPntType (type) {
31
+ if (typeof type == 'number') return type
32
+ const types = {
33
+ navigate: undefined,
34
+ reload: 1,
35
+ back_forward: 2,
36
+ prerender: 3
37
+ }
38
+ return types[type]
39
+ }
40
+
41
+ export function addPT (offset, pt, v = {}, isL1Api = false) {
42
+ if (!pt) return
31
43
  v.of = offset
32
- addRel(offset, offset, v, 'n')
33
- addRel(pt[UNLOAD_EVENT + START], offset, v, 'u')
34
- addRel(pt[REDIRECT + START], offset, v, 'r')
35
- addRel(pt[UNLOAD_EVENT + END], offset, v, 'ue')
36
- addRel(pt[REDIRECT + END], offset, v, 're')
37
- addRel(pt['fetch' + START], offset, v, 'f')
38
- addRel(pt[DOMAIN_LOOKUP + START], offset, v, 'dn')
39
- addRel(pt[DOMAIN_LOOKUP + END], offset, v, 'dne')
40
- addRel(pt['c' + ONNECT + START], offset, v, 'c')
41
- addRel(pt['secureC' + ONNECT + 'ion' + START], offset, v, 's')
42
- addRel(pt['c' + ONNECT + END], offset, v, 'ce')
43
- addRel(pt[REQUEST + START], offset, v, 'rq')
44
- addRel(pt[RESPONSE + START], offset, v, 'rp')
45
- addRel(pt[RESPONSE + END], offset, v, 'rpe')
46
- addRel(pt.domLoading, offset, v, 'dl')
47
- addRel(pt.domInteractive, offset, v, 'di')
48
- addRel(pt[DOM_CONTENT_LOAD_EVENT + START], offset, v, 'ds')
49
- addRel(pt[DOM_CONTENT_LOAD_EVENT + END], offset, v, 'de')
50
- addRel(pt.domComplete, offset, v, 'dc')
51
- addRel(pt[LOAD_EVENT + START], offset, v, 'l')
52
- addRel(pt[LOAD_EVENT + END], offset, v, 'le')
44
+ handleValue(v.of, v, 'n', true)
45
+ handleValue(pt[UNLOAD_EVENT + START], v, 'u', isL1Api)
46
+ handleValue(pt[REDIRECT + START], v, 'r', isL1Api)
47
+ handleValue(pt[UNLOAD_EVENT + END], v, 'ue', isL1Api)
48
+ handleValue(pt[REDIRECT + END], v, 're', isL1Api)
49
+ handleValue(pt['fetch' + START], v, 'f', isL1Api)
50
+ handleValue(pt[DOMAIN_LOOKUP + START], v, 'dn', isL1Api)
51
+ handleValue(pt[DOMAIN_LOOKUP + END], v, 'dne', isL1Api)
52
+ handleValue(pt['c' + ONNECT + START], v, 'c', isL1Api)
53
+ handleValue(pt['secureC' + ONNECT + 'ion' + START], v, 's', isL1Api)
54
+ handleValue(pt['c' + ONNECT + END], v, 'ce', isL1Api)
55
+ handleValue(pt[REQUEST + START], v, 'rq', isL1Api)
56
+ handleValue(pt[RESPONSE + START], v, 'rp', isL1Api)
57
+ handleValue(pt[RESPONSE + END], v, 'rpe', isL1Api)
58
+ handleValue(pt.domLoading, v, 'dl', isL1Api)
59
+ handleValue(pt.domInteractive, v, 'di', isL1Api)
60
+ handleValue(pt[DOM_CONTENT_LOAD_EVENT + START], v, 'ds', isL1Api)
61
+ handleValue(pt[DOM_CONTENT_LOAD_EVENT + END], v, 'de', isL1Api)
62
+ handleValue(pt.domComplete, v, 'dc', isL1Api)
63
+ handleValue(pt[LOAD_EVENT + START], v, 'l', isL1Api)
64
+ handleValue(pt[LOAD_EVENT + END], v, 'le', isL1Api)
53
65
  return v
54
66
  }
55
67
 
56
68
  // Add Performance Navigation values to the given object
57
69
  export function addPN (pn, v) {
58
- addRel(pn.type, 0, v, 'ty')
59
- addRel(pn.redirectCount, 0, v, 'rc')
70
+ handleValue(getPntType(pn.type), v, 'ty')
71
+ handleValue(pn.redirectCount, v, 'rc')
60
72
  return v
61
73
  }
62
74
 
63
- export function addRel (value, offset, obj, prop) {
64
- var relativeValue
65
- if (typeof (value) === 'number' && (value > 0)) {
66
- relativeValue = Math.max(Math.round(value - offset), 0)
67
- obj[prop] = relativeValue
75
+ function handleValue (value, obj, prop, isOldApi) {
76
+ /*
77
+ For L2 Timing API, the value will already be a relative-to-previous-document DOMHighResTimeStamp.
78
+ For L1 (deprecated) Timing, the value is an UNIX epoch timestamp, which we will convert to a relative time using our offset.
79
+ PNT.type is reported as undefined, 1, 2, etc -- note that zero-value properties will be recorded as 'undefined', however DEM interprets undefined "types" as "navigate"
80
+ */
81
+ if (typeof value === 'number' && value > 0) { // note that zero-value properties will be recorded as 'undefined'
82
+ if (isOldApi) {
83
+ const offset = obj?.of > 0 ? obj.of : 0 // expect an epoch timestamp, if called by addPT
84
+ value = Math.max(value - offset, 0)
85
+ }
86
+ value = Math.round(value)
87
+ obj[prop] = value
68
88
  }
69
- navTimingValues.push(relativeValue)
89
+ navTimingValues.push(value)
70
90
  }
@@ -0,0 +1,161 @@
1
+ import { addPT, addPN, navTimingValues } from './nav-timing'
2
+
3
+ const offset = 123
4
+ const testValues = {
5
+ unloadEventStart: 1,
6
+ redirectStart: 2,
7
+ unloadEventEnd: 3,
8
+ redirectEnd: 4,
9
+ fetchStart: 5,
10
+ domainLookupStart: 6,
11
+ domainLookupEnd: 7,
12
+ connectStart: 8,
13
+ secureConnectionStart: 9,
14
+ connectEnd: 10,
15
+ requestStart: 11,
16
+ responseStart: 12,
17
+ responseEnd: 13,
18
+ domLoading: 14,
19
+ domInteractive: 15,
20
+ domContentLoadedEventStart: 16,
21
+ domContentLoadedEventEnd: 17,
22
+ domComplete: 18,
23
+ loadEventStart: 19,
24
+ loadEventEnd: 20,
25
+ type: 'reload',
26
+ redirectCount: 22
27
+ }
28
+
29
+ const legacyTestValues = {
30
+ unloadEventStart: offset + 1,
31
+ redirectStart: offset + 2,
32
+ unloadEventEnd: offset + 3,
33
+ redirectEnd: offset + 4,
34
+ fetchStart: offset + 5,
35
+ domainLookupStart: offset + 6,
36
+ domainLookupEnd: offset + 7,
37
+ connectStart: offset + 8,
38
+ secureConnectionStart: offset + 9,
39
+ connectEnd: offset + 10,
40
+ requestStart: offset + 11,
41
+ responseStart: offset + 12,
42
+ responseEnd: offset + 13,
43
+ domLoading: offset + 14,
44
+ domInteractive: offset + 15,
45
+ domContentLoadedEventStart: offset + 16,
46
+ domContentLoadedEventEnd: offset + 17,
47
+ domComplete: offset + 18,
48
+ loadEventStart: offset + 19,
49
+ loadEventEnd: offset + 20,
50
+ type: 'reload',
51
+ redirectCount: offset + 22
52
+ }
53
+
54
+ const expectedPT = {
55
+ of: offset,
56
+ n: 0,
57
+ u: 1,
58
+ r: 2,
59
+ ue: 3,
60
+ re: 4,
61
+ f: 5,
62
+ dn: 6,
63
+ dne: 7,
64
+ c: 8,
65
+ s: 9,
66
+ ce: 10,
67
+ rq: 11,
68
+ rp: 12,
69
+ rpe: 13,
70
+ dl: 14,
71
+ di: 15,
72
+ ds: 16,
73
+ de: 17,
74
+ dc: 18,
75
+ l: 19,
76
+ le: 20
77
+ }
78
+
79
+ const expectedPN = {
80
+ ty: 1,
81
+ rc: 22
82
+ }
83
+
84
+ describe('addPT()', () => {
85
+ test('an output object is populated with valid values', () => {
86
+ const output = addPT(offset, testValues, {})
87
+ expect(output).toEqual(expectedPT)
88
+ })
89
+
90
+ test('an object with invalid values is handled', () => {
91
+ const output = addPT(offset, { ...testValues, invalidValue: 'test' }, {})
92
+ expect(output).toEqual(expectedPT)
93
+
94
+ const output2 = addPT(offset, { ...testValues, loadEventEnd: -1 }, {})
95
+ let expected = { ...expectedPT }
96
+ delete expected.le
97
+ expect(output2).toEqual(expected)
98
+
99
+ const output3 = addPT(offset, { ...testValues, loadEventEnd: 'test' }, {})
100
+ expected = { ...expectedPT }
101
+ delete expected.le
102
+ expect(output3).toEqual(expected)
103
+
104
+ const output4 = addPT(offset, { ...testValues, loadEventEnd: null }, {})
105
+ expected = { ...expectedPT }
106
+ delete expected.le
107
+ expect(output4).toEqual(expected)
108
+
109
+ const legacyoutput = addPT(offset, { ...legacyTestValues, invalidValue: 'test' }, {}, true)
110
+ expect(legacyoutput).toEqual(expectedPT)
111
+
112
+ const legacyoutput2 = addPT(offset, { ...legacyTestValues, loadEventEnd: -1 }, {}, true)
113
+ let legacyexpected = { ...expectedPT }
114
+ delete legacyexpected.le
115
+ expect(legacyoutput2).toEqual(expected)
116
+
117
+ const legacyoutput3 = addPT(offset, { ...legacyTestValues, loadEventEnd: 'test' }, {}, true)
118
+ legacyexpected = { ...expectedPT }
119
+ delete legacyexpected.le
120
+ expect(legacyoutput3).toEqual(legacyexpected)
121
+
122
+ const legacyoutput4 = addPT(offset, { ...legacyTestValues, loadEventEnd: null }, {}, true)
123
+ legacyexpected = { ...expectedPT }
124
+ delete legacyexpected.le
125
+ expect(legacyoutput4).toEqual(legacyexpected)
126
+ })
127
+
128
+ test('rounds values to integers', () => {
129
+ const output = addPT(offset, { unloadEventStart: 3.14159 }, {})
130
+ expect(output.u).toEqual(3)
131
+
132
+ const legacyoutput = addPT(0, { unloadEventStart: 3.14159 }, {}, true)
133
+ expect(legacyoutput.u).toEqual(3)
134
+ })
135
+
136
+ test('adds entries to navTimingValues', () => {
137
+ const beforeLength = navTimingValues.length
138
+ addPT(offset, { testValues }, {})
139
+ const afterLength = navTimingValues.length
140
+ expect(afterLength - beforeLength).toEqual(21) // 20 + value of n
141
+
142
+ const legacybeforeLength = navTimingValues.length
143
+ addPT(offset, { legacyTestValues }, {}, true)
144
+ const legacyafterLength = navTimingValues.length
145
+ expect(legacyafterLength - legacybeforeLength).toEqual(21) // 20 + value of n
146
+ })
147
+ })
148
+
149
+ describe('addPN()', () => {
150
+ test('an output object is populated with valid values', () => {
151
+ const output = addPN(testValues, {})
152
+ expect(output).toEqual(expectedPN)
153
+ })
154
+
155
+ test('adds entries to navTimingValues', () => {
156
+ const beforeLength = navTimingValues.length
157
+ addPN(offset, { testValues }, {})
158
+ const afterLength = navTimingValues.length
159
+ expect(afterLength - beforeLength).toEqual(2)
160
+ })
161
+ })
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { ffVersion } from '../browser-version/firefox-version'
6
6
  import { windowAddEventListener } from '../event-listener/event-listener-opts'
7
- import { single } from '../util/single'
7
+ import { single } from '../util/invoke'
8
8
  import { globalScope, isWorkerScope, isBrowserScope } from '../util/global-scope'
9
9
  import { subscribeToVisibilityChange } from '../window/page-visibility'
10
10
 
@@ -55,8 +55,7 @@ export function subscribeToEOL (cb, allowBFCache) {
55
55
  }
56
56
  windowAddEventListener('unload', oneCall)
57
57
  }
58
- }
59
- else if (isWorkerScope) {
58
+ } else if (isWorkerScope) {
60
59
  globalScope.cleanupTasks.push(cb) // close() should run these tasks before quitting thread
61
60
  }
62
61
  // By default (for other env), this fn has no effect.
@@ -0,0 +1,25 @@
1
+ import { cleanURL } from './clean-url'
2
+
3
+ test.each([
4
+ ['http://domain.com/path?query=5', 'http://domain.com/path'],
5
+ ['http://domain.com/path#fragment', 'http://domain.com/path'],
6
+ ['http://domain.com/path?query=5#fragment', 'http://domain.com/path'],
7
+ ['http://domain.com/path?query=5?dumb#fragment', 'http://domain.com/path'],
8
+ ['http://domain.com/path?query=5#fragment#dumb', 'http://domain.com/path'],
9
+ ['http://domain.com/path?query=5#fragment#dumb?additional_query', 'http://domain.com/path'],
10
+ ['http://domain.com/path?query=5#fragment/silly/dumber#dumbest?additional_query=silly#what_is_this_even', 'http://domain.com/path']
11
+ ])('cleanURL should remove hash', (input, expected) => {
12
+ expect(cleanURL(input)).toEqual(expected)
13
+ })
14
+
15
+ test.each([
16
+ ['http://domain.com/path?query=5', 'http://domain.com/path'],
17
+ ['http://domain.com/path#fragment', 'http://domain.com/path#fragment'],
18
+ ['http://domain.com/path?query=5#fragment', 'http://domain.com/path#fragment'],
19
+ ['http://domain.com/path?query=5?dumb#fragment', 'http://domain.com/path#fragment'],
20
+ ['http://domain.com/path?query=5#fragment#dumb', 'http://domain.com/path#fragment#dumb'],
21
+ ['http://domain.com/path?query=5#fragment#dumb?additional_query', 'http://domain.com/path#fragment#dumb'],
22
+ ['http://domain.com/path?query=5#fragment/silly/dumber#dumbest?additional_query=silly#what_is_this_even', 'http://domain.com/path#fragment/silly/dumber#dumbest']
23
+ ])('cleanURL should retain hash if second argument is true', (input, expected) => {
24
+ expect(cleanURL(input, true)).toEqual(expected)
25
+ })
@@ -0,0 +1,80 @@
1
+ import * as encode from './encode'
2
+
3
+ describe('query string encoding', () => {
4
+ test('escapes string components except safe characters', () => {
5
+ const input = 'Asdf:, :, /@$;'
6
+ const expected = 'Asdf:,%20:,%20/@$;'
7
+
8
+ expect(encode.qs(input)).toEqual(expected)
9
+ })
10
+
11
+ test('null and undefined value returns \'null\'', () => {
12
+ expect(encode.qs(null)).toEqual('null')
13
+ expect(encode.qs(undefined)).toEqual('null')
14
+ })
15
+ })
16
+
17
+ describe('fromArray encoding', () => {
18
+ test('cuts cleanly at end of byte', () => {
19
+ const input = ['a', 'b', 'c']
20
+ const expected = 'ab'
21
+
22
+ expect(encode.fromArray(input, 2)).toEqual(expected)
23
+ })
24
+
25
+ test('fall back to largest whole chunk', () => {
26
+ const input = ['aa', 'bb', 'cc']
27
+ const expected = 'aabb'
28
+
29
+ expect(encode.fromArray(input, 5)).toEqual(expected)
30
+ })
31
+ })
32
+
33
+ describe('object encoding', () => {
34
+ test('cuts cleanly at end of byte', () => {
35
+ const input = { foo: [1, 2, 3] }
36
+ const expected = '&foo=%5B1,2%5D'
37
+
38
+ expect(encode.obj(input, 12)).toEqual(expected)
39
+ })
40
+
41
+ test('fall back to largest whole chunk', () => {
42
+ const input = { bar: ['a', 'b', 'c'] }
43
+ const expected = '&bar=%5B%22a%22,%22b%22%5D'
44
+
45
+ expect(encode.obj(input, 30)).toEqual(expected)
46
+ })
47
+
48
+ test('handles circular objects', () => {
49
+ const circular = {}
50
+ circular.circular = circular
51
+ const input = { bar: ['a', circular, 'c'] }
52
+ const expected = '&bar=%5B%22a%22,%7B%7D,%22c%22%5D'
53
+
54
+ expect(encode.obj(input, 1000)).toEqual(expected)
55
+ })
56
+
57
+ test('handles circular arrays', () => {
58
+ const circular = []
59
+ circular.push(circular)
60
+ const input = { bar: ['a', circular, 'c'] }
61
+ const expected = '&bar=%5B%22a%22,%5Bnull%5D,%22c%22%5D'
62
+
63
+ expect(encode.obj(input, 1000)).toEqual(expected)
64
+ })
65
+ })
66
+
67
+ describe('encode key value pairs as query params', () => {
68
+ test('ignores input when value is null or undefined', () => {
69
+ expect(encode.param('foo', null)).toEqual('')
70
+ expect(encode.param('foo', undefined)).toEqual('')
71
+ })
72
+
73
+ test('encodes key value pair correctly', () => {
74
+ expect(encode.param('foo', 'bar')).toEqual('&foo=bar')
75
+ })
76
+
77
+ test('ignores input when value is not a string', () => {
78
+ expect(encode.param('foo', {})).toEqual('')
79
+ })
80
+ })
@@ -3,6 +3,10 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
6
+ /**
7
+ * This method only exists to support testing in JIL and can be removed once tests are migrated to WDIO.
8
+ * @returns global scope location
9
+ */
6
10
  export function getLocation () {
7
11
  return '' + location
8
12
  }
@@ -0,0 +1,15 @@
1
+ import { faker } from '@faker-js/faker'
2
+ import { getLocation } from './location'
3
+
4
+ test('should always return a string', () => {
5
+ jest.spyOn(window, 'location', 'get').mockReturnValue({})
6
+
7
+ expect(typeof getLocation()).toEqual('string')
8
+ })
9
+
10
+ test('should return window location', () => {
11
+ const expected = faker.internet.url()
12
+ jest.spyOn(window, 'location', 'get').mockReturnValue(expected)
13
+
14
+ expect(getLocation()).toEqual(expected)
15
+ })
@@ -27,8 +27,7 @@ export function parseUrl (url) {
27
27
  // Use an anchor dom element to resolve the url natively.
28
28
  urlEl = document.createElement('a')
29
29
  urlEl.href = url
30
- }
31
- else {
30
+ } else {
32
31
  try {
33
32
  urlEl = new URL(url, location.href)
34
33
  } catch (err) {
@@ -0,0 +1,110 @@
1
+ afterEach(() => {
2
+ jest.resetModules()
3
+ jest.clearAllMocks()
4
+ })
5
+
6
+ const urlTests = [
7
+ {
8
+ input: 'http://example.com/path/name?qs=5&a=b',
9
+ expected: {
10
+ hostname: 'example.com',
11
+ pathname: '/path/name',
12
+ protocol: 'http',
13
+ port: '80',
14
+ sameOrigin: false
15
+ }
16
+ },
17
+ {
18
+ input: 'http://foo:bar@example.com:8080/path/@name?qs=5&a=b',
19
+ expected: {
20
+ hostname: 'example.com',
21
+ pathname: '/path/@name',
22
+ protocol: 'http',
23
+ port: '8080',
24
+ sameOrigin: false
25
+ }
26
+ },
27
+ {
28
+ input: 'https://foo:bar@example.com/path/name?qs=5&a=b',
29
+ expected: {
30
+ hostname: 'example.com',
31
+ pathname: '/path/name',
32
+ protocol: 'https',
33
+ port: '443',
34
+ sameOrigin: false
35
+ }
36
+ },
37
+ {
38
+ input: '/path/name?qs=5&a=b',
39
+ expected: {
40
+ hostname: location.hostname,
41
+ pathname: '/path/name',
42
+ protocol: location.protocol.split(':')[0],
43
+ port: '80',
44
+ sameOrigin: true
45
+ }
46
+ },
47
+ {
48
+ input: location.protocol + '//' + location.hostname + ':' + location.port + '/path/name?qs=5&a=b',
49
+ expected: {
50
+ hostname: location.hostname,
51
+ pathname: '/path/name',
52
+ protocol: location.protocol.split(':')[0],
53
+ port: '80',
54
+ sameOrigin: true
55
+ }
56
+ },
57
+ {
58
+ input: 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==',
59
+ expected: {
60
+ protocol: 'data'
61
+ }
62
+ }
63
+ ]
64
+
65
+ test.each(urlTests)('verify url parsing inside browser scope', async ({ input, expected }) => {
66
+ jest.doMock('../util/global-scope', () => ({
67
+ __esModule: true,
68
+ isBrowserScope: true,
69
+ globalScope: global
70
+ }))
71
+
72
+ const { parseUrl } = await import('./parse-url')
73
+ expect(parseUrl(input)).toEqual(expected)
74
+ })
75
+
76
+ test.each(urlTests)('verify url parsing outside browser scope', async ({ input, expected }) => {
77
+ jest.doMock('../util/global-scope', () => ({
78
+ __esModule: true,
79
+ isBrowserScope: false,
80
+ globalScope: global
81
+ }))
82
+
83
+ const { parseUrl } = await import('./parse-url')
84
+ expect(parseUrl(input)).toEqual(expected)
85
+ })
86
+
87
+ test('should cache parsed urls', async () => {
88
+ jest.doMock('../util/global-scope', () => ({
89
+ __esModule: true,
90
+ isBrowserScope: true,
91
+ globalScope: global
92
+ }))
93
+
94
+ const input = 'http://example.com/'
95
+ const expected = {
96
+ hostname: 'example.com',
97
+ pathname: '/',
98
+ protocol: 'http',
99
+ port: '80',
100
+ sameOrigin: false
101
+ }
102
+
103
+ jest.spyOn(document, 'createElement')
104
+
105
+ const { parseUrl } = await import('./parse-url')
106
+ parseUrl(input)
107
+
108
+ expect(parseUrl(input)).toEqual(expected)
109
+ expect(document.createElement).toHaveBeenCalledTimes(1)
110
+ })
@@ -2,18 +2,8 @@
2
2
  * Copyright 2020 New Relic Corporation. All rights reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { getGlobalScope } from '../util/global-scope'
5
+ import { globalScope } from '../util/global-scope'
6
6
 
7
- export const protocol = {
8
- isFileProtocol: isFileProtocol,
9
- supportabilityMetricSent: false
10
- }
11
-
12
- function isFileProtocol () {
13
- let isFile = Boolean(getGlobalScope()?.location?.protocol === 'file:')
14
- if (isFile) {
15
- //metrics.recordSupportability('Generic/FileProtocol/Detected') -- may be implemented later? Probably make sure it's once per window
16
- protocol.supportabilityMetricSent = true
17
- }
18
- return isFile
7
+ export function isFileProtocol () {
8
+ return Boolean(globalScope?.location?.protocol === 'file:')
19
9
  }