@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.
- package/README.md +27 -3
- package/dist/cjs/common/browser-version/ios-version.js +4 -3
- package/dist/cjs/common/config/state/configurable.js +27 -21
- package/dist/cjs/common/config/state/info.js +1 -1
- package/dist/cjs/common/config/state/init.js +9 -1
- package/dist/cjs/common/config/state/loader-config.js +1 -1
- package/dist/cjs/common/config/state/runtime.js +26 -28
- 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/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 +14 -11
- package/dist/cjs/common/harvest/harvest.js +5 -3
- 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/session/constants.js +12 -0
- package/dist/cjs/common/session/session-entity.js +278 -0
- package/dist/cjs/common/session/session-entity.test.js +436 -0
- package/dist/cjs/common/storage/first-party-cookies.js +35 -0
- package/dist/cjs/common/storage/local-memory.js +35 -0
- package/dist/cjs/common/storage/local-memory.test.js +20 -0
- package/dist/cjs/common/storage/local-storage.js +33 -0
- package/dist/cjs/common/storage/local-storage.test.js +14 -0
- package/dist/cjs/common/timer/interaction-timer.js +78 -0
- package/dist/cjs/common/timer/interaction-timer.test.js +216 -0
- package/dist/cjs/common/timer/timer.js +32 -0
- package/dist/cjs/common/timer/timer.test.js +105 -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/unload/eol.js +2 -2
- 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 +1 -1
- package/dist/cjs/common/util/data-size.js +6 -0
- package/dist/cjs/common/util/data-size.test.js +47 -0
- package/dist/cjs/common/util/invoke.js +73 -0
- package/dist/cjs/common/util/invoke.test.js +49 -0
- package/dist/cjs/common/util/map-own.test.js +3 -3
- package/dist/cjs/common/util/obfuscate.js +1 -5
- package/dist/cjs/common/window/page-visibility.js +5 -2
- package/dist/cjs/common/wrap/index.js +0 -7
- package/dist/cjs/common/wrap/wrap-events.js +6 -9
- package/dist/cjs/common/wrap/wrap-fetch.js +6 -6
- 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 +7 -6
- 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 +7 -7
- package/dist/cjs/common/wrap/wrap-xhr.js +5 -6
- package/dist/cjs/features/ajax/aggregate/index.js +3 -3
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
- package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +1 -1
- package/dist/cjs/features/jserrors/aggregate/index.js +6 -6
- package/dist/cjs/features/jserrors/instrument/index.js +2 -2
- package/dist/cjs/features/metrics/aggregate/index.js +19 -9
- package/dist/cjs/features/metrics/instrument/index.js +0 -25
- package/dist/cjs/features/metrics/instrument/workers-helper.js +5 -5
- package/dist/cjs/features/page_action/aggregate/index.js +3 -3
- package/dist/cjs/features/page_view_event/aggregate/index.js +23 -9
- package/dist/cjs/features/page_view_timing/aggregate/index.js +40 -30
- package/dist/cjs/features/session_trace/aggregate/index.js +18 -15
- package/dist/cjs/features/spa/aggregate/index.js +6 -5
- package/dist/cjs/features/utils/agent-session.js +73 -0
- package/dist/cjs/features/utils/feature-base.js +1 -1
- package/dist/cjs/features/utils/instrument-base.js +12 -3
- package/dist/cjs/features/utils/lazy-loader.js +2 -2
- package/dist/cjs/loaders/agent.js +2 -2
- package/dist/cjs/loaders/api/api.js +9 -9
- package/dist/cjs/loaders/api/apiAsync.js +3 -2
- package/dist/cjs/loaders/configure/configure.js +0 -6
- package/dist/cjs/loaders/features/enabled-features.js +1 -1
- package/dist/cjs/loaders/micro-agent.js +2 -1
- package/dist/esm/common/browser-version/ios-version.js +4 -3
- package/dist/esm/common/config/state/configurable.js +26 -20
- package/dist/esm/common/config/state/info.js +1 -1
- package/dist/esm/common/config/state/init.js +9 -1
- package/dist/esm/common/config/state/loader-config.js +1 -1
- package/dist/esm/common/config/state/runtime.js +26 -28
- 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/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 +14 -11
- package/dist/esm/common/harvest/harvest.js +4 -2
- 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/session/constants.js +3 -0
- package/dist/esm/common/session/session-entity.js +271 -0
- package/dist/esm/common/session/session-entity.test.js +434 -0
- package/dist/esm/common/storage/first-party-cookies.js +28 -0
- package/dist/esm/common/storage/local-memory.js +28 -0
- package/dist/esm/common/storage/local-memory.test.js +18 -0
- package/dist/esm/common/storage/local-storage.js +26 -0
- package/dist/esm/common/storage/local-storage.test.js +12 -0
- package/dist/esm/common/timer/interaction-timer.js +71 -0
- package/dist/esm/common/timer/interaction-timer.test.js +214 -0
- package/dist/esm/common/timer/timer.js +25 -0
- package/dist/esm/common/timer/timer.test.js +103 -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/unload/eol.js +1 -1
- 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 +1 -1
- package/dist/esm/common/util/data-size.js +7 -0
- package/dist/esm/common/util/data-size.test.js +45 -0
- package/dist/esm/common/util/invoke.js +66 -0
- package/dist/esm/common/util/invoke.test.js +47 -0
- package/dist/esm/common/util/map-own.test.js +3 -3
- package/dist/esm/common/util/obfuscate.js +2 -6
- package/dist/esm/common/window/page-visibility.js +5 -2
- package/dist/esm/common/wrap/index.js +1 -2
- package/dist/esm/common/wrap/wrap-events.js +6 -9
- package/dist/esm/common/wrap/wrap-fetch.js +6 -6
- package/dist/esm/common/wrap/wrap-history.js +7 -6
- package/dist/esm/common/wrap/wrap-jsonp.js +7 -6
- package/dist/esm/common/wrap/wrap-mutation.js +7 -6
- package/dist/esm/common/wrap/wrap-promise.js +7 -6
- package/dist/esm/common/wrap/wrap-promise.test.js +115 -0
- package/dist/esm/common/wrap/wrap-raf.js +6 -6
- package/dist/esm/common/wrap/wrap-timer.js +7 -7
- package/dist/esm/common/wrap/wrap-xhr.js +5 -6
- package/dist/esm/features/ajax/aggregate/index.js +3 -3
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
- package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +1 -1
- package/dist/esm/features/jserrors/aggregate/index.js +6 -6
- package/dist/esm/features/jserrors/instrument/index.js +2 -2
- package/dist/esm/features/metrics/aggregate/index.js +21 -11
- package/dist/esm/features/metrics/instrument/index.js +0 -25
- package/dist/esm/features/metrics/instrument/workers-helper.js +5 -5
- package/dist/esm/features/page_action/aggregate/index.js +3 -3
- package/dist/esm/features/page_view_event/aggregate/index.js +23 -9
- package/dist/esm/features/page_view_timing/aggregate/index.js +40 -30
- package/dist/esm/features/session_trace/aggregate/index.js +18 -15
- package/dist/esm/features/spa/aggregate/index.js +6 -5
- package/dist/esm/features/utils/agent-session.js +67 -0
- package/dist/esm/features/utils/feature-base.js +1 -1
- package/dist/esm/features/utils/instrument-base.js +7 -2
- package/dist/esm/features/utils/lazy-loader.js +2 -2
- package/dist/esm/loaders/agent.js +2 -2
- package/dist/esm/loaders/api/api.js +6 -9
- package/dist/esm/loaders/api/apiAsync.js +2 -1
- package/dist/esm/loaders/configure/configure.js +2 -8
- package/dist/esm/loaders/features/enabled-features.js +1 -1
- package/dist/types/common/config/state/configurable.d.ts.map +1 -1
- package/dist/types/common/config/state/init.d.ts.map +1 -1
- package/dist/types/common/config/state/runtime.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/types/common/event-listener/event-listener-opts.d.ts +2 -2
- package/dist/types/common/event-listener/event-listener-opts.d.ts.map +1 -1
- package/dist/types/common/harvest/harvest-scheduler.d.ts +1 -0
- package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
- package/dist/types/common/harvest/harvest.d.ts.map +1 -1
- package/dist/types/common/ids/id.d.ts +11 -1
- package/dist/types/common/ids/id.d.ts.map +1 -1
- package/dist/types/common/ids/unique-id.d.ts +24 -1
- package/dist/types/common/ids/unique-id.d.ts.map +1 -1
- package/dist/types/common/session/constants.d.ts +4 -0
- package/dist/types/common/session/constants.d.ts.map +1 -0
- package/dist/types/common/session/session-entity.d.ts +72 -0
- package/dist/types/common/session/session-entity.d.ts.map +1 -0
- package/dist/types/common/storage/first-party-cookies.d.ts +8 -0
- package/dist/types/common/storage/first-party-cookies.d.ts.map +1 -0
- package/dist/types/common/storage/local-memory.d.ts +8 -0
- package/dist/types/common/storage/local-memory.d.ts.map +1 -0
- package/dist/types/common/storage/local-storage.d.ts +6 -0
- package/dist/types/common/storage/local-storage.d.ts.map +1 -0
- package/dist/types/common/timer/interaction-timer.d.ts +11 -0
- package/dist/types/common/timer/interaction-timer.d.ts.map +1 -0
- package/dist/types/common/timer/timer.d.ts +12 -0
- package/dist/types/common/timer/timer.d.ts.map +1 -0
- package/dist/types/common/timing/nav-timing.d.ts +1 -2
- package/dist/types/common/timing/nav-timing.d.ts.map +1 -1
- package/dist/types/common/unload/eol.d.ts.map +1 -1
- package/dist/types/common/url/location.d.ts +4 -0
- package/dist/types/common/url/location.d.ts.map +1 -1
- package/dist/types/common/url/parse-url.d.ts.map +1 -1
- package/dist/types/common/url/protocol.d.ts +1 -6
- package/dist/types/common/url/protocol.d.ts.map +1 -1
- package/dist/types/common/util/data-size.d.ts +7 -1
- package/dist/types/common/util/data-size.d.ts.map +1 -1
- package/dist/types/common/util/global-scope.d.ts.map +1 -1
- package/dist/types/common/util/invoke.d.ts +35 -0
- package/dist/types/common/util/invoke.d.ts.map +1 -0
- package/dist/types/common/util/obfuscate.d.ts.map +1 -1
- package/dist/types/common/window/page-visibility.d.ts +1 -1
- package/dist/types/common/window/page-visibility.d.ts.map +1 -1
- package/dist/types/common/wrap/index.d.ts +1 -2
- package/dist/types/common/wrap/index.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-history.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-jsonp.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-mutation.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-raf.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-timer.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-xhr.d.ts.map +1 -1
- package/dist/types/features/ajax/aggregate/index.d.ts +2 -2
- package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts +2 -2
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
- package/dist/types/features/metrics/aggregate/index.d.ts +2 -2
- package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/metrics/instrument/index.d.ts +0 -1
- package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
- package/dist/types/features/metrics/instrument/workers-helper.d.ts.map +1 -1
- package/dist/types/features/page_action/aggregate/index.d.ts +2 -2
- package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_event/aggregate/index.d.ts +2 -2
- package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_timing/aggregate/index.d.ts +3 -4
- package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/aggregate/index.d.ts +3 -3
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
- package/dist/types/features/spa/aggregate/index.d.ts +2 -2
- package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
- package/dist/types/features/utils/agent-session.d.ts +2 -0
- package/dist/types/features/utils/agent-session.d.ts.map +1 -0
- package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
- package/dist/types/features/utils/lazy-loader.d.ts +2 -2
- package/dist/types/features/utils/lazy-loader.d.ts.map +1 -1
- package/dist/types/loaders/api/api.d.ts.map +1 -1
- package/dist/types/loaders/api/apiAsync.d.ts.map +1 -1
- package/dist/types/loaders/configure/configure.d.ts.map +1 -1
- package/package.json +12 -32
- package/src/common/browser-version/ios-version.js +4 -3
- package/src/common/config/state/configurable.js +26 -19
- package/src/common/config/state/init.js +7 -0
- package/src/common/config/state/runtime.js +7 -10
- 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 +2 -1
- package/src/common/event-emitter/contextual-ee.test.js +310 -0
- package/src/common/event-emitter/handle.test.js +56 -0
- package/src/common/event-emitter/register-handler.test.js +61 -0
- package/src/common/event-listener/event-listener-opts.js +4 -4
- package/src/common/harvest/harvest-scheduler.js +12 -8
- package/src/common/harvest/harvest.js +5 -3
- package/src/common/ids/id.js +15 -6
- package/src/common/ids/id.test.js +92 -0
- package/src/common/ids/unique-id.js +77 -54
- package/src/common/ids/unique-id.test.js +58 -0
- package/src/common/session/constants.js +3 -0
- package/src/common/session/session-entity.js +271 -0
- package/src/common/session/session-entity.test.js +317 -0
- package/src/common/storage/first-party-cookies.js +31 -0
- package/src/common/storage/local-memory.js +30 -0
- package/src/common/storage/local-memory.test.js +19 -0
- package/src/common/storage/local-storage.js +28 -0
- package/src/common/storage/local-storage.test.js +17 -0
- package/src/common/timer/interaction-timer.js +75 -0
- package/src/common/timer/interaction-timer.test.js +167 -0
- package/src/common/timer/timer.js +31 -0
- package/src/common/timer/timer.test.js +100 -0
- package/src/common/timing/nav-timing.js +50 -30
- package/src/common/timing/nav-timing.test.js +161 -0
- package/src/common/unload/eol.js +2 -3
- package/src/common/url/clean-url.test.js +25 -0
- package/src/common/url/encode.test.js +80 -0
- package/src/common/url/location.js +4 -0
- package/src/common/url/location.test.js +15 -0
- package/src/common/url/parse-url.js +1 -2
- package/src/common/url/parse-url.test.js +110 -0
- package/src/common/url/protocol.js +3 -13
- package/src/common/url/protocol.test.js +18 -0
- package/src/common/util/data-size.js +6 -0
- package/src/common/util/data-size.test.js +50 -0
- package/src/common/util/global-scope.js +1 -2
- package/src/common/util/invoke.js +55 -0
- package/src/common/util/invoke.test.js +65 -0
- package/src/common/util/obfuscate.js +2 -6
- package/src/common/window/page-visibility.js +3 -3
- package/src/common/wrap/index.js +1 -2
- package/src/common/wrap/wrap-events.js +5 -5
- package/src/common/wrap/wrap-fetch.js +4 -3
- package/src/common/wrap/wrap-history.js +6 -3
- package/src/common/wrap/wrap-jsonp.js +5 -3
- package/src/common/wrap/wrap-mutation.js +6 -3
- package/src/common/wrap/wrap-promise.js +7 -6
- package/src/common/wrap/wrap-promise.test.js +140 -0
- package/src/common/wrap/wrap-raf.js +5 -3
- package/src/common/wrap/wrap-timer.js +6 -4
- package/src/common/wrap/wrap-xhr.js +4 -3
- package/src/features/ajax/aggregate/index.js +2 -2
- package/src/features/ajax/instrument/index.js +1 -1
- package/src/features/jserrors/aggregate/index.js +3 -3
- package/src/features/jserrors/instrument/index.js +4 -2
- package/src/features/metrics/aggregate/index.js +21 -7
- package/src/features/metrics/instrument/index.js +0 -30
- package/src/features/metrics/instrument/workers-helper.js +9 -6
- package/src/features/page_action/aggregate/index.js +2 -2
- package/src/features/page_view_event/aggregate/index.js +21 -9
- package/src/features/page_view_timing/aggregate/index.js +40 -29
- package/src/features/page_view_timing/long-tasks.js +10 -10
- package/src/features/session_trace/aggregate/index.js +17 -14
- package/src/features/session_trace/instrument/index.js +3 -2
- package/src/features/spa/aggregate/index.js +5 -5
- package/src/features/spa/instrument/index.js +4 -2
- package/src/features/utils/agent-session.js +68 -0
- package/src/features/utils/feature-base.js +1 -1
- package/src/features/utils/instrument-base.js +5 -2
- package/src/features/utils/lazy-loader.js +1 -1
- package/src/loaders/agent.js +1 -1
- package/src/loaders/api/api.js +3 -6
- package/src/loaders/api/apiAsync.js +2 -1
- package/src/loaders/configure/configure.js +2 -7
- package/dist/cjs/common/constants/environment-variables.js +0 -20
- package/dist/cjs/common/util/single.js +0 -23
- package/dist/cjs/common/window/session-storage.js +0 -87
- package/dist/cjs/common/wrap/wrap-console.js +0 -54
- package/dist/cjs/features/utils/aggregate-base.js +0 -13
- package/dist/esm/common/constants/environment-variables.js +0 -11
- package/dist/esm/common/util/single.js +0 -16
- package/dist/esm/common/window/session-storage.js +0 -77
- package/dist/esm/common/wrap/wrap-console.js +0 -46
- package/dist/esm/features/utils/aggregate-base.js +0 -6
- package/dist/types/common/constants/environment-variables.d.ts +0 -4
- package/dist/types/common/constants/environment-variables.d.ts.map +0 -1
- package/dist/types/common/util/single.d.ts +0 -2
- package/dist/types/common/util/single.d.ts.map +0 -1
- package/dist/types/common/window/session-storage.d.ts +0 -18
- package/dist/types/common/window/session-storage.d.ts.map +0 -1
- package/dist/types/common/wrap/wrap-console.d.ts +0 -16
- package/dist/types/common/wrap/wrap-console.d.ts.map +0 -1
- package/dist/types/features/utils/aggregate-base.d.ts +0 -4
- package/dist/types/features/utils/aggregate-base.d.ts.map +0 -1
- package/src/common/constants/environment-variables.js +0 -11
- package/src/common/util/single.js +0 -18
- package/src/common/window/session-storage.js +0 -75
- package/src/common/wrap/wrap-console.js +0 -47
- package/src/features/utils/aggregate-base.js +0 -7
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
<a href="https://opensource.newrelic.com/oss-category/#community-plus"><picture><source media="(prefers-color-scheme: dark)" srcset="https://github.com/newrelic/opensource-website/raw/main/src/images/categories/dark/Community_Plus.png"><source media="(prefers-color-scheme: light)" srcset="https://github.com/newrelic/opensource-website/raw/main/src/images/categories/Community_Plus.png"><img alt="New Relic Open Source community plus project banner." src="https://github.com/newrelic/opensource-website/raw/main/src/images/categories/Community_Plus.png"></picture></a>
|
|
2
2
|
|
|
3
3
|
# New Relic Browser Agent
|
|
4
4
|
|
|
5
5
|
The New Relic browser agent instruments your web application or site and provides observability into performance, errors, and other behaviors.
|
|
6
6
|
|
|
7
|
-
- The instructions on this page pertain to installing the browser agent as an NPM package
|
|
7
|
+
- The instructions on this page pertain to installing the browser agent as an NPM package.
|
|
8
8
|
|
|
9
9
|
- The browser agent is also generally available as a copy-paste JavaScript snippet and via auto-injection by backend apps. See *[Install the browser agent](https://docs.newrelic.com/docs/browser/browser-monitoring/installation/install-browser-monitoring-agent/)* for info on these alternatives.
|
|
10
10
|
|
|
11
|
-
- For questions and feedback on this
|
|
11
|
+
- For questions and feedback on this package, please visit the [Explorer's Hub](https://forum.newrelic.com/s/), New Relic's community support forum.
|
|
12
12
|
|
|
13
13
|
- Looking to contribute to the browser agent code base? See [DEVELOPING.md](DEVELOPING.md) for instructions on building and testing the browser agent library, and [CONTRIBUTING.md](CONTRIBUTING.md) for general guidance.
|
|
14
14
|
|
|
@@ -170,6 +170,30 @@ import { Agent } from '@newrelic/browser-agent/loaders/agent'
|
|
|
170
170
|
import { Metrics } from '@newrelic/browser-agent/src/features/metrics'
|
|
171
171
|
```
|
|
172
172
|
|
|
173
|
+
## Support
|
|
174
|
+
|
|
175
|
+
New Relic hosts and moderates an online forum where customers can interact with New Relic employees as well as other customers to get help and share best practices. Like all official New Relic open source projects, there's a related Community topic in the New Relic Explorers Hub. You can find this project's topic/threads here:
|
|
176
|
+
|
|
177
|
+
https://discuss.newrelic.com/c/full-stack-observability/browser
|
|
178
|
+
|
|
179
|
+
## Contribute
|
|
180
|
+
|
|
181
|
+
We encourage your contributions to improve the Browser agent! Keep in mind that when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project.
|
|
182
|
+
|
|
183
|
+
If you have any questions, or to execute our corporate CLA (which is required if your contribution is on behalf of a company), drop us an email at opensource@newrelic.com.
|
|
184
|
+
|
|
185
|
+
For more details on how best to contribute, see [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
186
|
+
|
|
187
|
+
**A note about vulnerabilities**
|
|
188
|
+
|
|
189
|
+
As noted in our [security policy](https://github.com/newrelic/newrelic-browser-agent/security/policy), New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.
|
|
190
|
+
|
|
191
|
+
If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through [HackerOne](https://hackerone.com/newrelic).
|
|
192
|
+
|
|
193
|
+
If you would like to contribute to this project, review [these guidelines](./CONTRIBUTING.md).
|
|
194
|
+
|
|
195
|
+
To all contributors, we thank you! Without your contribution, this project would not be what it is today. We also host [a community project page dedicated to the Browser agent](https://opensource.newrelic.com/projects/newrelic/newrelic-browser-agent).
|
|
196
|
+
|
|
173
197
|
## License
|
|
174
198
|
|
|
175
199
|
The Browser agent is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.
|
|
@@ -11,8 +11,9 @@ const isiOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
|
|
|
11
11
|
// Shared Web Workers introduced in iOS 16.0+ and n/a in 15.6-
|
|
12
12
|
exports.isiOS = isiOS;
|
|
13
13
|
const iOS_below16 = isiOS && Boolean(typeof SharedWorker === 'undefined');
|
|
14
|
-
/*
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
/*
|
|
15
|
+
^ It was discovered in Safari 14 (https://bugs.webkit.org/show_bug.cgi?id=225305) that the buffered flag in PerformanceObserver
|
|
16
|
+
did not work. This affects our onFCP metric in particular since web-vitals uses that flag to retrieve paint timing entries.
|
|
17
|
+
This was fixed in v16+.
|
|
17
18
|
*/
|
|
18
19
|
exports.iOS_below16 = iOS_below16;
|
|
@@ -8,26 +8,32 @@ var _featureDependencies = require("../../../loaders/features/featureDependencie
|
|
|
8
8
|
var _console = require("../../util/console");
|
|
9
9
|
class Configurable {
|
|
10
10
|
constructor(obj, model) {
|
|
11
|
-
|
|
12
|
-
if (!obj || typeof obj !== 'object') return (0, _console.warn)('New setting a Configurable requires an object as input');
|
|
13
|
-
if (!model || typeof model !== 'object') return (0, _console.warn)('Setting a Configurable requires a model to set its initial properties');
|
|
14
|
-
Object.assign(this, model);
|
|
15
|
-
Object.entries(obj).forEach(_ref => {
|
|
16
|
-
let [key, value] = _ref;
|
|
17
|
-
const frozenAttrs = (0, _featureDependencies.getFrozenAttributes)(key);
|
|
18
|
-
if (frozenAttrs.length && value && typeof value === 'object') {
|
|
19
|
-
frozenAttrs.forEach(attr => {
|
|
20
|
-
if (attr in value) {
|
|
21
|
-
(0, _console.warn)(`"${attr}" is a protected attribute and can not be changed in feature ${key}. It will have no effect.`);
|
|
22
|
-
delete value[attr];
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
this[key] = value;
|
|
27
|
-
});
|
|
28
|
-
} catch (err) {
|
|
29
|
-
(0, _console.warn)('An error occured while setting a Configurable', err);
|
|
30
|
-
}
|
|
11
|
+
Object.assign(this, setValues(obj, model));
|
|
31
12
|
}
|
|
32
13
|
}
|
|
33
|
-
exports.Configurable = Configurable;
|
|
14
|
+
exports.Configurable = Configurable;
|
|
15
|
+
function setValues(obj, model) {
|
|
16
|
+
const state = {};
|
|
17
|
+
try {
|
|
18
|
+
if (!obj || typeof obj !== 'object') return (0, _console.warn)('New setting a Configurable requires an object as input');
|
|
19
|
+
if (!model || typeof model !== 'object') return (0, _console.warn)('Setting a Configurable requires a model to set its initial properties');
|
|
20
|
+
Object.assign(state, model);
|
|
21
|
+
Object.entries(obj).forEach(_ref => {
|
|
22
|
+
let [key, value] = _ref;
|
|
23
|
+
if (!Object.keys(model).includes(key)) return;
|
|
24
|
+
const frozenAttrs = (0, _featureDependencies.getFrozenAttributes)(key);
|
|
25
|
+
if (frozenAttrs.length && value && typeof value === 'object') {
|
|
26
|
+
frozenAttrs.forEach(attr => {
|
|
27
|
+
if (attr in value) {
|
|
28
|
+
(0, _console.warn)("\"".concat(attr, "\" is a protected attribute and can not be changed in feature ").concat(key, ". It will have no effect."));
|
|
29
|
+
delete value[attr];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
state[key] = value;
|
|
34
|
+
});
|
|
35
|
+
return state;
|
|
36
|
+
} catch (err) {
|
|
37
|
+
(0, _console.warn)('An error occured while setting a Configurable', err);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -40,7 +40,7 @@ function isValid(id) {
|
|
|
40
40
|
}
|
|
41
41
|
function getInfo(id) {
|
|
42
42
|
if (!id) throw new Error('All info objects require an agent identifier!');
|
|
43
|
-
if (!_cache[id]) throw new Error(
|
|
43
|
+
if (!_cache[id]) throw new Error("Info for ".concat(id, " was never set"));
|
|
44
44
|
return _cache[id];
|
|
45
45
|
}
|
|
46
46
|
function setInfo(id, obj) {
|
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getConfiguration = getConfiguration;
|
|
7
7
|
exports.getConfigurationValue = getConfigurationValue;
|
|
8
8
|
exports.setConfiguration = setConfiguration;
|
|
9
|
+
var _constants = require("../../session/constants");
|
|
10
|
+
var _globalScope = require("../../util/global-scope");
|
|
9
11
|
var _nreum = require("../../window/nreum");
|
|
10
12
|
var _configurable = require("./configurable");
|
|
11
13
|
const model = {
|
|
@@ -27,6 +29,12 @@ const model = {
|
|
|
27
29
|
cors_use_tracecontext_headers: undefined,
|
|
28
30
|
allowed_origins: undefined
|
|
29
31
|
},
|
|
32
|
+
session: {
|
|
33
|
+
domain: undefined,
|
|
34
|
+
// used by first party cookies to set the top-level domain
|
|
35
|
+
expiresMs: _constants.DEFAULT_EXPIRES_MS,
|
|
36
|
+
inactiveMs: _constants.DEFAULT_INACTIVE_MS
|
|
37
|
+
},
|
|
30
38
|
ssl: undefined,
|
|
31
39
|
obfuscate: undefined,
|
|
32
40
|
jserrors: {
|
|
@@ -60,7 +68,7 @@ const model = {
|
|
|
60
68
|
const _cache = {};
|
|
61
69
|
function getConfiguration(id) {
|
|
62
70
|
if (!id) throw new Error('All configuration objects require an agent identifier!');
|
|
63
|
-
if (!_cache[id]) throw new Error(
|
|
71
|
+
if (!_cache[id]) throw new Error("Configuration for ".concat(id, " was never set"));
|
|
64
72
|
return _cache[id];
|
|
65
73
|
}
|
|
66
74
|
function setConfiguration(id, obj) {
|
|
@@ -18,7 +18,7 @@ const model = {
|
|
|
18
18
|
const _cache = {};
|
|
19
19
|
function getLoaderConfig(id) {
|
|
20
20
|
if (!id) throw new Error('All loader-config objects require an agent identifier!');
|
|
21
|
-
if (!_cache[id]) throw new Error(
|
|
21
|
+
if (!_cache[id]) throw new Error("LoaderConfig for ".concat(id, " was never set"));
|
|
22
22
|
return _cache[id];
|
|
23
23
|
}
|
|
24
24
|
function setLoaderConfig(id, obj) {
|
|
@@ -8,44 +8,42 @@ exports.setRuntime = setRuntime;
|
|
|
8
8
|
var userAgent = _interopRequireWildcard(require("../../util/user-agent"));
|
|
9
9
|
var _configurable = require("./configurable");
|
|
10
10
|
var _nreum = require("../../window/nreum");
|
|
11
|
-
var _sessionStorage = require("../../window/session-storage");
|
|
12
|
-
var _config = require("../config");
|
|
13
11
|
var _globalScope = require("../../util/global-scope");
|
|
14
|
-
var
|
|
12
|
+
var _env = require("../../constants/env.npm");
|
|
15
13
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
16
14
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
-
const model =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
15
|
+
const model = {
|
|
16
|
+
buildEnv: _env.BUILD_ENV,
|
|
17
|
+
bytesSent: {},
|
|
18
|
+
// Used for SM to capture body bytes sent per endpoint
|
|
19
|
+
queryBytesSent: {},
|
|
20
|
+
// Used for SM to capture query parameter bytes sent per endpoint
|
|
21
|
+
customTransaction: undefined,
|
|
22
|
+
disabled: false,
|
|
23
|
+
distMethod: _env.DIST_METHOD,
|
|
24
|
+
isolatedBacklog: false,
|
|
25
|
+
loaderType: undefined,
|
|
26
|
+
maxBytes: 30000,
|
|
27
|
+
// The "timeOrigin" property is the new standard timestamp property shared across main frame and workers, but is not supported in some early Safari browsers (safari<15) + IE
|
|
28
|
+
// ingest expects an integer value, and timeOrigin can return a float.
|
|
29
|
+
offset: Math.floor(_globalScope.globalScope?.performance?.timeOrigin || _globalScope.globalScope?.performance?.timing?.navigationStart || Date.now()),
|
|
30
|
+
onerror: undefined,
|
|
31
|
+
origin: '' + _globalScope.globalScope.location,
|
|
32
|
+
ptid: undefined,
|
|
33
|
+
releaseIds: {},
|
|
34
|
+
session: undefined,
|
|
35
|
+
xhrWrappable: typeof _globalScope.globalScope.XMLHttpRequest?.prototype?.addEventListener === 'function',
|
|
36
|
+
userAgent,
|
|
37
|
+
version: _env.VERSION
|
|
40
38
|
};
|
|
41
39
|
const _cache = {};
|
|
42
40
|
function getRuntime(id) {
|
|
43
41
|
if (!id) throw new Error('All runtime objects require an agent identifier!');
|
|
44
|
-
if (!_cache[id]) throw new Error(
|
|
42
|
+
if (!_cache[id]) throw new Error("Runtime for ".concat(id, " was never set"));
|
|
45
43
|
return _cache[id];
|
|
46
44
|
}
|
|
47
45
|
function setRuntime(id, obj) {
|
|
48
46
|
if (!id) throw new Error('All runtime objects require an agent identifier!');
|
|
49
|
-
_cache[id] = new _configurable.Configurable(obj, model
|
|
47
|
+
_cache[id] = new _configurable.Configurable(obj, model);
|
|
50
48
|
(0, _nreum.gosNREUMInitializedAgents)(id, _cache[id], 'runtime');
|
|
51
49
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @file This file exposes CDN build environment variables. These variables will
|
|
9
|
+
* be overridden with babel.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Exposes the version of the agent
|
|
14
|
+
*/
|
|
15
|
+
const VERSION = "1.232.0";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Exposes the build type of the agent
|
|
19
|
+
* Valid values are LOCAL, PROD, DEV
|
|
20
|
+
*/
|
|
21
|
+
exports.VERSION = VERSION;
|
|
22
|
+
const BUILD_ENV = undefined;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Exposes the distribution method of the agent
|
|
26
|
+
*/
|
|
27
|
+
exports.BUILD_ENV = BUILD_ENV;
|
|
28
|
+
const DIST_METHOD = 'CDN';
|
|
29
|
+
exports.DIST_METHOD = DIST_METHOD;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
|
|
7
|
+
var _package = _interopRequireDefault(require("../../../package.json"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
/**
|
|
10
|
+
* @file This file exposes build time environment variables that will be included in the
|
|
11
|
+
* build output of the agent. This file specifically contains the normal environment variables
|
|
12
|
+
* for the NPM agent build and will be overridden by webpack/babel during the build based on the
|
|
13
|
+
* type of build being performed.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Exposes the version of the agent
|
|
18
|
+
*/
|
|
19
|
+
const VERSION = _package.default.version;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Exposes the build type of the agent
|
|
23
|
+
*/
|
|
24
|
+
exports.VERSION = VERSION;
|
|
25
|
+
const BUILD_ENV = 'NPM';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Exposes the distribution method of the agent
|
|
29
|
+
*/
|
|
30
|
+
exports.BUILD_ENV = BUILD_ENV;
|
|
31
|
+
const DIST_METHOD = 'NPM';
|
|
32
|
+
exports.DIST_METHOD = DIST_METHOD;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @file This file exposes NPM build environment variables. These variables will
|
|
9
|
+
* be overridden with babel.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Exposes the version of the agent
|
|
14
|
+
*/
|
|
15
|
+
const VERSION = "1.232.0";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Exposes the build type of the agent
|
|
19
|
+
* Valid values are LOCAL, PROD, DEV
|
|
20
|
+
*/
|
|
21
|
+
exports.VERSION = VERSION;
|
|
22
|
+
const BUILD_ENV = 'NPM';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Exposes the distribution method of the agent
|
|
26
|
+
* Valid valuse are CDN, NPM
|
|
27
|
+
*/
|
|
28
|
+
exports.BUILD_ENV = BUILD_ENV;
|
|
29
|
+
const DIST_METHOD = 'NPM';
|
|
30
|
+
exports.DIST_METHOD = DIST_METHOD;
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _faker = require("@faker-js/faker");
|
|
4
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
5
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
6
|
+
let mockNREUM;
|
|
7
|
+
let runtime;
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
mockNREUM = {};
|
|
10
|
+
runtime = {};
|
|
11
|
+
jest.doMock('../window/nreum', () => ({
|
|
12
|
+
__esModule: true,
|
|
13
|
+
gosNREUM: jest.fn(() => mockNREUM)
|
|
14
|
+
}));
|
|
15
|
+
jest.doMock('../config/config', () => ({
|
|
16
|
+
__esModule: true,
|
|
17
|
+
getRuntime: jest.fn(() => runtime)
|
|
18
|
+
}));
|
|
19
|
+
});
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
jest.resetModules();
|
|
22
|
+
jest.resetAllMocks();
|
|
23
|
+
});
|
|
24
|
+
describe('global event-emitter', () => {
|
|
25
|
+
test('it returns the event-emitter defined on window.NREUM', async () => {
|
|
26
|
+
const mockEE = {};
|
|
27
|
+
mockNREUM.ee = mockEE;
|
|
28
|
+
const {
|
|
29
|
+
ee
|
|
30
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
31
|
+
expect(ee).toEqual(mockEE);
|
|
32
|
+
});
|
|
33
|
+
test('it sets the global event-emitter on window.NREUM', async () => {
|
|
34
|
+
const {
|
|
35
|
+
ee
|
|
36
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
37
|
+
expect(ee).toEqual(mockNREUM.ee);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe('scoping event-emitter', () => {
|
|
41
|
+
test('it creates a new child event-emitter', async () => {
|
|
42
|
+
const {
|
|
43
|
+
ee
|
|
44
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
45
|
+
const childName = _faker.faker.datatype.uuid();
|
|
46
|
+
const result = ee.get(childName);
|
|
47
|
+
expect(result).not.toEqual(mockNREUM.ee);
|
|
48
|
+
expect(result).toEqual(ee.get(childName)); // Should always return the same event-emitter
|
|
49
|
+
expect(result.debugId).toEqual(childName);
|
|
50
|
+
});
|
|
51
|
+
test('it creates a child event-emitter with an isolated backlog', async () => {
|
|
52
|
+
const childName = _faker.faker.random.alphaNumeric(16);
|
|
53
|
+
jest.doMock('../config/config', () => ({
|
|
54
|
+
__esModule: true,
|
|
55
|
+
getRuntime: jest.fn(id => {
|
|
56
|
+
if (id === childName) {
|
|
57
|
+
return {
|
|
58
|
+
isolatedBacklog: true
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return runtime;
|
|
62
|
+
})
|
|
63
|
+
}));
|
|
64
|
+
const {
|
|
65
|
+
ee
|
|
66
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
67
|
+
const result = ee.get(childName);
|
|
68
|
+
expect(ee.backlog).not.toBe(result.backlog);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe('event-emitter context', () => {
|
|
72
|
+
test('it returns a new context', async () => {
|
|
73
|
+
const {
|
|
74
|
+
ee
|
|
75
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
76
|
+
const result = ee.context();
|
|
77
|
+
expect(result).toEqual({});
|
|
78
|
+
});
|
|
79
|
+
test('it returns the same context', async () => {
|
|
80
|
+
const {
|
|
81
|
+
ee
|
|
82
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
83
|
+
const result = ee.context();
|
|
84
|
+
expect(result).toEqual(ee.context(result));
|
|
85
|
+
});
|
|
86
|
+
test('it adds the context to the provided object', async () => {
|
|
87
|
+
const {
|
|
88
|
+
ee
|
|
89
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
90
|
+
const obj = {};
|
|
91
|
+
const result = ee.context(obj);
|
|
92
|
+
expect(result).toEqual(obj['nr@context']);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
describe('event-emitter buffer', () => {
|
|
96
|
+
it('it should create a new buffer for the given group', async () => {
|
|
97
|
+
const {
|
|
98
|
+
ee
|
|
99
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
100
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
101
|
+
const group = _faker.faker.datatype.uuid();
|
|
102
|
+
ee.buffer([eventType], group);
|
|
103
|
+
expect(ee.backlog).toEqual(expect.objectContaining({
|
|
104
|
+
[group]: []
|
|
105
|
+
}));
|
|
106
|
+
expect(ee.isBuffering(eventType)).toEqual(true);
|
|
107
|
+
});
|
|
108
|
+
it('it should default group to "feature"', async () => {
|
|
109
|
+
const {
|
|
110
|
+
ee
|
|
111
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
112
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
113
|
+
ee.buffer([eventType]);
|
|
114
|
+
expect(ee.backlog).toEqual(expect.objectContaining({
|
|
115
|
+
feature: []
|
|
116
|
+
}));
|
|
117
|
+
expect(ee.isBuffering(eventType)).toEqual(true);
|
|
118
|
+
});
|
|
119
|
+
it('it should not create buffer if event-emitter is aborted', async () => {
|
|
120
|
+
const {
|
|
121
|
+
ee
|
|
122
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
123
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
124
|
+
const group = _faker.faker.datatype.uuid();
|
|
125
|
+
ee.backlog = {
|
|
126
|
+
api: ['foo', 'bar', 'baz']
|
|
127
|
+
};
|
|
128
|
+
ee.abort();
|
|
129
|
+
ee.buffer([eventType], group);
|
|
130
|
+
expect(ee.backlog).toEqual({});
|
|
131
|
+
expect(ee.isBuffering(eventType)).toEqual(false);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
describe('event-emitter abort', () => {
|
|
135
|
+
test('it aborts if there is an API backlog', async () => {
|
|
136
|
+
const {
|
|
137
|
+
ee
|
|
138
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
139
|
+
ee.backlog = {
|
|
140
|
+
api: ['foo', 'bar', 'baz']
|
|
141
|
+
};
|
|
142
|
+
ee.abort();
|
|
143
|
+
expect(ee.aborted).toEqual(true);
|
|
144
|
+
expect(ee.backlog).toEqual({});
|
|
145
|
+
});
|
|
146
|
+
test('it aborts if there is a feature backlog', async () => {
|
|
147
|
+
const {
|
|
148
|
+
ee
|
|
149
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
150
|
+
ee.backlog = {
|
|
151
|
+
feature: ['foo', 'bar', 'baz']
|
|
152
|
+
};
|
|
153
|
+
ee.abort();
|
|
154
|
+
expect(ee.aborted).toEqual(true);
|
|
155
|
+
expect(ee.backlog).toEqual({});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
describe('event-emitter emit', () => {
|
|
159
|
+
it('should execute the listener', async () => {
|
|
160
|
+
const {
|
|
161
|
+
ee
|
|
162
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
163
|
+
const mockListener = jest.fn();
|
|
164
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
165
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
166
|
+
ee.on(eventType, mockListener);
|
|
167
|
+
ee.emit(eventType, eventArgs);
|
|
168
|
+
expect(mockListener).toHaveBeenCalledWith(eventArgs[0], eventArgs[1], eventArgs[2]);
|
|
169
|
+
});
|
|
170
|
+
it('should not execute the listener after removal', async () => {
|
|
171
|
+
const {
|
|
172
|
+
ee
|
|
173
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
174
|
+
const mockListener = jest.fn();
|
|
175
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
176
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
177
|
+
ee.on(eventType, mockListener);
|
|
178
|
+
ee.emit(eventType, eventArgs);
|
|
179
|
+
ee.removeEventListener(eventType, mockListener);
|
|
180
|
+
ee.emit(eventType, eventArgs);
|
|
181
|
+
expect(mockListener).toHaveBeenCalledTimes(1);
|
|
182
|
+
});
|
|
183
|
+
it('should return early if global event-emitter is aborted', async () => {
|
|
184
|
+
const {
|
|
185
|
+
ee
|
|
186
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
187
|
+
const mockListener = jest.fn();
|
|
188
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
189
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
190
|
+
ee.backlog = {
|
|
191
|
+
api: ['foo', 'bar', 'baz']
|
|
192
|
+
};
|
|
193
|
+
ee.abort();
|
|
194
|
+
ee.on(eventType, mockListener);
|
|
195
|
+
ee.emit(eventType, eventArgs);
|
|
196
|
+
expect(mockListener).toHaveBeenCalledTimes(0);
|
|
197
|
+
});
|
|
198
|
+
it('should still emit if global event-emitter is aborted but force flag is true', async () => {
|
|
199
|
+
const {
|
|
200
|
+
ee
|
|
201
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
202
|
+
const scopeEE = ee.get(_faker.faker.datatype.uuid());
|
|
203
|
+
const mockScopeListener = jest.fn();
|
|
204
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
205
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
206
|
+
ee.backlog = {
|
|
207
|
+
api: ['foo', 'bar', 'baz']
|
|
208
|
+
};
|
|
209
|
+
ee.abort();
|
|
210
|
+
scopeEE.on(eventType, mockScopeListener);
|
|
211
|
+
scopeEE.emit(eventType, eventArgs, {}, true);
|
|
212
|
+
expect(mockScopeListener).toHaveBeenCalledTimes(1);
|
|
213
|
+
});
|
|
214
|
+
it('should bubble the event if bubble flag is true', async () => {
|
|
215
|
+
const {
|
|
216
|
+
ee
|
|
217
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
218
|
+
const scopeEE = ee.get(_faker.faker.datatype.uuid());
|
|
219
|
+
const mockListener = jest.fn();
|
|
220
|
+
const mockScopeListener = jest.fn();
|
|
221
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
222
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
223
|
+
ee.on(eventType, mockListener);
|
|
224
|
+
scopeEE.on(eventType, mockScopeListener);
|
|
225
|
+
scopeEE.emit(eventType, eventArgs, {}, false, true);
|
|
226
|
+
expect(mockScopeListener).toHaveBeenCalledTimes(1);
|
|
227
|
+
expect(mockListener).toHaveBeenCalledTimes(1);
|
|
228
|
+
});
|
|
229
|
+
it('should not bubble the event if bubble flag is false', async () => {
|
|
230
|
+
const {
|
|
231
|
+
ee
|
|
232
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
233
|
+
const scopeEE = ee.get(_faker.faker.datatype.uuid());
|
|
234
|
+
const mockListener = jest.fn();
|
|
235
|
+
const mockScopeListener = jest.fn();
|
|
236
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
237
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
238
|
+
ee.on(eventType, mockListener);
|
|
239
|
+
scopeEE.on(eventType, mockScopeListener);
|
|
240
|
+
scopeEE.emit(eventType, eventArgs, {}, false, false);
|
|
241
|
+
expect(mockScopeListener).toHaveBeenCalledTimes(1);
|
|
242
|
+
expect(mockListener).not.toHaveBeenCalled();
|
|
243
|
+
});
|
|
244
|
+
it('should buffer the event on the scoped event-emitter', async () => {
|
|
245
|
+
const {
|
|
246
|
+
ee
|
|
247
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
248
|
+
const scopeEE = ee.get(_faker.faker.datatype.uuid());
|
|
249
|
+
const mockListener = jest.fn();
|
|
250
|
+
const mockScopeListener = jest.fn();
|
|
251
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
252
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
253
|
+
ee.on(eventType, mockListener);
|
|
254
|
+
ee.buffer([eventType]);
|
|
255
|
+
scopeEE.on(eventType, mockScopeListener);
|
|
256
|
+
scopeEE.buffer([eventType]);
|
|
257
|
+
scopeEE.emit(eventType, eventArgs, {}, false, false);
|
|
258
|
+
expect(mockScopeListener).toHaveBeenCalledTimes(1);
|
|
259
|
+
expect(mockListener).not.toHaveBeenCalled();
|
|
260
|
+
expect(scopeEE.backlog.feature).toEqual(expect.arrayContaining([expect.arrayContaining([scopeEE, eventType, eventArgs, {}])]));
|
|
261
|
+
expect(ee.backlog.feature).toEqual(scopeEE.backlog.feature);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
describe('getOrSetContext', () => {
|
|
265
|
+
test('it returns a new context', async () => {
|
|
266
|
+
const {
|
|
267
|
+
getOrSetContext
|
|
268
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
269
|
+
const obj = {};
|
|
270
|
+
const result = getOrSetContext(obj);
|
|
271
|
+
expect(result).toEqual({});
|
|
272
|
+
expect(result).toEqual(obj['nr@context']);
|
|
273
|
+
});
|
|
274
|
+
test('it returns the same context', async () => {
|
|
275
|
+
const {
|
|
276
|
+
getOrSetContext
|
|
277
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
278
|
+
const obj = {};
|
|
279
|
+
const result = getOrSetContext(obj);
|
|
280
|
+
expect(getOrSetContext(obj)).toEqual(result);
|
|
281
|
+
});
|
|
282
|
+
});
|