@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,214 @@
1
+ import { InteractionTimer } from './interaction-timer';
2
+ jest.useFakeTimers();
3
+ let now;
4
+ beforeEach(() => {
5
+ now = Date.now();
6
+ jest.setSystemTime(now);
7
+ });
8
+ afterEach(() => {
9
+ jest.clearAllMocks();
10
+ });
11
+ describe('constructor', () => {
12
+ test('appropriate properties are set with valid values -- no refresh', () => {
13
+ const timer = new InteractionTimer({
14
+ onEnd: jest.fn()
15
+ }, 100);
16
+ const requiredKeys = ['onEnd', 'initialMs', 'startTimestamp', 'timer'];
17
+ expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy();
18
+ });
19
+ test('appropriate properties are set with valid values -- with refresh', () => {
20
+ const timer = new InteractionTimer({
21
+ onEnd: jest.fn()
22
+ }, 100);
23
+ const requiredKeys = ['onEnd', 'refresh', 'initialMs', 'startTimestamp', 'timer'];
24
+ expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy();
25
+ });
26
+ test('required keys are enforced', () => {
27
+ try {
28
+ new InteractionTimer({}, 100);
29
+ } catch (e) {
30
+ expect(e).toEqual(new Error('onEnd handler is required'));
31
+ }
32
+ try {
33
+ new InteractionTimer({
34
+ onEnd: jest.fn()
35
+ });
36
+ } catch (e) {
37
+ expect(e).toEqual(new Error('ms duration is required'));
38
+ }
39
+ });
40
+ test('refresh type timers set event listeners', () => {
41
+ // eslint-disable-next-line
42
+ let ee = {
43
+ on: jest.fn().mockImplementation((evt, cb) => {
44
+ cb([{
45
+ type: 'click'
46
+ }]);
47
+ })
48
+ };
49
+ let it = new InteractionTimer({
50
+ onEnd: jest.fn(),
51
+ onRefresh: jest.fn(),
52
+ ee
53
+ }, 100);
54
+ // scroll, keypress, click
55
+ expect(ee.on).toHaveBeenCalledTimes(1);
56
+ expect(it.onRefresh).toHaveBeenCalledTimes(1);
57
+
58
+ // eslint-disable-next-line
59
+ ee = {
60
+ on: jest.fn().mockImplementation((evt, cb) => {
61
+ cb([{
62
+ type: 'scroll'
63
+ }]);
64
+ })
65
+ };
66
+ it = new InteractionTimer({
67
+ onEnd: jest.fn(),
68
+ onRefresh: jest.fn(),
69
+ ee
70
+ }, 100);
71
+ // scroll, keypress, click
72
+ expect(ee.on).toHaveBeenCalledTimes(1);
73
+ expect(it.onRefresh).toHaveBeenCalledTimes(1);
74
+
75
+ // eslint-disable-next-line
76
+ ee = {
77
+ on: jest.fn().mockImplementation((evt, cb) => {
78
+ cb([{
79
+ type: 'keydown'
80
+ }]);
81
+ })
82
+ };
83
+ it = new InteractionTimer({
84
+ onEnd: jest.fn(),
85
+ onRefresh: jest.fn(),
86
+ ee
87
+ }, 100);
88
+ // scroll, keypress, click
89
+ expect(ee.on).toHaveBeenCalledTimes(1);
90
+ expect(it.onRefresh).toHaveBeenCalledTimes(1);
91
+ const aelSpy = jest.spyOn(document, 'addEventListener');
92
+ // eslint-disable-next-line
93
+ ee = {
94
+ on: jest.fn().mockImplementation((evt, cb) => {
95
+ cb([{
96
+ type: 'keydown'
97
+ }]);
98
+ })
99
+ };
100
+ it = new InteractionTimer({
101
+ onEnd: jest.fn(),
102
+ onRefresh: jest.fn(),
103
+ ee
104
+ }, 100);
105
+ // visibility change
106
+ expect(aelSpy).toHaveBeenCalledTimes(1);
107
+ });
108
+ });
109
+ describe('create()', () => {
110
+ test('Create sets a timeout that can execute a cb', () => {
111
+ const timer = new InteractionTimer({
112
+ onEnd: jest.fn()
113
+ }, 100);
114
+ expect(timer.timer).toBeTruthy();
115
+ expect(timer.onEnd).toHaveBeenCalledTimes(0);
116
+ jest.runOnlyPendingTimers();
117
+ expect(timer.onEnd).toHaveBeenCalledTimes(1);
118
+ });
119
+ test('Create can fallback to use defaults', () => {
120
+ let called = 0;
121
+ const timer1 = new InteractionTimer({
122
+ onEnd: jest.fn()
123
+ }, 100);
124
+ timer1.create();
125
+ const timer2 = new InteractionTimer({
126
+ onEnd: jest.fn()
127
+ }, 100);
128
+ timer2.create(timer2.onEnd);
129
+ const timer3 = new InteractionTimer({
130
+ onEnd: jest.fn()
131
+ }, 100);
132
+ timer3.create(undefined, 100);
133
+ jest.runAllTimers(200);
134
+ expect(timer1.onEnd).toHaveBeenCalledTimes(1);
135
+ expect(timer2.onEnd).toHaveBeenCalledTimes(1);
136
+ expect(timer3.onEnd).toHaveBeenCalledTimes(1);
137
+ });
138
+ });
139
+ describe('refresh()', () => {
140
+ test('refresh prevents the callback from firing', () => {
141
+ const timer = new InteractionTimer({
142
+ onEnd: jest.fn(),
143
+ onRefresh: jest.fn()
144
+ }, 100);
145
+ expect(timer.onEnd).toHaveBeenCalledTimes(0);
146
+ jest.advanceTimersByTime(75);
147
+ expect(timer.onEnd).toHaveBeenCalledTimes(0);
148
+ timer.refresh();
149
+ jest.advanceTimersByTime(75);
150
+ expect(timer.onEnd).toHaveBeenCalledTimes(0);
151
+ jest.advanceTimersByTime(100);
152
+ expect(timer.onEnd).toHaveBeenCalledTimes(1);
153
+ });
154
+ test('refresh executes a callback for consumers', () => {
155
+ const timer = new InteractionTimer({
156
+ onEnd: jest.fn(),
157
+ onRefresh: jest.fn()
158
+ }, 100);
159
+ timer.refresh();
160
+ expect(timer.onRefresh).toHaveBeenCalledTimes(1);
161
+ });
162
+ });
163
+ describe('pause()', () => {
164
+ test('pause prevents the callback from firing', () => {
165
+ const timer = new InteractionTimer({
166
+ onEnd: jest.fn()
167
+ }, 100);
168
+ expect(timer.onEnd).toHaveBeenCalledTimes(0);
169
+ timer.pause();
170
+ jest.advanceTimersByTime(150);
171
+ expect(timer.onEnd).toHaveBeenCalledTimes(0);
172
+ });
173
+ test('pause sets remainingMs timestamp', () => {
174
+ const timer = new InteractionTimer({
175
+ onEnd: jest.fn()
176
+ }, 100);
177
+ expect(timer.remainingMs).toEqual(undefined);
178
+ timer.pause();
179
+ expect(timer.remainingMs).toEqual(timer.initialMs - (now - timer.startTimestamp));
180
+ });
181
+ });
182
+ describe('clear()', () => {
183
+ test('clear prevents the callback from firing and deletes the pointer', () => {
184
+ const timer = new InteractionTimer({
185
+ onEnd: jest.fn()
186
+ }, 100);
187
+ expect(timer.onEnd).toHaveBeenCalledTimes(0);
188
+ timer.clear();
189
+ jest.advanceTimersByTime(150);
190
+ expect(timer.onEnd).toHaveBeenCalledTimes(0);
191
+ expect(timer.timer).toEqual(null);
192
+ });
193
+ });
194
+ describe('end()', () => {
195
+ test('end clears the callback and calls the onEnd callback', () => {
196
+ const timer = new InteractionTimer({
197
+ onEnd: jest.fn()
198
+ }, 100);
199
+ expect(timer.onEnd).toHaveBeenCalledTimes(0);
200
+ timer.end();
201
+ expect(timer.onEnd).toHaveBeenCalledTimes(1);
202
+ expect(timer.timer).toEqual(null);
203
+ });
204
+ });
205
+ describe('isValid', () => {
206
+ test('isValid validates timeStamps', () => {
207
+ const timer = new InteractionTimer({
208
+ onEnd: jest.fn()
209
+ }, 100);
210
+ expect(timer.isValid()).toEqual(true);
211
+ timer.startTimestamp -= 100;
212
+ expect(timer.isValid()).toEqual(false);
213
+ });
214
+ });
@@ -0,0 +1,25 @@
1
+ export class Timer {
2
+ constructor(opts, ms) {
3
+ if (!opts.onEnd) throw new Error('onEnd handler is required');
4
+ if (!ms) throw new Error('ms duration is required');
5
+ this.onEnd = opts.onEnd;
6
+ this.initialMs = ms;
7
+ this.startTimestamp = Date.now();
8
+ this.timer = this.create(this.onEnd, ms);
9
+ }
10
+ create(cb, ms) {
11
+ if (this.timer) this.clear();
12
+ return setTimeout(() => cb ? cb() : this.onEnd(), ms || this.initialMs);
13
+ }
14
+ clear() {
15
+ clearTimeout(this.timer);
16
+ this.timer = null;
17
+ }
18
+ end() {
19
+ this.clear();
20
+ this.onEnd();
21
+ }
22
+ isValid() {
23
+ return this.initialMs - (Date.now() - this.startTimestamp) > 0;
24
+ }
25
+ }
@@ -0,0 +1,103 @@
1
+ import { Timer } from './timer';
2
+ jest.useFakeTimers();
3
+ let now;
4
+ beforeEach(() => {
5
+ now = Date.now();
6
+ jest.setSystemTime(now);
7
+ });
8
+ afterEach(() => {
9
+ jest.clearAllMocks();
10
+ });
11
+ describe('constructor', () => {
12
+ test('appropriate properties are set with valid values -- no refresh', () => {
13
+ const timer = new Timer({
14
+ onEnd: jest.fn()
15
+ }, 100);
16
+ const requiredKeys = ['onEnd', 'initialMs', 'startTimestamp', 'timer'];
17
+ expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy();
18
+ });
19
+ test('appropriate properties are set with valid values -- with refresh', () => {
20
+ const timer = new Timer({
21
+ onEnd: jest.fn()
22
+ }, 100);
23
+ const requiredKeys = ['onEnd', 'initialMs', 'startTimestamp', 'timer'];
24
+ expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy();
25
+ });
26
+ test('required keys are enforced', () => {
27
+ try {
28
+ new Timer({}, 100);
29
+ } catch (e) {
30
+ expect(e).toEqual(new Error('onEnd handler is required'));
31
+ }
32
+ try {
33
+ new Timer({
34
+ onEnd: jest.fn()
35
+ });
36
+ } catch (e) {
37
+ expect(e).toEqual(new Error('ms duration is required'));
38
+ }
39
+ });
40
+ });
41
+ describe('create()', () => {
42
+ test('Create sets a timeout that can execute a cb', () => {
43
+ const timer = new Timer({
44
+ onEnd: jest.fn()
45
+ }, 100);
46
+ expect(timer.timer).toBeTruthy();
47
+ expect(timer.onEnd).toHaveBeenCalledTimes(0);
48
+ jest.runOnlyPendingTimers();
49
+ expect(timer.onEnd).toHaveBeenCalledTimes(1);
50
+ });
51
+ test('Create can fallback to use defaults', () => {
52
+ let called = 0;
53
+ const timer1 = new Timer({
54
+ onEnd: jest.fn()
55
+ }, 100);
56
+ timer1.create();
57
+ const timer2 = new Timer({
58
+ onEnd: jest.fn()
59
+ }, 100);
60
+ timer2.create(timer2.onEnd);
61
+ const timer3 = new Timer({
62
+ onEnd: jest.fn()
63
+ }, 100);
64
+ timer3.create(undefined, 100);
65
+ jest.runAllTimers(200);
66
+ expect(timer1.onEnd).toHaveBeenCalledTimes(1);
67
+ expect(timer2.onEnd).toHaveBeenCalledTimes(1);
68
+ expect(timer3.onEnd).toHaveBeenCalledTimes(1);
69
+ });
70
+ });
71
+ describe('clear()', () => {
72
+ test('clear prevents the callback from firing and deletes the pointer', () => {
73
+ const timer = new Timer({
74
+ onEnd: jest.fn()
75
+ }, 100);
76
+ expect(timer.onEnd).toHaveBeenCalledTimes(0);
77
+ timer.clear();
78
+ jest.advanceTimersByTime(150);
79
+ expect(timer.onEnd).toHaveBeenCalledTimes(0);
80
+ expect(timer.timer).toEqual(null);
81
+ });
82
+ });
83
+ describe('end()', () => {
84
+ test('end clears the callback and calls the onEnd callback', () => {
85
+ const timer = new Timer({
86
+ onEnd: jest.fn()
87
+ }, 100);
88
+ expect(timer.onEnd).toHaveBeenCalledTimes(0);
89
+ timer.end();
90
+ expect(timer.onEnd).toHaveBeenCalledTimes(1);
91
+ expect(timer.timer).toEqual(null);
92
+ });
93
+ });
94
+ describe('isValid', () => {
95
+ test('isValid validates timeStamps', () => {
96
+ const timer = new Timer({
97
+ onEnd: jest.fn()
98
+ }, 100);
99
+ expect(timer.isValid()).toEqual(true);
100
+ timer.startTimestamp -= 100;
101
+ expect(timer.isValid()).toEqual(false);
102
+ });
103
+ });
@@ -25,43 +25,65 @@ var RESPONSE = 'response';
25
25
  var LOAD_EVENT = 'loadEvent';
26
26
  var DOM_CONTENT_LOAD_EVENT = 'domContentLoadedEvent';
27
27
  export var navTimingValues = [];
28
- export function addPT(offset, pt, v) {
28
+ function getPntType(type) {
29
+ if (typeof type == 'number') return type;
30
+ const types = {
31
+ navigate: undefined,
32
+ reload: 1,
33
+ back_forward: 2,
34
+ prerender: 3
35
+ };
36
+ return types[type];
37
+ }
38
+ export function addPT(offset, pt) {
39
+ let v = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
40
+ let isL1Api = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
41
+ if (!pt) return;
29
42
  v.of = offset;
30
- addRel(offset, offset, v, 'n');
31
- addRel(pt[UNLOAD_EVENT + START], offset, v, 'u');
32
- addRel(pt[REDIRECT + START], offset, v, 'r');
33
- addRel(pt[UNLOAD_EVENT + END], offset, v, 'ue');
34
- addRel(pt[REDIRECT + END], offset, v, 're');
35
- addRel(pt['fetch' + START], offset, v, 'f');
36
- addRel(pt[DOMAIN_LOOKUP + START], offset, v, 'dn');
37
- addRel(pt[DOMAIN_LOOKUP + END], offset, v, 'dne');
38
- addRel(pt['c' + ONNECT + START], offset, v, 'c');
39
- addRel(pt['secureC' + ONNECT + 'ion' + START], offset, v, 's');
40
- addRel(pt['c' + ONNECT + END], offset, v, 'ce');
41
- addRel(pt[REQUEST + START], offset, v, 'rq');
42
- addRel(pt[RESPONSE + START], offset, v, 'rp');
43
- addRel(pt[RESPONSE + END], offset, v, 'rpe');
44
- addRel(pt.domLoading, offset, v, 'dl');
45
- addRel(pt.domInteractive, offset, v, 'di');
46
- addRel(pt[DOM_CONTENT_LOAD_EVENT + START], offset, v, 'ds');
47
- addRel(pt[DOM_CONTENT_LOAD_EVENT + END], offset, v, 'de');
48
- addRel(pt.domComplete, offset, v, 'dc');
49
- addRel(pt[LOAD_EVENT + START], offset, v, 'l');
50
- addRel(pt[LOAD_EVENT + END], offset, v, 'le');
43
+ handleValue(v.of, v, 'n', true);
44
+ handleValue(pt[UNLOAD_EVENT + START], v, 'u', isL1Api);
45
+ handleValue(pt[REDIRECT + START], v, 'r', isL1Api);
46
+ handleValue(pt[UNLOAD_EVENT + END], v, 'ue', isL1Api);
47
+ handleValue(pt[REDIRECT + END], v, 're', isL1Api);
48
+ handleValue(pt['fetch' + START], v, 'f', isL1Api);
49
+ handleValue(pt[DOMAIN_LOOKUP + START], v, 'dn', isL1Api);
50
+ handleValue(pt[DOMAIN_LOOKUP + END], v, 'dne', isL1Api);
51
+ handleValue(pt['c' + ONNECT + START], v, 'c', isL1Api);
52
+ handleValue(pt['secureC' + ONNECT + 'ion' + START], v, 's', isL1Api);
53
+ handleValue(pt['c' + ONNECT + END], v, 'ce', isL1Api);
54
+ handleValue(pt[REQUEST + START], v, 'rq', isL1Api);
55
+ handleValue(pt[RESPONSE + START], v, 'rp', isL1Api);
56
+ handleValue(pt[RESPONSE + END], v, 'rpe', isL1Api);
57
+ handleValue(pt.domLoading, v, 'dl', isL1Api);
58
+ handleValue(pt.domInteractive, v, 'di', isL1Api);
59
+ handleValue(pt[DOM_CONTENT_LOAD_EVENT + START], v, 'ds', isL1Api);
60
+ handleValue(pt[DOM_CONTENT_LOAD_EVENT + END], v, 'de', isL1Api);
61
+ handleValue(pt.domComplete, v, 'dc', isL1Api);
62
+ handleValue(pt[LOAD_EVENT + START], v, 'l', isL1Api);
63
+ handleValue(pt[LOAD_EVENT + END], v, 'le', isL1Api);
51
64
  return v;
52
65
  }
53
66
 
54
67
  // Add Performance Navigation values to the given object
55
68
  export function addPN(pn, v) {
56
- addRel(pn.type, 0, v, 'ty');
57
- addRel(pn.redirectCount, 0, v, 'rc');
69
+ handleValue(getPntType(pn.type), v, 'ty');
70
+ handleValue(pn.redirectCount, v, 'rc');
58
71
  return v;
59
72
  }
60
- export function addRel(value, offset, obj, prop) {
61
- var relativeValue;
73
+ function handleValue(value, obj, prop, isOldApi) {
74
+ /*
75
+ For L2 Timing API, the value will already be a relative-to-previous-document DOMHighResTimeStamp.
76
+ For L1 (deprecated) Timing, the value is an UNIX epoch timestamp, which we will convert to a relative time using our offset.
77
+ 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"
78
+ */
62
79
  if (typeof value === 'number' && value > 0) {
63
- relativeValue = Math.max(Math.round(value - offset), 0);
64
- obj[prop] = relativeValue;
80
+ // note that zero-value properties will be recorded as 'undefined'
81
+ if (isOldApi) {
82
+ const offset = obj?.of > 0 ? obj.of : 0; // expect an epoch timestamp, if called by addPT
83
+ value = Math.max(value - offset, 0);
84
+ }
85
+ value = Math.round(value);
86
+ obj[prop] = value;
65
87
  }
66
- navTimingValues.push(relativeValue);
88
+ navTimingValues.push(value);
67
89
  }
@@ -0,0 +1,190 @@
1
+ import { addPT, addPN, navTimingValues } from './nav-timing';
2
+ const offset = 123;
3
+ const testValues = {
4
+ unloadEventStart: 1,
5
+ redirectStart: 2,
6
+ unloadEventEnd: 3,
7
+ redirectEnd: 4,
8
+ fetchStart: 5,
9
+ domainLookupStart: 6,
10
+ domainLookupEnd: 7,
11
+ connectStart: 8,
12
+ secureConnectionStart: 9,
13
+ connectEnd: 10,
14
+ requestStart: 11,
15
+ responseStart: 12,
16
+ responseEnd: 13,
17
+ domLoading: 14,
18
+ domInteractive: 15,
19
+ domContentLoadedEventStart: 16,
20
+ domContentLoadedEventEnd: 17,
21
+ domComplete: 18,
22
+ loadEventStart: 19,
23
+ loadEventEnd: 20,
24
+ type: 'reload',
25
+ redirectCount: 22
26
+ };
27
+ const legacyTestValues = {
28
+ unloadEventStart: offset + 1,
29
+ redirectStart: offset + 2,
30
+ unloadEventEnd: offset + 3,
31
+ redirectEnd: offset + 4,
32
+ fetchStart: offset + 5,
33
+ domainLookupStart: offset + 6,
34
+ domainLookupEnd: offset + 7,
35
+ connectStart: offset + 8,
36
+ secureConnectionStart: offset + 9,
37
+ connectEnd: offset + 10,
38
+ requestStart: offset + 11,
39
+ responseStart: offset + 12,
40
+ responseEnd: offset + 13,
41
+ domLoading: offset + 14,
42
+ domInteractive: offset + 15,
43
+ domContentLoadedEventStart: offset + 16,
44
+ domContentLoadedEventEnd: offset + 17,
45
+ domComplete: offset + 18,
46
+ loadEventStart: offset + 19,
47
+ loadEventEnd: offset + 20,
48
+ type: 'reload',
49
+ redirectCount: offset + 22
50
+ };
51
+ const expectedPT = {
52
+ of: offset,
53
+ n: 0,
54
+ u: 1,
55
+ r: 2,
56
+ ue: 3,
57
+ re: 4,
58
+ f: 5,
59
+ dn: 6,
60
+ dne: 7,
61
+ c: 8,
62
+ s: 9,
63
+ ce: 10,
64
+ rq: 11,
65
+ rp: 12,
66
+ rpe: 13,
67
+ dl: 14,
68
+ di: 15,
69
+ ds: 16,
70
+ de: 17,
71
+ dc: 18,
72
+ l: 19,
73
+ le: 20
74
+ };
75
+ const expectedPN = {
76
+ ty: 1,
77
+ rc: 22
78
+ };
79
+ describe('addPT()', () => {
80
+ test('an output object is populated with valid values', () => {
81
+ const output = addPT(offset, testValues, {});
82
+ expect(output).toEqual(expectedPT);
83
+ });
84
+ test('an object with invalid values is handled', () => {
85
+ const output = addPT(offset, {
86
+ ...testValues,
87
+ invalidValue: 'test'
88
+ }, {});
89
+ expect(output).toEqual(expectedPT);
90
+ const output2 = addPT(offset, {
91
+ ...testValues,
92
+ loadEventEnd: -1
93
+ }, {});
94
+ let expected = {
95
+ ...expectedPT
96
+ };
97
+ delete expected.le;
98
+ expect(output2).toEqual(expected);
99
+ const output3 = addPT(offset, {
100
+ ...testValues,
101
+ loadEventEnd: 'test'
102
+ }, {});
103
+ expected = {
104
+ ...expectedPT
105
+ };
106
+ delete expected.le;
107
+ expect(output3).toEqual(expected);
108
+ const output4 = addPT(offset, {
109
+ ...testValues,
110
+ loadEventEnd: null
111
+ }, {});
112
+ expected = {
113
+ ...expectedPT
114
+ };
115
+ delete expected.le;
116
+ expect(output4).toEqual(expected);
117
+ const legacyoutput = addPT(offset, {
118
+ ...legacyTestValues,
119
+ invalidValue: 'test'
120
+ }, {}, true);
121
+ expect(legacyoutput).toEqual(expectedPT);
122
+ const legacyoutput2 = addPT(offset, {
123
+ ...legacyTestValues,
124
+ loadEventEnd: -1
125
+ }, {}, true);
126
+ let legacyexpected = {
127
+ ...expectedPT
128
+ };
129
+ delete legacyexpected.le;
130
+ expect(legacyoutput2).toEqual(expected);
131
+ const legacyoutput3 = addPT(offset, {
132
+ ...legacyTestValues,
133
+ loadEventEnd: 'test'
134
+ }, {}, true);
135
+ legacyexpected = {
136
+ ...expectedPT
137
+ };
138
+ delete legacyexpected.le;
139
+ expect(legacyoutput3).toEqual(legacyexpected);
140
+ const legacyoutput4 = addPT(offset, {
141
+ ...legacyTestValues,
142
+ loadEventEnd: null
143
+ }, {}, true);
144
+ legacyexpected = {
145
+ ...expectedPT
146
+ };
147
+ delete legacyexpected.le;
148
+ expect(legacyoutput4).toEqual(legacyexpected);
149
+ });
150
+ test('rounds values to integers', () => {
151
+ const output = addPT(offset, {
152
+ unloadEventStart: 3.14159
153
+ }, {});
154
+ expect(output.u).toEqual(3);
155
+ const legacyoutput = addPT(0, {
156
+ unloadEventStart: 3.14159
157
+ }, {}, true);
158
+ expect(legacyoutput.u).toEqual(3);
159
+ });
160
+ test('adds entries to navTimingValues', () => {
161
+ const beforeLength = navTimingValues.length;
162
+ addPT(offset, {
163
+ testValues
164
+ }, {});
165
+ const afterLength = navTimingValues.length;
166
+ expect(afterLength - beforeLength).toEqual(21); // 20 + value of n
167
+
168
+ const legacybeforeLength = navTimingValues.length;
169
+ addPT(offset, {
170
+ legacyTestValues
171
+ }, {}, true);
172
+ const legacyafterLength = navTimingValues.length;
173
+ expect(legacyafterLength - legacybeforeLength).toEqual(21); // 20 + value of n
174
+ });
175
+ });
176
+
177
+ describe('addPN()', () => {
178
+ test('an output object is populated with valid values', () => {
179
+ const output = addPN(testValues, {});
180
+ expect(output).toEqual(expectedPN);
181
+ });
182
+ test('adds entries to navTimingValues', () => {
183
+ const beforeLength = navTimingValues.length;
184
+ addPN(offset, {
185
+ testValues
186
+ }, {});
187
+ const afterLength = navTimingValues.length;
188
+ expect(afterLength - beforeLength).toEqual(2);
189
+ });
190
+ });
@@ -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
  if (isWorkerScope) {
@@ -0,0 +1,7 @@
1
+ import { cleanURL } from './clean-url';
2
+ test.each([['http://domain.com/path?query=5', 'http://domain.com/path'], ['http://domain.com/path#fragment', 'http://domain.com/path'], ['http://domain.com/path?query=5#fragment', 'http://domain.com/path'], ['http://domain.com/path?query=5?dumb#fragment', 'http://domain.com/path'], ['http://domain.com/path?query=5#fragment#dumb', 'http://domain.com/path'], ['http://domain.com/path?query=5#fragment#dumb?additional_query', 'http://domain.com/path'], ['http://domain.com/path?query=5#fragment/silly/dumber#dumbest?additional_query=silly#what_is_this_even', 'http://domain.com/path']])('cleanURL should remove hash', (input, expected) => {
3
+ expect(cleanURL(input)).toEqual(expected);
4
+ });
5
+ test.each([['http://domain.com/path?query=5', 'http://domain.com/path'], ['http://domain.com/path#fragment', 'http://domain.com/path#fragment'], ['http://domain.com/path?query=5#fragment', 'http://domain.com/path#fragment'], ['http://domain.com/path?query=5?dumb#fragment', 'http://domain.com/path#fragment'], ['http://domain.com/path?query=5#fragment#dumb', 'http://domain.com/path#fragment#dumb'], ['http://domain.com/path?query=5#fragment#dumb?additional_query', 'http://domain.com/path#fragment#dumb'], ['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']])('cleanURL should retain hash if second argument is true', (input, expected) => {
6
+ expect(cleanURL(input, true)).toEqual(expected);
7
+ });