@newrelic/browser-agent 0.1.229 → 0.1.231
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.
- package/README.md +65 -2
- package/dist/cjs/common/browser-version/ios-version.js +4 -3
- package/dist/cjs/common/config/state/configurable.js +3 -2
- package/dist/cjs/common/config/state/info.js +1 -1
- package/dist/cjs/common/config/state/init.js +1 -1
- package/dist/cjs/common/config/state/loader-config.js +1 -1
- package/dist/cjs/common/config/state/runtime.js +6 -5
- package/dist/cjs/common/constants/env.cdn.js +29 -0
- package/dist/cjs/common/constants/env.js +32 -0
- package/dist/cjs/common/constants/env.npm.js +30 -0
- package/dist/cjs/common/context/shared-context.js +2 -1
- package/dist/cjs/common/drain/drain.js +9 -3
- package/dist/cjs/common/event-emitter/contextual-ee.test.js +282 -0
- package/dist/cjs/common/event-emitter/handle.test.js +58 -0
- package/dist/cjs/common/event-emitter/register-handler.test.js +55 -0
- package/dist/cjs/common/event-listener/event-listener-opts.js +4 -2
- package/dist/cjs/common/harvest/harvest-scheduler.js +2 -1
- package/dist/cjs/common/harvest/harvest.js +15 -4
- package/dist/cjs/common/ids/id.js +14 -6
- package/dist/cjs/common/ids/id.test.js +85 -0
- package/dist/cjs/common/ids/unique-id.js +75 -51
- package/dist/cjs/common/ids/unique-id.test.js +49 -0
- package/dist/cjs/common/timing/nav-timing.js +51 -30
- package/dist/cjs/common/timing/nav-timing.test.js +192 -0
- package/dist/cjs/common/url/clean-url.test.js +9 -0
- package/dist/cjs/common/url/encode.test.js +74 -0
- package/dist/cjs/common/url/location.js +4 -0
- package/dist/cjs/common/url/location.test.js +13 -0
- package/dist/cjs/common/url/parse-url.test.js +111 -0
- package/dist/cjs/common/url/protocol.js +2 -12
- package/dist/cjs/common/url/protocol.test.js +16 -0
- package/dist/cjs/common/util/console.js +2 -2
- package/dist/cjs/common/util/map-own.js +21 -14
- package/dist/cjs/common/util/map-own.test.js +49 -0
- package/dist/cjs/common/util/obfuscate.js +1 -1
- package/dist/cjs/common/util/submit-data.js +11 -3
- package/dist/cjs/common/window/page-visibility.js +4 -2
- package/dist/cjs/common/window/session-storage.js +56 -11
- package/dist/cjs/common/wrap/index.js +4 -4
- package/dist/cjs/common/wrap/wrap-events.js +10 -10
- package/dist/cjs/common/wrap/wrap-fetch.js +6 -8
- package/dist/cjs/common/wrap/wrap-function.js +4 -18
- package/dist/cjs/common/wrap/wrap-history.js +7 -6
- package/dist/cjs/common/wrap/wrap-jsonp.js +7 -6
- package/dist/cjs/common/wrap/wrap-mutation.js +7 -6
- package/dist/cjs/common/wrap/wrap-promise.js +11 -7
- package/dist/cjs/common/wrap/wrap-promise.test.js +119 -0
- package/dist/cjs/common/wrap/wrap-raf.js +6 -6
- package/dist/cjs/common/wrap/wrap-timer.js +6 -6
- package/dist/cjs/common/wrap/wrap-xhr.js +5 -6
- package/dist/cjs/features/ajax/aggregate/index.js +1 -1
- package/dist/cjs/features/ajax/instrument/index.js +2 -1
- package/dist/cjs/features/jserrors/aggregate/canonical-function-name.test.js +5 -4
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +1 -2
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
- package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +6 -5
- package/dist/cjs/features/jserrors/aggregate/index.js +35 -14
- package/dist/cjs/features/jserrors/aggregate/string-hash-code.test.js +5 -4
- package/dist/cjs/features/jserrors/instrument/index.js +9 -12
- package/dist/cjs/features/metrics/aggregate/index.js +16 -6
- package/dist/cjs/features/metrics/instrument/index.js +2 -1
- package/dist/cjs/features/metrics/instrument/workers-helper.js +9 -6
- package/dist/cjs/features/page_action/aggregate/index.js +12 -4
- package/dist/cjs/features/page_action/instrument/index.js +2 -1
- package/dist/cjs/features/page_view_event/aggregate/index.js +25 -10
- package/dist/cjs/features/page_view_event/instrument/index.js +2 -1
- package/dist/cjs/features/page_view_timing/aggregate/index.js +90 -61
- package/dist/cjs/features/page_view_timing/instrument/index.js +2 -1
- package/dist/cjs/features/session_trace/aggregate/index.js +69 -26
- package/dist/cjs/features/session_trace/instrument/index.js +2 -1
- package/dist/cjs/features/spa/instrument/index.js +2 -1
- package/dist/cjs/features/utils/instrument-base.js +8 -3
- package/dist/cjs/features/utils/lazy-loader.js +1 -1
- package/dist/cjs/index.js +9 -9
- package/dist/cjs/loaders/agent.js +3 -2
- package/dist/cjs/loaders/api/api.js +90 -22
- package/dist/cjs/loaders/api/apiAsync.js +3 -3
- package/dist/cjs/loaders/configure/configure.js +13 -7
- package/dist/cjs/loaders/features/enabled-features.js +1 -1
- package/dist/cjs/loaders/micro-agent.js +20 -14
- package/dist/esm/common/browser-version/ios-version.js +4 -3
- package/dist/esm/common/config/state/configurable.js +3 -2
- package/dist/esm/common/config/state/info.js +1 -1
- package/dist/esm/common/config/state/init.js +1 -1
- package/dist/esm/common/config/state/loader-config.js +1 -1
- package/dist/esm/common/config/state/runtime.js +3 -2
- package/dist/esm/common/constants/env.cdn.js +20 -0
- package/dist/esm/common/constants/env.js +23 -0
- package/dist/esm/common/constants/env.npm.js +21 -0
- package/dist/esm/common/context/shared-context.js +2 -1
- package/dist/esm/common/drain/drain.js +9 -3
- package/dist/esm/common/event-emitter/contextual-ee.test.js +278 -0
- package/dist/esm/common/event-emitter/handle.test.js +54 -0
- package/dist/esm/common/event-emitter/register-handler.test.js +51 -0
- package/dist/esm/common/event-listener/event-listener-opts.js +4 -2
- package/dist/esm/common/harvest/harvest-scheduler.js +2 -1
- package/dist/esm/common/harvest/harvest.js +14 -3
- package/dist/esm/common/ids/id.js +16 -6
- package/dist/esm/common/ids/id.test.js +81 -0
- package/dist/esm/common/ids/unique-id.js +75 -51
- package/dist/esm/common/ids/unique-id.test.js +44 -0
- package/dist/esm/common/timing/nav-timing.js +51 -29
- package/dist/esm/common/timing/nav-timing.test.js +190 -0
- package/dist/esm/common/url/clean-url.test.js +7 -0
- package/dist/esm/common/url/encode.test.js +70 -0
- package/dist/esm/common/url/location.js +4 -0
- package/dist/esm/common/url/location.test.js +11 -0
- package/dist/esm/common/url/parse-url.test.js +107 -0
- package/dist/esm/common/url/protocol.js +3 -12
- package/dist/esm/common/url/protocol.test.js +14 -0
- package/dist/esm/common/util/console.js +2 -2
- package/dist/esm/common/util/map-own.js +19 -13
- package/dist/esm/common/util/map-own.test.js +47 -0
- package/dist/esm/common/util/obfuscate.js +2 -2
- package/dist/esm/common/util/submit-data.js +11 -3
- package/dist/esm/common/window/page-visibility.js +4 -2
- package/dist/esm/common/window/session-storage.js +54 -13
- package/dist/esm/common/wrap/index.js +3 -3
- package/dist/esm/common/wrap/wrap-events.js +11 -11
- package/dist/esm/common/wrap/wrap-fetch.js +7 -9
- package/dist/esm/common/wrap/wrap-function.js +4 -17
- package/dist/esm/common/wrap/wrap-history.js +8 -7
- package/dist/esm/common/wrap/wrap-jsonp.js +8 -7
- package/dist/esm/common/wrap/wrap-mutation.js +7 -6
- package/dist/esm/common/wrap/wrap-promise.js +11 -7
- package/dist/esm/common/wrap/wrap-promise.test.js +115 -0
- package/dist/esm/common/wrap/wrap-raf.js +7 -7
- package/dist/esm/common/wrap/wrap-timer.js +7 -7
- package/dist/esm/common/wrap/wrap-xhr.js +7 -8
- package/dist/esm/features/ajax/aggregate/index.js +1 -1
- package/dist/esm/features/ajax/instrument/index.js +2 -1
- package/dist/esm/features/jserrors/aggregate/canonical-function-name.test.js +5 -4
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +1 -2
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
- package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +6 -5
- package/dist/esm/features/jserrors/aggregate/index.js +35 -14
- package/dist/esm/features/jserrors/aggregate/string-hash-code.test.js +5 -4
- package/dist/esm/features/jserrors/instrument/index.js +9 -12
- package/dist/esm/features/metrics/aggregate/index.js +17 -7
- package/dist/esm/features/metrics/instrument/index.js +2 -1
- package/dist/esm/features/metrics/instrument/workers-helper.js +9 -6
- package/dist/esm/features/page_action/aggregate/index.js +12 -4
- package/dist/esm/features/page_action/instrument/index.js +2 -1
- package/dist/esm/features/page_view_event/aggregate/index.js +25 -10
- package/dist/esm/features/page_view_event/instrument/index.js +2 -1
- package/dist/esm/features/page_view_timing/aggregate/index.js +90 -61
- package/dist/esm/features/page_view_timing/instrument/index.js +2 -1
- package/dist/esm/features/session_trace/aggregate/index.js +69 -26
- package/dist/esm/features/session_trace/instrument/index.js +2 -1
- package/dist/esm/features/spa/instrument/index.js +2 -1
- package/dist/esm/features/utils/instrument-base.js +3 -2
- package/dist/esm/features/utils/lazy-loader.js +1 -1
- package/dist/esm/index.js +4 -4
- package/dist/esm/loaders/agent.js +3 -2
- package/dist/esm/loaders/api/api.js +85 -21
- package/dist/esm/loaders/api/apiAsync.js +3 -3
- package/dist/esm/loaders/configure/configure.js +14 -8
- package/dist/esm/loaders/features/enabled-features.js +1 -1
- package/dist/esm/loaders/micro-agent.js +18 -13
- package/dist/types/cdn/lite.d.ts +2 -0
- package/dist/types/cdn/lite.d.ts.map +1 -0
- package/dist/types/cdn/polyfills/lite.d.ts +2 -0
- package/dist/types/cdn/polyfills/lite.d.ts.map +1 -0
- package/dist/types/cdn/polyfills/pro.d.ts +2 -0
- package/dist/types/cdn/polyfills/pro.d.ts.map +1 -0
- package/dist/types/cdn/polyfills/spa.d.ts +2 -0
- package/dist/types/cdn/polyfills/spa.d.ts.map +1 -0
- package/dist/types/cdn/polyfills.d.ts +2 -0
- package/dist/types/cdn/polyfills.d.ts.map +1 -0
- package/dist/types/cdn/pro.d.ts +2 -0
- package/dist/types/cdn/pro.d.ts.map +1 -0
- package/dist/types/cdn/spa.d.ts +2 -0
- package/dist/types/cdn/spa.d.ts.map +1 -0
- package/dist/types/cdn/worker.d.ts +2 -0
- package/dist/types/cdn/worker.d.ts.map +1 -0
- package/dist/types/common/aggregate/aggregator.d.ts +11 -0
- package/dist/types/common/aggregate/aggregator.d.ts.map +1 -0
- package/dist/types/common/browser-version/firefox-version.d.ts +2 -0
- package/dist/types/common/browser-version/firefox-version.d.ts.map +1 -0
- package/dist/types/common/browser-version/ios-version.d.ts +3 -0
- package/dist/types/common/browser-version/ios-version.d.ts.map +1 -0
- package/dist/types/common/config/config.d.ts +13 -0
- package/dist/types/common/config/config.d.ts.map +1 -0
- package/dist/types/common/config/state/configurable.d.ts +4 -0
- package/dist/types/common/config/state/configurable.d.ts.map +1 -0
- package/dist/types/common/config/state/info.d.ts +4 -0
- package/dist/types/common/config/state/info.d.ts.map +1 -0
- package/dist/types/common/config/state/init.d.ts +4 -0
- package/dist/types/common/config/state/init.d.ts.map +1 -0
- package/dist/types/common/config/state/loader-config.d.ts +3 -0
- package/dist/types/common/config/state/loader-config.d.ts.map +1 -0
- package/dist/types/common/config/state/originals.d.ts +2 -0
- package/dist/types/common/config/state/originals.d.ts.map +1 -0
- package/dist/types/common/config/state/runtime.d.ts +3 -0
- package/dist/types/common/config/state/runtime.d.ts.map +1 -0
- package/dist/types/common/constants/env.cdn.d.ts +18 -0
- package/dist/types/common/constants/env.cdn.d.ts.map +1 -0
- package/dist/types/common/constants/env.d.ts +13 -0
- package/dist/types/common/constants/env.d.ts.map +1 -0
- package/dist/types/common/constants/env.npm.d.ts +19 -0
- package/dist/types/common/constants/env.npm.d.ts.map +1 -0
- package/dist/types/common/context/shared-context.d.ts +5 -0
- package/dist/types/common/context/shared-context.d.ts.map +1 -0
- package/dist/types/common/deny-list/deny-list.d.ts +12 -0
- package/dist/types/common/deny-list/deny-list.d.ts.map +1 -0
- package/dist/types/common/drain/drain.d.ts +17 -0
- package/dist/types/common/drain/drain.d.ts.map +1 -0
- package/dist/types/common/event-emitter/contextual-ee.d.ts +4 -0
- package/dist/types/common/event-emitter/contextual-ee.d.ts.map +1 -0
- package/dist/types/common/event-emitter/handle.d.ts +3 -0
- package/dist/types/common/event-emitter/handle.d.ts.map +1 -0
- package/dist/types/common/event-emitter/register-handler.d.ts +8 -0
- package/dist/types/common/event-emitter/register-handler.d.ts.map +1 -0
- package/dist/types/common/event-listener/event-listener-opts.d.ts +10 -0
- package/dist/types/common/event-listener/event-listener-opts.d.ts.map +1 -0
- package/dist/types/common/harvest/harvest-scheduler.d.ts +21 -0
- package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -0
- package/dist/types/common/harvest/harvest.d.ts +58 -0
- package/dist/types/common/harvest/harvest.d.ts.map +1 -0
- package/dist/types/common/ids/id.d.ts +12 -0
- package/dist/types/common/ids/id.d.ts.map +1 -0
- package/dist/types/common/ids/unique-id.d.ts +28 -0
- package/dist/types/common/ids/unique-id.d.ts.map +1 -0
- package/dist/types/common/metrics/framework-detection.d.ts +2 -0
- package/dist/types/common/metrics/framework-detection.d.ts.map +1 -0
- package/dist/types/common/metrics/paint-metrics.d.ts +2 -0
- package/dist/types/common/metrics/paint-metrics.d.ts.map +1 -0
- package/dist/types/common/serialize/bel-serializer.d.ts +5 -0
- package/dist/types/common/serialize/bel-serializer.d.ts.map +1 -0
- package/dist/types/common/timing/nav-timing.d.ts +4 -0
- package/dist/types/common/timing/nav-timing.d.ts.map +1 -0
- package/dist/types/common/timing/now.d.ts +2 -0
- package/dist/types/common/timing/now.d.ts.map +1 -0
- package/dist/types/common/unload/eol.d.ts +8 -0
- package/dist/types/common/unload/eol.d.ts.map +1 -0
- package/dist/types/common/url/clean-url.d.ts +2 -0
- package/dist/types/common/url/clean-url.d.ts.map +1 -0
- package/dist/types/common/url/encode.d.ts +5 -0
- package/dist/types/common/url/encode.d.ts.map +1 -0
- package/dist/types/common/url/location.d.ts +6 -0
- package/dist/types/common/url/location.d.ts.map +1 -0
- package/dist/types/common/url/parse-url.d.ts +2 -0
- package/dist/types/common/url/parse-url.d.ts.map +1 -0
- package/dist/types/common/url/protocol.d.ts +2 -0
- package/dist/types/common/url/protocol.d.ts.map +1 -0
- package/dist/types/common/util/console.d.ts +8 -0
- package/dist/types/common/util/console.d.ts.map +1 -0
- package/dist/types/common/util/data-size.d.ts +2 -0
- package/dist/types/common/util/data-size.d.ts.map +1 -0
- package/dist/types/common/util/feature-flags.d.ts +3 -0
- package/dist/types/common/util/feature-flags.d.ts.map +1 -0
- package/dist/types/common/util/get-or-set.d.ts +2 -0
- package/dist/types/common/util/get-or-set.d.ts.map +1 -0
- package/dist/types/common/util/global-scope.d.ts +13 -0
- package/dist/types/common/util/global-scope.d.ts.map +1 -0
- package/dist/types/common/util/map-own.d.ts +3 -0
- package/dist/types/common/util/map-own.d.ts.map +1 -0
- package/dist/types/common/util/obfuscate.d.ts +8 -0
- package/dist/types/common/util/obfuscate.d.ts.map +1 -0
- package/dist/types/common/util/s-hash.d.ts +2 -0
- package/dist/types/common/util/s-hash.d.ts.map +1 -0
- package/dist/types/common/util/single.d.ts +2 -0
- package/dist/types/common/util/single.d.ts.map +1 -0
- package/dist/types/common/util/stringify.d.ts +8 -0
- package/dist/types/common/util/stringify.d.ts.map +1 -0
- package/dist/types/common/util/submit-data.d.ts +35 -0
- package/dist/types/common/util/submit-data.d.ts.map +1 -0
- package/dist/types/common/util/traverse.d.ts +2 -0
- package/dist/types/common/util/traverse.d.ts.map +1 -0
- package/dist/types/common/util/user-agent.d.ts +5 -0
- package/dist/types/common/util/user-agent.d.ts.map +1 -0
- package/dist/types/common/window/load.d.ts +3 -0
- package/dist/types/common/window/load.d.ts.map +1 -0
- package/dist/types/common/window/nreum.d.ts +14 -0
- package/dist/types/common/window/nreum.d.ts.map +1 -0
- package/dist/types/common/window/page-visibility.d.ts +7 -0
- package/dist/types/common/window/page-visibility.d.ts.map +1 -0
- package/dist/types/common/window/session-storage.d.ts +18 -0
- package/dist/types/common/window/session-storage.d.ts.map +1 -0
- package/dist/types/common/window/supports-performance-observer.d.ts +2 -0
- package/dist/types/common/window/supports-performance-observer.d.ts.map +1 -0
- package/dist/types/common/wrap/index.d.ts +11 -0
- package/dist/types/common/wrap/index.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-events.d.ts +17 -0
- package/dist/types/common/wrap/wrap-events.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-fetch.d.ts +18 -0
- package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-function.d.ts +28 -0
- package/dist/types/common/wrap/wrap-function.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-history.d.ts +16 -0
- package/dist/types/common/wrap/wrap-history.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-jsonp.d.ts +16 -0
- package/dist/types/common/wrap/wrap-jsonp.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-mutation.d.ts +16 -0
- package/dist/types/common/wrap/wrap-mutation.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-promise.d.ts +17 -0
- package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-raf.d.ts +16 -0
- package/dist/types/common/wrap/wrap-raf.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-timer.d.ts +17 -0
- package/dist/types/common/wrap/wrap-timer.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-xhr.d.ts +16 -0
- package/dist/types/common/wrap/wrap-xhr.d.ts.map +1 -0
- package/dist/types/features/ajax/aggregate/index.d.ts +16 -0
- package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/ajax/constants.d.ts +2 -0
- package/dist/types/features/ajax/constants.d.ts.map +1 -0
- package/dist/types/features/ajax/index.d.ts +2 -0
- package/dist/types/features/ajax/index.d.ts.map +1 -0
- package/dist/types/features/ajax/instrument/distributed-tracing.d.ts +19 -0
- package/dist/types/features/ajax/instrument/distributed-tracing.d.ts.map +1 -0
- package/dist/types/features/ajax/instrument/index.d.ts +9 -0
- package/dist/types/features/ajax/instrument/index.d.ts.map +1 -0
- package/dist/types/features/ajax/instrument/response-size.d.ts +2 -0
- package/dist/types/features/ajax/instrument/response-size.d.ts.map +1 -0
- package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts +2 -0
- package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts.map +1 -0
- package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts +22 -0
- package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts.map +1 -0
- package/dist/types/features/jserrors/aggregate/format-stack-trace.d.ts +3 -0
- package/dist/types/features/jserrors/aggregate/format-stack-trace.d.ts.map +1 -0
- package/dist/types/features/jserrors/aggregate/index.d.ts +24 -0
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/jserrors/aggregate/string-hash-code.d.ts +2 -0
- package/dist/types/features/jserrors/aggregate/string-hash-code.d.ts.map +1 -0
- package/dist/types/features/jserrors/constants.d.ts +3 -0
- package/dist/types/features/jserrors/constants.d.ts.map +1 -0
- package/dist/types/features/jserrors/index.d.ts +2 -0
- package/dist/types/features/jserrors/index.d.ts.map +1 -0
- package/dist/types/features/jserrors/instrument/debug.d.ts +2 -0
- package/dist/types/features/jserrors/instrument/debug.d.ts.map +1 -0
- package/dist/types/features/jserrors/instrument/index.d.ts +22 -0
- package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -0
- package/dist/types/features/metrics/aggregate/index.d.ts +12 -0
- package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/metrics/constants.d.ts +6 -0
- package/dist/types/features/metrics/constants.d.ts.map +1 -0
- package/dist/types/features/metrics/index.d.ts +2 -0
- package/dist/types/features/metrics/index.d.ts.map +1 -0
- package/dist/types/features/metrics/instrument/index.d.ts +6 -0
- package/dist/types/features/metrics/instrument/index.d.ts.map +1 -0
- package/dist/types/features/metrics/instrument/workers-helper.d.ts +7 -0
- package/dist/types/features/metrics/instrument/workers-helper.d.ts.map +1 -0
- package/dist/types/features/page_action/aggregate/index.d.ts +24 -0
- package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/page_action/constants.d.ts +2 -0
- package/dist/types/features/page_action/constants.d.ts.map +1 -0
- package/dist/types/features/page_action/index.d.ts +2 -0
- package/dist/types/features/page_action/index.d.ts.map +1 -0
- package/dist/types/features/page_action/instrument/index.d.ts +6 -0
- package/dist/types/features/page_action/instrument/index.d.ts.map +1 -0
- package/dist/types/features/page_view_event/aggregate/index.d.ts +9 -0
- package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/page_view_event/aggregate/initialized-features.d.ts +8 -0
- package/dist/types/features/page_view_event/aggregate/initialized-features.d.ts.map +1 -0
- package/dist/types/features/page_view_event/constants.d.ts +5 -0
- package/dist/types/features/page_view_event/constants.d.ts.map +1 -0
- package/dist/types/features/page_view_event/index.d.ts +2 -0
- package/dist/types/features/page_view_event/index.d.ts.map +1 -0
- package/dist/types/features/page_view_event/instrument/index.d.ts +6 -0
- package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -0
- package/dist/types/features/page_view_timing/aggregate/index.d.ts +32 -0
- package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/page_view_timing/constants.d.ts +2 -0
- package/dist/types/features/page_view_timing/constants.d.ts.map +1 -0
- package/dist/types/features/page_view_timing/first-paint.d.ts +2 -0
- package/dist/types/features/page_view_timing/first-paint.d.ts.map +1 -0
- package/dist/types/features/page_view_timing/index.d.ts +2 -0
- package/dist/types/features/page_view_timing/index.d.ts.map +1 -0
- package/dist/types/features/page_view_timing/instrument/index.d.ts +6 -0
- package/dist/types/features/page_view_timing/instrument/index.d.ts.map +1 -0
- package/dist/types/features/page_view_timing/long-tasks.d.ts +2 -0
- package/dist/types/features/page_view_timing/long-tasks.d.ts.map +1 -0
- package/dist/types/features/session_trace/aggregate/index.d.ts +77 -0
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/session_trace/constants.d.ts +13 -0
- package/dist/types/features/session_trace/constants.d.ts.map +1 -0
- package/dist/types/features/session_trace/index.d.ts +2 -0
- package/dist/types/features/session_trace/index.d.ts.map +1 -0
- package/dist/types/features/session_trace/instrument/index.d.ts +11 -0
- package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -0
- package/dist/types/features/spa/aggregate/index.d.ts +25 -0
- package/dist/types/features/spa/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/spa/aggregate/interaction-node.d.ts +15 -0
- package/dist/types/features/spa/aggregate/interaction-node.d.ts.map +1 -0
- package/dist/types/features/spa/aggregate/interaction.d.ts +20 -0
- package/dist/types/features/spa/aggregate/interaction.d.ts.map +1 -0
- package/dist/types/features/spa/aggregate/serializer.d.ts +15 -0
- package/dist/types/features/spa/aggregate/serializer.d.ts.map +1 -0
- package/dist/types/features/spa/constants.d.ts +23 -0
- package/dist/types/features/spa/constants.d.ts.map +1 -0
- package/dist/types/features/spa/index.d.ts +2 -0
- package/dist/types/features/spa/index.d.ts.map +1 -0
- package/dist/types/features/spa/instrument/index.d.ts +8 -0
- package/dist/types/features/spa/instrument/index.d.ts.map +1 -0
- package/dist/types/features/utils/aggregate-base.d.ts +4 -0
- package/dist/types/features/utils/aggregate-base.d.ts.map +1 -0
- package/dist/types/features/utils/feature-base.d.ts +23 -0
- package/dist/types/features/utils/feature-base.d.ts.map +1 -0
- package/dist/types/features/utils/handler-cache.d.ts +22 -0
- package/dist/types/features/utils/handler-cache.d.ts.map +1 -0
- package/dist/types/features/utils/instrument-base.d.ts +27 -0
- package/dist/types/features/utils/instrument-base.d.ts.map +1 -0
- package/dist/types/features/utils/lazy-loader.d.ts +13 -0
- package/dist/types/features/utils/lazy-loader.d.ts.map +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/loaders/agent.d.ts +20 -0
- package/dist/types/loaders/agent.d.ts.map +1 -0
- package/dist/types/loaders/api/api.d.ts +17 -0
- package/dist/types/loaders/api/api.d.ts.map +1 -0
- package/dist/types/loaders/api/apiAsync.d.ts +2 -0
- package/dist/types/loaders/api/apiAsync.d.ts.map +1 -0
- package/dist/types/loaders/browser-agent.d.ts +9 -0
- package/dist/types/loaders/browser-agent.d.ts.map +1 -0
- package/dist/types/loaders/configure/configure.d.ts +10 -0
- package/dist/types/loaders/configure/configure.d.ts.map +1 -0
- package/dist/types/loaders/features/enabled-features.d.ts +2 -0
- package/dist/types/loaders/features/enabled-features.d.ts.map +1 -0
- package/dist/types/loaders/features/featureDependencies.d.ts +3 -0
- package/dist/types/loaders/features/featureDependencies.d.ts.map +1 -0
- package/dist/types/loaders/features/features.d.ts +18 -0
- package/dist/types/loaders/features/features.d.ts.map +1 -0
- package/dist/types/loaders/micro-agent.d.ts +25 -0
- package/dist/types/loaders/micro-agent.d.ts.map +1 -0
- package/dist/types/loaders/worker-agent.d.ts +8 -0
- package/dist/types/loaders/worker-agent.d.ts.map +1 -0
- package/package.json +67 -59
- package/src/cdn/lite.js +18 -0
- package/src/cdn/polyfills/lite.js +7 -0
- package/src/cdn/polyfills/pro.js +7 -0
- package/src/cdn/polyfills/spa.js +7 -0
- package/src/cdn/polyfills.js +17 -0
- package/src/cdn/pro.js +27 -0
- package/src/cdn/spa.js +28 -0
- package/src/cdn/worker.js +21 -0
- package/src/common/aggregate/aggregator.js +171 -0
- package/src/common/browser-version/firefox-version.js +10 -0
- package/src/common/browser-version/ios-version.js +11 -0
- package/src/common/config/config.js +12 -0
- package/src/common/config/state/configurable.js +26 -0
- package/src/common/config/state/info.js +49 -0
- package/src/common/config/state/init.js +56 -0
- package/src/common/config/state/loader-config.js +25 -0
- package/src/common/config/state/originals.js +3 -0
- package/src/common/config/state/runtime.js +47 -0
- package/src/common/constants/env.cdn.js +20 -0
- package/src/common/constants/env.js +23 -0
- package/src/common/constants/env.npm.js +21 -0
- package/src/common/context/shared-context.js +21 -0
- package/src/common/deny-list/deny-list.js +116 -0
- package/src/common/drain/drain.js +119 -0
- package/src/common/event-emitter/contextual-ee.js +159 -0
- package/src/common/event-emitter/contextual-ee.test.js +310 -0
- package/src/common/event-emitter/handle.js +17 -0
- package/src/common/event-emitter/handle.test.js +56 -0
- package/src/common/event-emitter/register-handler.js +25 -0
- package/src/common/event-emitter/register-handler.test.js +61 -0
- package/src/common/event-listener/event-listener-opts.js +41 -0
- package/src/common/harvest/harvest-scheduler.js +112 -0
- package/src/common/harvest/harvest.js +248 -0
- package/src/common/ids/id.js +32 -0
- package/src/common/ids/id.test.js +92 -0
- package/src/common/ids/unique-id.js +104 -0
- package/src/common/ids/unique-id.test.js +58 -0
- package/src/common/metrics/framework-detection.js +71 -0
- package/src/common/metrics/paint-metrics.js +6 -0
- package/src/common/serialize/bel-serializer.js +93 -0
- package/src/common/timing/nav-timing.js +90 -0
- package/src/common/timing/nav-timing.test.js +161 -0
- package/src/common/timing/now.js +9 -0
- package/src/common/unload/eol.js +62 -0
- package/src/common/url/clean-url.js +10 -0
- package/src/common/url/clean-url.test.js +25 -0
- package/src/common/url/encode.js +75 -0
- package/src/common/url/encode.test.js +80 -0
- package/src/common/url/location.js +12 -0
- package/src/common/url/location.test.js +15 -0
- package/src/common/url/parse-url.js +70 -0
- package/src/common/url/parse-url.test.js +110 -0
- package/src/common/url/protocol.js +9 -0
- package/src/common/url/protocol.test.js +18 -0
- package/src/common/util/console.js +11 -0
- package/src/common/util/data-size.js +21 -0
- package/src/common/util/feature-flags.js +38 -0
- package/src/common/util/get-or-set.js +34 -0
- package/src/common/util/global-scope.js +47 -0
- package/src/common/util/map-own.js +22 -0
- package/src/common/util/map-own.test.js +52 -0
- package/src/common/util/obfuscate.js +73 -0
- package/src/common/util/s-hash.js +14 -0
- package/src/common/util/single.js +18 -0
- package/src/common/util/stringify.js +42 -0
- package/src/common/util/submit-data.js +101 -0
- package/src/common/util/traverse.js +36 -0
- package/src/common/util/user-agent.js +56 -0
- package/src/common/window/load.js +15 -0
- package/src/common/window/nreum.js +110 -0
- package/src/common/window/page-visibility.js +24 -0
- package/src/common/window/session-storage.js +75 -0
- package/src/common/window/supports-performance-observer.js +10 -0
- package/src/common/wrap/index.js +17 -0
- package/src/common/wrap/wrap-events.js +106 -0
- package/src/common/wrap/wrap-fetch.js +110 -0
- package/src/common/wrap/wrap-function.js +248 -0
- package/src/common/wrap/wrap-history.js +51 -0
- package/src/common/wrap/wrap-jsonp.js +136 -0
- package/src/common/wrap/wrap-mutation.js +58 -0
- package/src/common/wrap/wrap-promise.js +166 -0
- package/src/common/wrap/wrap-promise.test.js +140 -0
- package/src/common/wrap/wrap-raf.js +52 -0
- package/src/common/wrap/wrap-timer.js +69 -0
- package/src/common/wrap/wrap-xhr.js +214 -0
- package/src/features/ajax/aggregate/index.js +248 -0
- package/src/features/ajax/constants.js +3 -0
- package/src/features/ajax/index.js +1 -0
- package/src/features/ajax/instrument/distributed-tracing.js +166 -0
- package/src/features/ajax/instrument/index.js +380 -0
- package/src/features/ajax/instrument/response-size.js +18 -0
- package/src/features/jserrors/aggregate/canonical-function-name.js +14 -0
- package/src/features/jserrors/aggregate/canonical-function-name.test.js +13 -0
- package/src/features/jserrors/aggregate/compute-stack-trace.js +231 -0
- package/src/features/jserrors/aggregate/compute-stack-trace.test.js +297 -0
- package/src/features/jserrors/aggregate/format-stack-trace.js +30 -0
- package/src/features/jserrors/aggregate/format-stack-trace.test.js +39 -0
- package/src/features/jserrors/aggregate/index.js +310 -0
- package/src/features/jserrors/aggregate/string-hash-code.js +17 -0
- package/src/features/jserrors/aggregate/string-hash-code.test.js +12 -0
- package/src/features/jserrors/constants.js +4 -0
- package/src/features/jserrors/index.js +1 -0
- package/src/features/jserrors/instrument/debug.js +36 -0
- package/src/features/jserrors/instrument/index.js +151 -0
- package/src/features/metrics/aggregate/index.js +133 -0
- package/src/features/metrics/constants.js +7 -0
- package/src/features/metrics/index.js +1 -0
- package/src/features/metrics/instrument/index.js +14 -0
- package/src/features/metrics/instrument/workers-helper.js +113 -0
- package/src/features/page_action/aggregate/index.js +113 -0
- package/src/features/page_action/constants.js +3 -0
- package/src/features/page_action/index.js +1 -0
- package/src/features/page_action/instrument/index.js +15 -0
- package/src/features/page_view_event/aggregate/index.js +143 -0
- package/src/features/page_view_event/aggregate/initialized-features.js +31 -0
- package/src/features/page_view_event/constants.js +6 -0
- package/src/features/page_view_event/index.js +1 -0
- package/src/features/page_view_event/instrument/index.js +33 -0
- package/src/features/page_view_timing/aggregate/index.js +257 -0
- package/src/features/page_view_timing/constants.js +3 -0
- package/src/features/page_view_timing/first-paint.js +41 -0
- package/src/features/page_view_timing/index.js +1 -0
- package/src/features/page_view_timing/instrument/index.js +30 -0
- package/src/features/page_view_timing/long-tasks.js +60 -0
- package/src/features/session_trace/aggregate/index.js +413 -0
- package/src/features/session_trace/constants.js +15 -0
- package/src/features/session_trace/index.js +1 -0
- package/src/features/session_trace/instrument/index.js +127 -0
- package/src/features/spa/aggregate/index.js +738 -0
- package/src/features/spa/aggregate/interaction-node.js +85 -0
- package/src/features/spa/aggregate/interaction-node.test.js +17 -0
- package/src/features/spa/aggregate/interaction.js +112 -0
- package/src/features/spa/aggregate/serializer.js +198 -0
- package/src/features/spa/constants.js +36 -0
- package/src/features/spa/index.js +1 -0
- package/src/features/spa/instrument/index.js +114 -0
- package/src/features/utils/aggregate-base.js +7 -0
- package/src/features/utils/feature-base.js +51 -0
- package/src/features/utils/handler-cache.js +60 -0
- package/src/features/utils/instrument-base.js +68 -0
- package/src/features/utils/lazy-loader.js +37 -0
- package/src/index.js +15 -0
- package/src/loaders/agent.js +80 -0
- package/src/loaders/api/api.js +175 -0
- package/src/loaders/api/apiAsync.js +92 -0
- package/src/loaders/browser-agent.js +33 -0
- package/src/loaders/configure/configure.js +39 -0
- package/src/loaders/features/enabled-features.js +16 -0
- package/src/loaders/features/featureDependencies.js +26 -0
- package/src/loaders/features/features.js +25 -0
- package/src/loaders/micro-agent.js +84 -0
- package/src/loaders/worker-agent.js +24 -0
- package/dist/cjs/common/constants/environment-variables.js +0 -20
- package/dist/cjs/common/util/reduce.js +0 -22
- package/dist/cjs/common/window/top-level-callers.js +0 -23
- package/dist/esm/common/constants/environment-variables.js +0 -11
- package/dist/esm/common/util/reduce.js +0 -16
- package/dist/esm/common/window/top-level-callers.js +0 -17
- package/types.ts +0 -221
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
var MAX_NODES = 128
|
|
7
|
+
|
|
8
|
+
var lastId = 0
|
|
9
|
+
|
|
10
|
+
export function InteractionNode (interaction, parent, type, timestamp) {
|
|
11
|
+
Object.defineProperty(this, 'interaction', {
|
|
12
|
+
value: interaction, writable: true // enumerable: false -- by default, which hides this prop from obj (iterations)
|
|
13
|
+
})
|
|
14
|
+
this.parent = parent
|
|
15
|
+
this.id = ++lastId
|
|
16
|
+
this.type = type
|
|
17
|
+
this.children = []
|
|
18
|
+
this.end = null
|
|
19
|
+
this.jsEnd = this.start = timestamp
|
|
20
|
+
this.jsTime = 0
|
|
21
|
+
this.attrs = {}
|
|
22
|
+
this.cancelled = false
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var InteractionNodePrototype = InteractionNode.prototype
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} type
|
|
29
|
+
* @param {number} timestamp
|
|
30
|
+
* @param {string} name
|
|
31
|
+
* @param {bool} dontWait - When true, the interaction will not immediately start waiting
|
|
32
|
+
* for this node to complete. This is used when the creation of
|
|
33
|
+
* the node and its start happen at different times (e.g. XHR).
|
|
34
|
+
*/
|
|
35
|
+
InteractionNodePrototype.child = function child (type, timestamp, name, dontWait) {
|
|
36
|
+
var interaction = this.interaction
|
|
37
|
+
if (interaction.end || interaction.nodes >= MAX_NODES) return null
|
|
38
|
+
|
|
39
|
+
interaction.onNodeAdded(this)
|
|
40
|
+
|
|
41
|
+
var node = new InteractionNode(interaction, this, type, timestamp)
|
|
42
|
+
node.attrs.name = name
|
|
43
|
+
interaction.nodes++
|
|
44
|
+
if (!dontWait) {
|
|
45
|
+
interaction.remaining++
|
|
46
|
+
}
|
|
47
|
+
return node
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
InteractionNodePrototype.callback = function addCallbackTime (exclusiveTime, end) {
|
|
51
|
+
var node = this
|
|
52
|
+
|
|
53
|
+
node.jsTime += exclusiveTime
|
|
54
|
+
if (end > node.jsEnd) {
|
|
55
|
+
node.jsEnd = end
|
|
56
|
+
node.interaction.lastCb = end
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
InteractionNodePrototype.cancel = function cancel () {
|
|
61
|
+
this.cancelled = true
|
|
62
|
+
var interaction = this.interaction
|
|
63
|
+
interaction.remaining--
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
InteractionNodePrototype.finish = function finish (timestamp) {
|
|
67
|
+
var node = this
|
|
68
|
+
if (node.end) return
|
|
69
|
+
node.end = timestamp
|
|
70
|
+
|
|
71
|
+
// Find the next parent node that is not cancelled
|
|
72
|
+
let parent = node.parent
|
|
73
|
+
while (parent?.cancelled) parent = parent.parent
|
|
74
|
+
|
|
75
|
+
// Assign the node to the non-cancelled parent node
|
|
76
|
+
if (parent) parent.children.push(node)
|
|
77
|
+
node.parent = null
|
|
78
|
+
|
|
79
|
+
// Update the interaction remaining counter
|
|
80
|
+
var interaction = this.interaction
|
|
81
|
+
interaction.remaining--
|
|
82
|
+
interaction.lastFinish = timestamp
|
|
83
|
+
// check if interaction has finished, (this is needed for older browsers for unknown reasons)
|
|
84
|
+
interaction.checkFinish()
|
|
85
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker'
|
|
2
|
+
import { InteractionNode } from './interaction-node'
|
|
3
|
+
|
|
4
|
+
test('finishing node with cancelled parent should not throw an error', () => {
|
|
5
|
+
const interaction = {
|
|
6
|
+
remaining: 0,
|
|
7
|
+
onNodeAdded: jest.fn(),
|
|
8
|
+
checkFinish: jest.fn()
|
|
9
|
+
}
|
|
10
|
+
const interactionRootNode = new InteractionNode(interaction, null, 'interaction', faker.date.past().getUTCSeconds())
|
|
11
|
+
const interactionNode = interactionRootNode.child('test', faker.date.past().getUTCSeconds(), 'test', false)
|
|
12
|
+
|
|
13
|
+
interactionRootNode.cancel()
|
|
14
|
+
interactionNode.finish()
|
|
15
|
+
|
|
16
|
+
expect(interactionRootNode.children.length).toEqual(0)
|
|
17
|
+
})
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { getInfo, getRuntime, originals } from '../../../common/config/config'
|
|
7
|
+
import { mapOwn } from '../../../common/util/map-own'
|
|
8
|
+
import { ee } from '../../../common/event-emitter/contextual-ee'
|
|
9
|
+
import { InteractionNode } from './interaction-node'
|
|
10
|
+
import { now } from '../../../common/timing/now'
|
|
11
|
+
|
|
12
|
+
var originalSetTimeout = originals.ST
|
|
13
|
+
var originalClearTimeout = originals.CT
|
|
14
|
+
|
|
15
|
+
var lastId = {}
|
|
16
|
+
|
|
17
|
+
export function Interaction (eventName, timestamp, url, routeName, onFinished, agentIdentifier) {
|
|
18
|
+
this.agentIdentifier = agentIdentifier
|
|
19
|
+
this.ee = ee.get(agentIdentifier)
|
|
20
|
+
|
|
21
|
+
lastId[agentIdentifier] = 0
|
|
22
|
+
this.id = ++lastId[agentIdentifier]
|
|
23
|
+
this.eventName = eventName
|
|
24
|
+
this.nodes = 0
|
|
25
|
+
this.remaining = 0
|
|
26
|
+
this.finishTimer = null
|
|
27
|
+
this.checkingFinish = false
|
|
28
|
+
this.lastCb = this.lastFinish = timestamp
|
|
29
|
+
this.handlers = []
|
|
30
|
+
this.onFinished = onFinished
|
|
31
|
+
this.done = false
|
|
32
|
+
|
|
33
|
+
var root = this.root = new InteractionNode(this, null, 'interaction', timestamp)
|
|
34
|
+
var attrs = root.attrs
|
|
35
|
+
|
|
36
|
+
attrs.trigger = eventName
|
|
37
|
+
attrs.initialPageURL = getRuntime(agentIdentifier).origin
|
|
38
|
+
attrs.oldRoute = routeName
|
|
39
|
+
attrs.newURL = attrs.oldURL = url
|
|
40
|
+
attrs.custom = {}
|
|
41
|
+
attrs.store = {}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var InteractionPrototype = Interaction.prototype
|
|
45
|
+
|
|
46
|
+
InteractionPrototype.checkFinish = function checkFinish () {
|
|
47
|
+
var interaction = this
|
|
48
|
+
|
|
49
|
+
if (interaction.remaining > 0) {
|
|
50
|
+
interaction._resetFinishCheck()
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (interaction.checkingFinish) {
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (interaction.root.end !== null) return
|
|
59
|
+
|
|
60
|
+
interaction._resetFinishCheck()
|
|
61
|
+
|
|
62
|
+
interaction.checkingFinish = true
|
|
63
|
+
interaction.finishTimer = originalSetTimeout(() => {
|
|
64
|
+
interaction.checkingFinish = false
|
|
65
|
+
interaction.finishTimer = originalSetTimeout(() => {
|
|
66
|
+
interaction.finishTimer = null
|
|
67
|
+
if (interaction.remaining <= 0) interaction.finish()
|
|
68
|
+
}, 1)
|
|
69
|
+
}, 0)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
InteractionPrototype.setNewURL = function setNewURL (url) {
|
|
73
|
+
this.root.attrs.newURL = url
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
InteractionPrototype.setNewRoute = function setNewRoute (route) {
|
|
77
|
+
this.root.attrs.newRoute = route
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
InteractionPrototype.onNodeAdded = function onNodeAdded () {
|
|
81
|
+
this._resetFinishCheck()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
InteractionPrototype._resetFinishCheck = function _resetFinishCheck () {
|
|
85
|
+
if (this.finishTimer) {
|
|
86
|
+
originalClearTimeout(this.finishTimer)
|
|
87
|
+
this.finishTimer = null
|
|
88
|
+
this.checkingFinish = false
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// serialize report and remove nodes from map
|
|
93
|
+
InteractionPrototype.finish = function finishInteraction () {
|
|
94
|
+
var interaction = this
|
|
95
|
+
var root = interaction.root
|
|
96
|
+
if (root.end !== null) return
|
|
97
|
+
var endTimestamp = Math.max(interaction.lastCb, interaction.lastFinish)
|
|
98
|
+
var delta = now() - endTimestamp
|
|
99
|
+
var attrs = root.attrs
|
|
100
|
+
var customAttrs = attrs.custom
|
|
101
|
+
|
|
102
|
+
if (this.onFinished) {
|
|
103
|
+
this.onFinished(this)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
mapOwn(getInfo(interaction.agentIdentifier).jsAttributes, function (attr, value) {
|
|
107
|
+
if (!(attr in customAttrs)) customAttrs[attr] = value
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
root.end = endTimestamp
|
|
111
|
+
interaction.ee.emit('interaction', [this])
|
|
112
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { cleanURL } from '../../../common/url/clean-url'
|
|
6
|
+
import { mapOwn } from '../../../common/util/map-own'
|
|
7
|
+
import { nullable, numeric, getAddStringContext, addCustomAttributes } from '../../../common/serialize/bel-serializer'
|
|
8
|
+
import { SharedContext } from '../../../common/context/shared-context'
|
|
9
|
+
import { getInfo } from '../../../common/config/config'
|
|
10
|
+
|
|
11
|
+
export class Serializer extends SharedContext {
|
|
12
|
+
constructor (parent) {
|
|
13
|
+
super(parent)
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* This variable is used to calculate an interactions ending offset when the
|
|
17
|
+
* harvest includes multiple interactions. This variable is set by the first
|
|
18
|
+
* interaction processed and used by subsequent interactions in the same harvest.
|
|
19
|
+
* See https://issues.newrelic.com/browse/NEWRELIC-5498
|
|
20
|
+
* @type {number|undefined}
|
|
21
|
+
*/
|
|
22
|
+
this.firstTimestamp = undefined
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
serializeMultiple (interactions, offset, navTiming) {
|
|
26
|
+
const info = getInfo(this.sharedContext.agentIdentifier)
|
|
27
|
+
var addString = getAddStringContext(this.sharedContext.agentIdentifier)
|
|
28
|
+
var serialized = 'bel.7'
|
|
29
|
+
interactions.forEach((interaction) => {
|
|
30
|
+
serialized += ';' + this.serializeInteraction(interaction.root, offset, navTiming, interaction.routeChange, addString, info)
|
|
31
|
+
})
|
|
32
|
+
this.firstTimestamp = undefined
|
|
33
|
+
return serialized
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
serializeSingle (root, offset, navTiming, isRouteChange) {
|
|
37
|
+
const info = getInfo(this.sharedContext.agentIdentifier)
|
|
38
|
+
var addString = getAddStringContext(this.sharedContext.agentIdentifier)
|
|
39
|
+
var serialized = 'bel.7;' + this.serializeInteraction(root, offset, navTiming, isRouteChange, addString, info)
|
|
40
|
+
this.firstTimestamp = undefined
|
|
41
|
+
return serialized
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
serializeInteraction (root, offset, navTiming, isRouteChange, addString, info) {
|
|
45
|
+
offset = offset || 0
|
|
46
|
+
var isInitialPage = root.attrs.trigger === 'initialPageLoad'
|
|
47
|
+
var typeIdsByName = {
|
|
48
|
+
interaction: 1,
|
|
49
|
+
ajax: 2,
|
|
50
|
+
customTracer: 4
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Include the hash fragment with all SPA data
|
|
54
|
+
var includeHashFragment = true
|
|
55
|
+
|
|
56
|
+
const addNode = (node, nodeList) => {
|
|
57
|
+
if (node.type === 'customEnd') return nodeList.push([3, numeric(node.end - this.firstTimestamp)])
|
|
58
|
+
var typeName = node.type
|
|
59
|
+
var typeId = typeIdsByName[typeName]
|
|
60
|
+
var startTimestamp = node.start
|
|
61
|
+
var childCount = node.children.length
|
|
62
|
+
var attrCount = 0
|
|
63
|
+
var apmAttributes = info.atts
|
|
64
|
+
var hasNavTiming = isInitialPage && navTiming.length && typeId === 1
|
|
65
|
+
var children = []
|
|
66
|
+
var attrs = node.attrs
|
|
67
|
+
var metrics = attrs.metrics
|
|
68
|
+
var params = attrs.params
|
|
69
|
+
var queueTime = info.queueTime
|
|
70
|
+
var appTime = info.applicationTime
|
|
71
|
+
|
|
72
|
+
if (typeof this.firstTimestamp === 'undefined') {
|
|
73
|
+
startTimestamp += offset
|
|
74
|
+
this.firstTimestamp = startTimestamp
|
|
75
|
+
} else {
|
|
76
|
+
startTimestamp -= this.firstTimestamp
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var fields = [
|
|
80
|
+
numeric(startTimestamp),
|
|
81
|
+
numeric(node.end - node.start),
|
|
82
|
+
numeric(node.jsEnd - node.end),
|
|
83
|
+
numeric(node.jsTime)
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
switch (typeId) {
|
|
87
|
+
case 1:
|
|
88
|
+
fields[2] = numeric(node.jsEnd - this.firstTimestamp)
|
|
89
|
+
fields.push(
|
|
90
|
+
addString(attrs.trigger),
|
|
91
|
+
addString(cleanURL(attrs.initialPageURL, includeHashFragment)),
|
|
92
|
+
addString(cleanURL(attrs.oldURL, includeHashFragment)),
|
|
93
|
+
addString(cleanURL(attrs.newURL, includeHashFragment)),
|
|
94
|
+
addString(attrs.customName),
|
|
95
|
+
isInitialPage ? '' : isRouteChange ? 1 : 2,
|
|
96
|
+
nullable(isInitialPage && queueTime, numeric, true) +
|
|
97
|
+
nullable(isInitialPage && appTime, numeric, true) +
|
|
98
|
+
nullable(attrs.oldRoute, addString, true) +
|
|
99
|
+
nullable(attrs.newRoute, addString, true) +
|
|
100
|
+
addString(attrs.id),
|
|
101
|
+
addString(node.id),
|
|
102
|
+
nullable(attrs.firstPaint, numeric, true) +
|
|
103
|
+
nullable(attrs.firstContentfulPaint, numeric, false)
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
var attrParts = addCustomAttributes(attrs.custom, addString)
|
|
107
|
+
children = children.concat(attrParts)
|
|
108
|
+
attrCount = attrParts.length
|
|
109
|
+
|
|
110
|
+
if (apmAttributes) {
|
|
111
|
+
childCount++
|
|
112
|
+
children.push('a,' + addString(apmAttributes))
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
break
|
|
116
|
+
|
|
117
|
+
case 2:
|
|
118
|
+
fields.push(
|
|
119
|
+
addString(params.method),
|
|
120
|
+
numeric(params.status),
|
|
121
|
+
addString(params.host),
|
|
122
|
+
addString(params.pathname),
|
|
123
|
+
numeric(metrics.txSize),
|
|
124
|
+
numeric(metrics.rxSize),
|
|
125
|
+
attrs.isFetch ? 1 : (attrs.isJSONP ? 2 : ''),
|
|
126
|
+
addString(node.id),
|
|
127
|
+
nullable(node.dt && node.dt.spanId, addString, true) +
|
|
128
|
+
nullable(node.dt && node.dt.traceId, addString, true) +
|
|
129
|
+
nullable(node.dt && node.dt.timestamp, numeric, false)
|
|
130
|
+
)
|
|
131
|
+
break
|
|
132
|
+
|
|
133
|
+
case 4:
|
|
134
|
+
var tracedTime = attrs.tracedTime
|
|
135
|
+
fields.push(
|
|
136
|
+
addString(attrs.name),
|
|
137
|
+
nullable(tracedTime, numeric, true) +
|
|
138
|
+
addString(node.id)
|
|
139
|
+
)
|
|
140
|
+
break
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
for (var i = 0; i < node.children.length; i++) {
|
|
144
|
+
addNode(node.children[i], children)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
fields.unshift(
|
|
148
|
+
numeric(typeId),
|
|
149
|
+
numeric(childCount += attrCount)
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
nodeList.push(fields)
|
|
153
|
+
|
|
154
|
+
if (childCount) {
|
|
155
|
+
nodeList.push(children.join(';'))
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (hasNavTiming) {
|
|
159
|
+
// this build up the navTiming node
|
|
160
|
+
// it for each navTiming value (pre aggregated in nav-timing.js):
|
|
161
|
+
// we initialize the seperator to ',' (seperates the nodeType id from the first value)
|
|
162
|
+
// we initialize the navTiming node to 'b' (the nodeType id)
|
|
163
|
+
// if the value is present:
|
|
164
|
+
// we add the seperator followed by the value
|
|
165
|
+
// otherwise
|
|
166
|
+
// we add null seperator ('!') to the navTimingNode
|
|
167
|
+
// we set the seperator to an empty string since we already wrote it above
|
|
168
|
+
// the reason for writing the null seperator instead of setting the seperator
|
|
169
|
+
// is to ensure we still write it if the null is the last navTiming value.
|
|
170
|
+
|
|
171
|
+
var seperator = ','
|
|
172
|
+
var navTimingNode = 'b'
|
|
173
|
+
var prev = 0
|
|
174
|
+
|
|
175
|
+
// get all navTiming values except navigationStart
|
|
176
|
+
// (since its the same as interaction.start)
|
|
177
|
+
// and limit to just the first 20 values we know about
|
|
178
|
+
mapOwn(navTiming.slice(1, 21), function (i, v) {
|
|
179
|
+
if (v !== void 0) {
|
|
180
|
+
navTimingNode += seperator + numeric(v - prev)
|
|
181
|
+
seperator = ','
|
|
182
|
+
prev = v
|
|
183
|
+
} else {
|
|
184
|
+
navTimingNode += seperator + '!'
|
|
185
|
+
seperator = ''
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
nodeList.push(navTimingNode)
|
|
189
|
+
} else if (typeId === 1) {
|
|
190
|
+
nodeList.push('')
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return nodeList
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return addNode(root, []).join(';')
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { originals } from '../../common/config/config'
|
|
2
|
+
import { globalScope } from '../../common/util/global-scope'
|
|
3
|
+
import { FEATURE_NAMES } from '../../loaders/features/features'
|
|
4
|
+
|
|
5
|
+
export const FEATURE_NAME = FEATURE_NAMES.spa
|
|
6
|
+
export const INTERACTION_EVENTS = [
|
|
7
|
+
'click',
|
|
8
|
+
'submit',
|
|
9
|
+
'keypress',
|
|
10
|
+
'keydown',
|
|
11
|
+
'keyup',
|
|
12
|
+
'change'
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
export const MAX_TIMER_BUDGET = 999
|
|
16
|
+
export const FN_START = 'fn-start'
|
|
17
|
+
export const FN_END = 'fn-end'
|
|
18
|
+
export const CB_START = 'cb-start'
|
|
19
|
+
export const INTERACTION_API = 'api-ixn-'
|
|
20
|
+
export const REMAINING = 'remaining'
|
|
21
|
+
export const INTERACTION = 'interaction'
|
|
22
|
+
export const SPA_NODE = 'spaNode'
|
|
23
|
+
export const JSONP_NODE = 'jsonpNode'
|
|
24
|
+
export const FETCH_START = 'fetch-start'
|
|
25
|
+
export const FETCH_DONE = 'fetch-done'
|
|
26
|
+
export const FETCH_BODY = 'fetch-body-'
|
|
27
|
+
export const JSONP_END = 'jsonp-end'
|
|
28
|
+
|
|
29
|
+
export const originalSetTimeout = originals.ST
|
|
30
|
+
|
|
31
|
+
export const START = '-start'
|
|
32
|
+
export const END = '-end'
|
|
33
|
+
export const BODY = '-body'
|
|
34
|
+
export const CB_END = 'cb' + END
|
|
35
|
+
export const JS_TIME = 'jsTime'
|
|
36
|
+
export const FETCH = 'fetch'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Instrument as Spa } from './instrument/index'
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import {
|
|
6
|
+
wrapMutation, wrapPromise, wrapHistory, wrapTimer, wrapFetch, wrapXhr, wrapJsonP
|
|
7
|
+
} from '../../../common/wrap'
|
|
8
|
+
import { eventListenerOpts } from '../../../common/event-listener/event-listener-opts'
|
|
9
|
+
import { InstrumentBase } from '../../utils/instrument-base'
|
|
10
|
+
import { getRuntime } from '../../../common/config/config'
|
|
11
|
+
import { now } from '../../../common/timing/now'
|
|
12
|
+
import * as CONSTANTS from '../constants'
|
|
13
|
+
import { isBrowserScope } from '../../../common/util/global-scope'
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
FEATURE_NAME, START, END, BODY, CB_END, JS_TIME, FETCH, FN_START, CB_START, FN_END
|
|
17
|
+
} = CONSTANTS
|
|
18
|
+
|
|
19
|
+
export class Instrument extends InstrumentBase {
|
|
20
|
+
static featureName = FEATURE_NAME
|
|
21
|
+
constructor (agentIdentifier, aggregator, auto = true) {
|
|
22
|
+
super(agentIdentifier, aggregator, FEATURE_NAME, auto)
|
|
23
|
+
if (!isBrowserScope) return // SPA not supported outside web env
|
|
24
|
+
|
|
25
|
+
if (!getRuntime(agentIdentifier).xhrWrappable) return
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
this.removeOnAbort = new AbortController()
|
|
29
|
+
} catch (e) {}
|
|
30
|
+
|
|
31
|
+
let depth = 0
|
|
32
|
+
let startHash
|
|
33
|
+
|
|
34
|
+
const tracerEE = this.ee.get('tracer')
|
|
35
|
+
const jsonpEE = wrapJsonP(this.ee)
|
|
36
|
+
const promiseEE = wrapPromise(this.ee)
|
|
37
|
+
const timerEE = wrapTimer(this.ee)
|
|
38
|
+
const xhrEE = wrapXhr(this.ee)
|
|
39
|
+
const eventsEE = this.ee.get('events') // wrapXhr will call wrapEvents
|
|
40
|
+
const fetchEE = wrapFetch(this.ee)
|
|
41
|
+
const historyEE = wrapHistory(this.ee)
|
|
42
|
+
const mutationEE = wrapMutation(this.ee)
|
|
43
|
+
|
|
44
|
+
this.ee.on(FN_START, startTimestamp)
|
|
45
|
+
promiseEE.on(CB_START, startTimestamp)
|
|
46
|
+
jsonpEE.on(CB_START, startTimestamp)
|
|
47
|
+
|
|
48
|
+
this.ee.on(FN_END, endTimestamp)
|
|
49
|
+
promiseEE.on(CB_END, endTimestamp)
|
|
50
|
+
jsonpEE.on(CB_END, endTimestamp)
|
|
51
|
+
|
|
52
|
+
this.ee.buffer([FN_START, FN_END, 'xhr-resolved'], this.featureName)
|
|
53
|
+
eventsEE.buffer([FN_START], this.featureName)
|
|
54
|
+
timerEE.buffer(['setTimeout' + END, 'clearTimeout' + START, FN_START], this.featureName)
|
|
55
|
+
xhrEE.buffer([FN_START, 'new-xhr', 'send-xhr' + START], this.featureName)
|
|
56
|
+
fetchEE.buffer([FETCH + START, FETCH + '-done', FETCH + BODY + START, FETCH + BODY + END], this.featureName)
|
|
57
|
+
historyEE.buffer(['newURL'], this.featureName)
|
|
58
|
+
mutationEE.buffer([FN_START], this.featureName)
|
|
59
|
+
promiseEE.buffer(['propagate', CB_START, CB_END, 'executor-err', 'resolve' + START], this.featureName)
|
|
60
|
+
tracerEE.buffer([FN_START, 'no-' + FN_START], this.featureName)
|
|
61
|
+
jsonpEE.buffer(['new-jsonp', 'cb-start', 'jsonp-error', 'jsonp-end'], this.featureName)
|
|
62
|
+
|
|
63
|
+
timestamp(fetchEE, FETCH + START)
|
|
64
|
+
timestamp(fetchEE, FETCH + '-done')
|
|
65
|
+
timestamp(jsonpEE, 'new-jsonp')
|
|
66
|
+
timestamp(jsonpEE, 'jsonp-end')
|
|
67
|
+
timestamp(jsonpEE, 'cb-start')
|
|
68
|
+
|
|
69
|
+
historyEE.on('pushState-end', trackURLChange)
|
|
70
|
+
historyEE.on('replaceState-end', trackURLChange)
|
|
71
|
+
|
|
72
|
+
window.addEventListener('hashchange', trackURLChange, eventListenerOpts(true, this.removeOnAbort?.signal))
|
|
73
|
+
window.addEventListener('load', trackURLChange, eventListenerOpts(true, this.removeOnAbort?.signal))
|
|
74
|
+
window.addEventListener('popstate', function () {
|
|
75
|
+
trackURLChange(0, depth > 1)
|
|
76
|
+
}, eventListenerOpts(true, this.removeOnAbort?.signal))
|
|
77
|
+
|
|
78
|
+
function trackURLChange (unusedArgs, hashChangedDuringCb) {
|
|
79
|
+
historyEE.emit('newURL', ['' + window.location, hashChangedDuringCb])
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function startTimestamp () {
|
|
83
|
+
depth++
|
|
84
|
+
startHash = window.location.hash
|
|
85
|
+
this[FN_START] = now()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function endTimestamp () {
|
|
89
|
+
depth--
|
|
90
|
+
if (window.location.hash !== startHash) {
|
|
91
|
+
trackURLChange(0, true)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
var time = now()
|
|
95
|
+
this[JS_TIME] = (~~this[JS_TIME]) + time - this[FN_START]
|
|
96
|
+
this[FN_END] = time
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function timestamp (ee, type) {
|
|
100
|
+
ee.on(type, function () {
|
|
101
|
+
this[type] = now()
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
this.abortHandler = this.#abort
|
|
106
|
+
this.importAggregator()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Restoration and resource release tasks to be done if SPA loader is being aborted. Unwind changes to globals and subscription to DOM events. */
|
|
110
|
+
#abort () {
|
|
111
|
+
this.removeOnAbort?.abort()
|
|
112
|
+
this.abortHandler = undefined // weakly allow this abort op to run only once
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { getInfo, isConfigured, getRuntime } from '../../common/config/config'
|
|
2
|
+
import { ee } from '../../common/event-emitter/contextual-ee'
|
|
3
|
+
import { configure } from '../../loaders/configure/configure'
|
|
4
|
+
import { gosCDN } from '../../common/window/nreum'
|
|
5
|
+
|
|
6
|
+
export class FeatureBase {
|
|
7
|
+
constructor (agentIdentifier, aggregator, featureName) {
|
|
8
|
+
/** @type {string} */
|
|
9
|
+
this.agentIdentifier = agentIdentifier
|
|
10
|
+
/** @type {Aggregator} */
|
|
11
|
+
this.aggregator = aggregator
|
|
12
|
+
/** @type {ContextualEE} */
|
|
13
|
+
this.ee = ee.get(agentIdentifier, getRuntime(this.agentIdentifier).isolatedBacklog)
|
|
14
|
+
/** @type {string} */
|
|
15
|
+
this.featureName = featureName
|
|
16
|
+
/**
|
|
17
|
+
* Blocked can be used to prevent aggregation and harvest after inititalization time of the feature.
|
|
18
|
+
* This can currently happen if RUM response setToken flag is 0, which is tied to ingest account entitlement info.
|
|
19
|
+
* @type {boolean}
|
|
20
|
+
*/
|
|
21
|
+
this.blocked = false
|
|
22
|
+
|
|
23
|
+
this.checkConfiguration()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Checks for additional `jsAttributes` items to support backward compatibility with implementations of the agent where
|
|
28
|
+
* loader configurations may appear after the loader code is executed.
|
|
29
|
+
*/
|
|
30
|
+
checkConfiguration () {
|
|
31
|
+
// NOTE: This check has to happen at aggregator load time, but could be moved to `AggregateBase`.
|
|
32
|
+
if (!isConfigured(this.agentIdentifier)) {
|
|
33
|
+
let jsAttributes = { ...gosCDN().info?.jsAttributes }
|
|
34
|
+
try {
|
|
35
|
+
jsAttributes = {
|
|
36
|
+
...jsAttributes,
|
|
37
|
+
...getInfo(this.agentIdentifier)?.jsAttributes
|
|
38
|
+
}
|
|
39
|
+
} catch (err) {
|
|
40
|
+
// do nothing
|
|
41
|
+
}
|
|
42
|
+
configure(this.agentIdentifier, {
|
|
43
|
+
...gosCDN(),
|
|
44
|
+
info: {
|
|
45
|
+
...gosCDN().info,
|
|
46
|
+
jsAttributes
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* A class to defer callback execution until a decision can be reached
|
|
4
|
+
*/
|
|
5
|
+
export class HandlerCache {
|
|
6
|
+
/** @private @type {boolean | undefined} */
|
|
7
|
+
#decision = undefined
|
|
8
|
+
/** @private @type {boolean} */
|
|
9
|
+
#shouldsettle = true
|
|
10
|
+
/** @private @type {Function[]} */
|
|
11
|
+
#cache = []
|
|
12
|
+
/** @private @type {Timeout} */
|
|
13
|
+
#settleTimer = setTimeout(() => this.#close(), 5000)
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* tell the handlerCache that its ok to immediately execute the callbacks that are triggered by the ee from this moment on
|
|
17
|
+
* and execute all the storage callbacks saved up in the handlerCache
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
#drain () {
|
|
21
|
+
this.#cache.forEach(h => h())
|
|
22
|
+
this.#cache = []
|
|
23
|
+
clearTimeout(this.#settleTimer)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* tell the handlerCache not to execute any of the storage callbacks
|
|
28
|
+
* and wipe out all the storage callbacks saved up in the handlerCache
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
#close () {
|
|
32
|
+
this.#shouldsettle = false
|
|
33
|
+
this.#cache = []
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Wrap callback functions with this method to defer their execution until a decision has been reached
|
|
38
|
+
* @param {Function} handler
|
|
39
|
+
* @returns {void}
|
|
40
|
+
*/
|
|
41
|
+
settle (handler) {
|
|
42
|
+
if (this.#decision === false || this.#shouldsettle === false) return
|
|
43
|
+
else if (this.#decision === undefined) this.#cache.push(handler)
|
|
44
|
+
else handler()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Make a decision about what to do with the cache of callbacks.
|
|
49
|
+
* --- if true: tell the handlerCache that its ok to immediately execute the callbacks that are triggered by the ee from this moment on
|
|
50
|
+
* and execute all the storage callbacks saved up in the handlerCache ---
|
|
51
|
+
* --- if false: tell the handlerCache not to execute any of the storage callbacks
|
|
52
|
+
* and wipe out all the storage callbacks saved up in the handlerCache
|
|
53
|
+
* @param {boolean} decision
|
|
54
|
+
*/
|
|
55
|
+
decide (decision) {
|
|
56
|
+
this.#decision = decision
|
|
57
|
+
if (decision === false) this.#close()
|
|
58
|
+
if (decision === true) this.#drain()
|
|
59
|
+
}
|
|
60
|
+
}
|