@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
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker'
|
|
2
|
+
import { isFileProtocol } from './protocol'
|
|
3
|
+
|
|
4
|
+
test('should return true when location url contains file protocol', () => {
|
|
5
|
+
jest.spyOn(window, 'location', 'get').mockReturnValue({
|
|
6
|
+
protocol: 'file:'
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
expect(isFileProtocol()).toEqual(true)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test('should return false when location url does not contains file protocol', () => {
|
|
13
|
+
jest.spyOn(window, 'location', 'get').mockReturnValue({
|
|
14
|
+
protocol: 'http:'
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
expect(isFileProtocol()).toEqual(false)
|
|
18
|
+
})
|
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
import { stringify } from './stringify'
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Returns the size of the provided data. Designed for measuring XHR responses.
|
|
10
|
+
*
|
|
11
|
+
* @param {*} data - The data to be measured.
|
|
12
|
+
* @returns {(number|undefined)} - The size of the data or undefined if size cannot be determined.
|
|
13
|
+
*/
|
|
8
14
|
export function dataSize (data) {
|
|
9
15
|
if (typeof data === 'string' && data.length) return data.length
|
|
10
16
|
if (typeof data !== 'object') return undefined
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { dataSize } from './data-size'
|
|
2
|
+
|
|
3
|
+
describe('dataSize', () => {
|
|
4
|
+
test('returns length of string', () => {
|
|
5
|
+
const str = 'Hello, world!'
|
|
6
|
+
expect(dataSize(str)).toBe(str.length)
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
test('returns undefined for non-object, number, or empty string', () => {
|
|
10
|
+
expect(dataSize(Infinity)).toBeUndefined()
|
|
11
|
+
expect(dataSize(12345)).toBeUndefined() // might not actually be by design, but this is how it works today
|
|
12
|
+
expect(dataSize('')).toBeUndefined()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test('returns byte length of ArrayBuffer object', () => {
|
|
16
|
+
const buffer = new ArrayBuffer(8)
|
|
17
|
+
expect(dataSize(buffer)).toBe(8)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('returns size of Blob object', () => {
|
|
21
|
+
const blob = new Blob(['Hello, world!'], { type: 'text/plain' })
|
|
22
|
+
expect(dataSize(blob)).toBe(blob.size)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test('returns undefined for FormData object', () => {
|
|
26
|
+
const formData = new FormData()
|
|
27
|
+
expect(dataSize(formData)).toBeUndefined()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('returns length of JSON string representation of object', () => {
|
|
31
|
+
const obj = {
|
|
32
|
+
str: 'Hello, world!',
|
|
33
|
+
num: 12345,
|
|
34
|
+
nestedObj: {
|
|
35
|
+
arr: [1, 2, 3]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const expectedSize = JSON.stringify(obj).length
|
|
39
|
+
expect(dataSize(obj)).toBe(expectedSize)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('returns undefined for object with toJSON method that throws an error', () => {
|
|
43
|
+
const obj = {
|
|
44
|
+
toJSON: () => {
|
|
45
|
+
throw new Error('Error in toJSON')
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
expect(dataSize(obj)).toBeUndefined()
|
|
49
|
+
})
|
|
50
|
+
})
|
|
@@ -38,8 +38,7 @@ export function resetScope () {
|
|
|
38
38
|
} else if (self instanceof WorkerGlobalScope) {
|
|
39
39
|
globalScope = self
|
|
40
40
|
}
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
41
|
+
} else {
|
|
43
42
|
throw new Error('New Relic browser agent shutting down due to error: Unable to locate global scope. This is possibly due to code redefining browser global variables like "self" and "window".')
|
|
44
43
|
}
|
|
45
44
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce the invocation of the supplied function so that it is only invoked
|
|
3
|
+
* once within a given timeout.
|
|
4
|
+
*
|
|
5
|
+
* If `wait` is `0`, the function will be invoked during the next tick.
|
|
6
|
+
* If `options.leading` is false or not provided, the function will be invoked
|
|
7
|
+
* N milliseconds after the last invocation of the returned function where
|
|
8
|
+
* N is the `timeout` value.
|
|
9
|
+
* If `options.leading` is true, the function will be invoked immediately upon
|
|
10
|
+
* the first invocation of the returned function and not again for N milliseconds
|
|
11
|
+
* where N is the `timeout` value.
|
|
12
|
+
* @param {function} func Function whose invocation should be limited so it is only invoked
|
|
13
|
+
* once within a given timeout period.
|
|
14
|
+
* @param {number} timeout Time in milliseconds that the function should only be invoked
|
|
15
|
+
* once within.
|
|
16
|
+
* @param {object} options Debounce options
|
|
17
|
+
* @param {boolean} options.leading Forces the function to be invoked on the first
|
|
18
|
+
* invocation of the returned function instead of N milliseconds after the last
|
|
19
|
+
* invocation.
|
|
20
|
+
* @returns {function} A wrapping function that will ensure the provided function
|
|
21
|
+
* is invoked only once within the given timeout.
|
|
22
|
+
*/
|
|
23
|
+
export function debounce (func, timeout = 500, options = {}) {
|
|
24
|
+
const leading = options?.leading || false
|
|
25
|
+
let timer
|
|
26
|
+
return (...args) => {
|
|
27
|
+
if (leading && timer === undefined) {
|
|
28
|
+
func.apply(this, args)
|
|
29
|
+
timer = setTimeout(() => timer = clearTimeout(timer), timeout)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!leading) {
|
|
33
|
+
clearTimeout(timer)
|
|
34
|
+
timer = setTimeout(() => { func.apply(this, args) }, timeout)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Reduce the invocation of the supplied function so that it is only invoked
|
|
41
|
+
* once.
|
|
42
|
+
* @param {function} func Function whose invocation should be limited so it is only invoked
|
|
43
|
+
* once.
|
|
44
|
+
* @returns {function} A wrapping function that will ensure the provided function
|
|
45
|
+
* is invoked only once.
|
|
46
|
+
*/
|
|
47
|
+
export function single (func) {
|
|
48
|
+
let called = false
|
|
49
|
+
return (...args) => {
|
|
50
|
+
if (!called) {
|
|
51
|
+
called = true
|
|
52
|
+
func.apply(this, args)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { debounce, single } from './invoke'
|
|
2
|
+
|
|
3
|
+
jest.useFakeTimers()
|
|
4
|
+
|
|
5
|
+
describe('debounce', () => {
|
|
6
|
+
test('should run the supplied function after 100ms', () => {
|
|
7
|
+
let mockCallback = jest.fn()
|
|
8
|
+
|
|
9
|
+
let debouncedMethod = debounce(mockCallback, 100)
|
|
10
|
+
execFnTimes(debouncedMethod, 100)
|
|
11
|
+
|
|
12
|
+
expect(mockCallback).not.toHaveBeenCalled()
|
|
13
|
+
|
|
14
|
+
jest.advanceTimersByTime(1000)
|
|
15
|
+
expect(mockCallback).toHaveBeenCalledTimes(1)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('should rerun the supplied function when called again after 100ms', () => {
|
|
19
|
+
let mockCallback = jest.fn()
|
|
20
|
+
|
|
21
|
+
let debouncedMethod = debounce(mockCallback, 100)
|
|
22
|
+
|
|
23
|
+
execFnTimes(debouncedMethod, 100)
|
|
24
|
+
jest.advanceTimersByTime(200)
|
|
25
|
+
execFnTimes(debouncedMethod, 100)
|
|
26
|
+
jest.advanceTimersByTime(2000)
|
|
27
|
+
|
|
28
|
+
expect(mockCallback).toHaveBeenCalledTimes(2)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('should run the supplied function on the first event and debounce subsequent events', () => {
|
|
32
|
+
let mockCallback = jest.fn()
|
|
33
|
+
|
|
34
|
+
let debouncedMethod = debounce(mockCallback, 100, { leading: true })
|
|
35
|
+
|
|
36
|
+
execFnTimes(debouncedMethod, 100)
|
|
37
|
+
expect(mockCallback).toHaveBeenCalledTimes(1)
|
|
38
|
+
|
|
39
|
+
jest.advanceTimersByTime(200)
|
|
40
|
+
|
|
41
|
+
expect(mockCallback).toHaveBeenCalledTimes(1)
|
|
42
|
+
|
|
43
|
+
execFnTimes(debouncedMethod, 100)
|
|
44
|
+
jest.advanceTimersByTime(200)
|
|
45
|
+
|
|
46
|
+
expect(mockCallback).toHaveBeenCalledTimes(2)
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
describe('single', () => {
|
|
51
|
+
test('should run the supplied function only once', () => {
|
|
52
|
+
let mockCallback = jest.fn()
|
|
53
|
+
|
|
54
|
+
let singleMethod = single(mockCallback, 100)
|
|
55
|
+
execFnTimes(singleMethod, 100)
|
|
56
|
+
|
|
57
|
+
expect(mockCallback).toHaveBeenCalledTimes(1)
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
function execFnTimes (fn, count) {
|
|
62
|
+
for (let i = 0; i < count; i++) {
|
|
63
|
+
fn()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getConfigurationValue } from '../config/config'
|
|
2
2
|
import { SharedContext } from '../context/shared-context'
|
|
3
|
-
import {
|
|
3
|
+
import { isFileProtocol } from '../url/protocol'
|
|
4
4
|
import { warn } from './console'
|
|
5
5
|
|
|
6
6
|
var fileProtocolRule = {
|
|
@@ -8,10 +8,6 @@ var fileProtocolRule = {
|
|
|
8
8
|
replacement: 'file://OBFUSCATED'
|
|
9
9
|
}
|
|
10
10
|
export class Obfuscator extends SharedContext {
|
|
11
|
-
constructor (parent) {
|
|
12
|
-
super(parent) // gets any allowed properties from the parent and stores them in `sharedContext`
|
|
13
|
-
}
|
|
14
|
-
|
|
15
11
|
shouldObfuscate () {
|
|
16
12
|
return getRules(this.sharedContext.agentIdentifier).length > 0
|
|
17
13
|
}
|
|
@@ -41,7 +37,7 @@ export function getRules (agentIdentifier) {
|
|
|
41
37
|
|
|
42
38
|
rules = rules.concat(configRules)
|
|
43
39
|
|
|
44
|
-
if (
|
|
40
|
+
if (isFileProtocol()) rules.push(fileProtocolRule)
|
|
45
41
|
// could add additional runtime/environment-specific rules here
|
|
46
42
|
|
|
47
43
|
return rules
|
|
@@ -10,14 +10,14 @@ import { documentAddEventListener } from '../event-listener/event-listener-opts'
|
|
|
10
10
|
* @param {boolean} [toHiddenOnly=false] - only execute the 'cb' when the vis is changing to the hidden state; no arg is passed to 'cb' if used
|
|
11
11
|
* @returns void
|
|
12
12
|
*/
|
|
13
|
-
export function subscribeToVisibilityChange (cb, toHiddenOnly = false) {
|
|
14
|
-
documentAddEventListener('visibilitychange', handleVisibilityChange)
|
|
13
|
+
export function subscribeToVisibilityChange (cb, toHiddenOnly = false, capture, abortSignal) {
|
|
14
|
+
documentAddEventListener('visibilitychange', handleVisibilityChange, capture, abortSignal)
|
|
15
15
|
return
|
|
16
16
|
|
|
17
17
|
function handleVisibilityChange () {
|
|
18
18
|
if (toHiddenOnly) { // trigger cb on change to hidden state only
|
|
19
19
|
if (document.visibilityState == 'hidden') cb()
|
|
20
|
-
|
|
20
|
+
return
|
|
21
21
|
}
|
|
22
22
|
cb(document.visibilityState)
|
|
23
23
|
}
|
package/src/common/wrap/index.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* @file Wraps assorted native objects and functions for instrumentation.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { wrapConsole } from './wrap-console'
|
|
6
5
|
import { wrapEvents } from './wrap-events'
|
|
7
6
|
import { wrapFetch } from './wrap-fetch'
|
|
8
7
|
import { wrapHistory } from './wrap-history'
|
|
@@ -14,5 +13,5 @@ import { wrapTimer } from './wrap-timer'
|
|
|
14
13
|
import { wrapXhr } from './wrap-xhr'
|
|
15
14
|
|
|
16
15
|
export {
|
|
17
|
-
|
|
16
|
+
wrapEvents, wrapFetch, wrapHistory, wrapJsonP, wrapMutation, wrapPromise, wrapRaf, wrapTimer, wrapXhr
|
|
18
17
|
}
|
|
@@ -26,16 +26,16 @@ const REMOVE_EVENT_LISTENER = 'removeEventListener'
|
|
|
26
26
|
*/
|
|
27
27
|
export function wrapEvents (sharedEE) {
|
|
28
28
|
var ee = scopedEE(sharedEE)
|
|
29
|
-
if (wrapped[ee.debugId]++) // Notice if our wrapping never ran yet, the falsey NaN will not early return; but if it has,
|
|
30
|
-
{ return ee } // then we increment the count to track # of feats using this at runtime.
|
|
31
|
-
wrapped[ee.debugId] = 1
|
|
32
29
|
|
|
30
|
+
// Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
|
|
31
|
+
// then we increment the count to track # of feats using this at runtime.
|
|
32
|
+
if (wrapped[ee.debugId]++) return ee
|
|
33
|
+
wrapped[ee.debugId] = 1 // otherwise, first feature to wrap events
|
|
33
34
|
var wrapFn = wfn(ee, true)
|
|
34
35
|
|
|
35
36
|
// Guard against instrumenting environments w/o necessary features
|
|
36
37
|
if ('getPrototypeOf' in Object) {
|
|
37
|
-
if (isBrowserScope)
|
|
38
|
-
{ findEventListenerProtoAndCb(document, wrapNode) }
|
|
38
|
+
if (isBrowserScope) findEventListenerProtoAndCb(document, wrapNode)
|
|
39
39
|
findEventListenerProtoAndCb(globalScope, wrapNode)
|
|
40
40
|
findEventListenerProtoAndCb(XHR.prototype, wrapNode)
|
|
41
41
|
}
|
|
@@ -35,9 +35,10 @@ export function wrapFetch (sharedEE) {
|
|
|
35
35
|
return ee
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
wrapped[ee.debugId]
|
|
38
|
+
// Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
|
|
39
|
+
// then we increment the count to track # of feats using this at runtime.
|
|
40
|
+
if (wrapped[ee.debugId]++) return ee
|
|
41
|
+
wrapped[ee.debugId] = 1 // otherwise, first feature to wrap fetch
|
|
41
42
|
|
|
42
43
|
bodyMethods.forEach(method => {
|
|
43
44
|
wrapPromiseMethod(Req[proto], method, bodyPrefix)
|
|
@@ -21,9 +21,12 @@ const HISTORY_FNS = ['pushState', 'replaceState']
|
|
|
21
21
|
*/
|
|
22
22
|
export function wrapHistory (sharedEE) {
|
|
23
23
|
const ee = scopedEE(sharedEE)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
|
|
25
|
+
// Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
|
|
26
|
+
// then we increment the count to track # of feats using this at runtime. History API is only
|
|
27
|
+
// available in browser DOM context.
|
|
28
|
+
if (!isBrowserScope || wrapped[ee.debugId]++) return ee
|
|
29
|
+
wrapped[ee.debugId] = 1 // otherwise, first feature to wrap history
|
|
27
30
|
|
|
28
31
|
var wrapFn = wfn(ee)
|
|
29
32
|
/*
|
|
@@ -24,9 +24,11 @@ const domInsertMethods = ['appendChild', 'insertBefore', 'replaceChild']
|
|
|
24
24
|
export function wrapJsonP (sharedEE) {
|
|
25
25
|
const ee = scopedEE(sharedEE)
|
|
26
26
|
|
|
27
|
-
if
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
// Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
|
|
28
|
+
// then we increment the count to track # of feats using this at runtime. JSONP deals with DOM
|
|
29
|
+
// tags so browser window env is required.
|
|
30
|
+
if (!isBrowserScope || wrapped[ee.debugId]) return ee
|
|
31
|
+
wrapped[ee.debugId] = true // otherwise, first feature to wrap JSONP
|
|
30
32
|
|
|
31
33
|
var wrapFn = wfn(ee)
|
|
32
34
|
|
|
@@ -22,9 +22,12 @@ const wrapped = {}
|
|
|
22
22
|
*/
|
|
23
23
|
export function wrapMutation (sharedEE) {
|
|
24
24
|
const ee = scopedEE(sharedEE)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
|
|
26
|
+
// Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
|
|
27
|
+
// then we increment the count to track # of feats using this at runtime. Mutations API is only
|
|
28
|
+
// available in browser DOM context.
|
|
29
|
+
if (!isBrowserScope || wrapped[ee.debugId]) return ee
|
|
30
|
+
wrapped[ee.debugId] = true // otherwise, first feature to wrap mutations
|
|
28
31
|
|
|
29
32
|
var wrapFn = wfn(ee)
|
|
30
33
|
var OriginalObserver = originals.MO
|
|
@@ -24,9 +24,10 @@ const wrapped = {}
|
|
|
24
24
|
export function wrapPromise (sharedEE) {
|
|
25
25
|
const promiseEE = scopedEE(sharedEE)
|
|
26
26
|
|
|
27
|
-
if
|
|
28
|
-
|
|
29
|
-
wrapped[promiseEE.debugId]
|
|
27
|
+
// Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
|
|
28
|
+
// then we increment the count to track # of feats using this at runtime.
|
|
29
|
+
if (wrapped[promiseEE.debugId]) return promiseEE
|
|
30
|
+
wrapped[promiseEE.debugId] = true // otherwise, first feature to wrap promise
|
|
30
31
|
|
|
31
32
|
var getContext = getOrSetContext
|
|
32
33
|
var promiseWrapper = wrapFn(promiseEE)
|
|
@@ -69,9 +70,9 @@ export function wrapPromise (sharedEE) {
|
|
|
69
70
|
const prevStaticFn = prevPromiseObj[method]
|
|
70
71
|
WrappedPromise[method] = function (subPromises) { // use our own wrapped version of "Promise.all" and ".race" static fns
|
|
71
72
|
let finalized = false
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
this.resolve(sub).then(setNrId(method === 'all'), setNrId(false))
|
|
73
|
+
|
|
74
|
+
Array.from(subPromises || []).forEach(sub => {
|
|
75
|
+
this.resolve(sub).then(setNrId(method === 'all'), setNrId(false))
|
|
75
76
|
})
|
|
76
77
|
|
|
77
78
|
const origFnCallWithThis = prevStaticFn.apply(this, arguments)
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker'
|
|
2
|
+
import { globalScope } from '../util/global-scope'
|
|
3
|
+
import { originals } from '../config/config'
|
|
4
|
+
|
|
5
|
+
jest.mock('./wrap-function', () => ({
|
|
6
|
+
__esModule: true,
|
|
7
|
+
createWrapperWithEmitter: jest.fn(() => (fn) => (...args) => {
|
|
8
|
+
return fn.apply(null, args)
|
|
9
|
+
})
|
|
10
|
+
}))
|
|
11
|
+
jest.mock('../event-emitter/contextual-ee', () => ({
|
|
12
|
+
__esModule: true,
|
|
13
|
+
getOrSetContext: jest.fn(() => ({})),
|
|
14
|
+
ee: {
|
|
15
|
+
get: jest.fn((name) => ({
|
|
16
|
+
debugId: name,
|
|
17
|
+
on: jest.fn(),
|
|
18
|
+
context: jest.fn(() => ({})),
|
|
19
|
+
emit: jest.fn()
|
|
20
|
+
}))
|
|
21
|
+
}
|
|
22
|
+
}))
|
|
23
|
+
jest.mock('../config/config', () => ({
|
|
24
|
+
__esModule: true,
|
|
25
|
+
originals: {}
|
|
26
|
+
}))
|
|
27
|
+
jest.mock('../util/global-scope', () => ({
|
|
28
|
+
__esModule: true,
|
|
29
|
+
globalScope: {
|
|
30
|
+
NREUM: {}
|
|
31
|
+
}
|
|
32
|
+
}))
|
|
33
|
+
|
|
34
|
+
let promiseConstructorCalls
|
|
35
|
+
|
|
36
|
+
beforeEach(async () => {
|
|
37
|
+
promiseConstructorCalls = []
|
|
38
|
+
|
|
39
|
+
// Proxy the global Promise to prevent the wrapping from
|
|
40
|
+
// messing with Jest internal promises
|
|
41
|
+
originals.PR = new Proxy(class extends Promise {}, {
|
|
42
|
+
construct (target, args) {
|
|
43
|
+
promiseConstructorCalls.push(args)
|
|
44
|
+
|
|
45
|
+
return Reflect.construct(target, args)
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
;(await import('./wrap-promise')).wrapPromise()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
jest.resetModules()
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('should wrap promise constructor', async () => {
|
|
57
|
+
const promiseInstance = new globalScope.Promise(jest.fn())
|
|
58
|
+
|
|
59
|
+
expect(promiseInstance).toBeInstanceOf(Promise)
|
|
60
|
+
expect(promiseConstructorCalls.length).toEqual(1)
|
|
61
|
+
expect(globalScope.Promise.toString()).toMatch(/\[native code\]/)
|
|
62
|
+
expect(globalScope.Promise.name).toEqual('Promise')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
describe('all', () => {
|
|
66
|
+
test('should work with acceptable iterables', async () => {
|
|
67
|
+
const resolveValue = faker.datatype.uuid()
|
|
68
|
+
const customIterable = new CustomIterable([
|
|
69
|
+
new globalScope.Promise(resolve => resolve(resolveValue))
|
|
70
|
+
])
|
|
71
|
+
const arrayIterable = [
|
|
72
|
+
new globalScope.Promise(resolve => resolve(resolveValue))
|
|
73
|
+
]
|
|
74
|
+
const setIterable = new Set()
|
|
75
|
+
setIterable.add(new globalScope.Promise(resolve => resolve(resolveValue)))
|
|
76
|
+
|
|
77
|
+
await expect(globalScope.Promise.all(customIterable)).resolves.toEqual([resolveValue])
|
|
78
|
+
await expect(globalScope.Promise.all(arrayIterable)).resolves.toEqual([resolveValue])
|
|
79
|
+
await expect(globalScope.Promise.all(setIterable)).resolves.toEqual([resolveValue])
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test.each([null, undefined])('should not try to iterate a non-iterable %s', async (input) => {
|
|
83
|
+
jest.spyOn(globalScope.Promise, 'resolve')
|
|
84
|
+
|
|
85
|
+
await expect(globalScope.Promise.all(input)).rejects.toThrow()
|
|
86
|
+
expect(globalScope.Promise.resolve).not.toHaveBeenCalled()
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
describe('race', () => {
|
|
91
|
+
test('should work with acceptable iterables', async () => {
|
|
92
|
+
jest.spyOn(globalScope.Promise, 'resolve')
|
|
93
|
+
|
|
94
|
+
const resolveValue = faker.datatype.uuid()
|
|
95
|
+
const customIterable = new CustomIterable([
|
|
96
|
+
new globalScope.Promise(resolve => resolve(resolveValue))
|
|
97
|
+
])
|
|
98
|
+
const arrayIterable = [
|
|
99
|
+
new globalScope.Promise(resolve => resolve(resolveValue))
|
|
100
|
+
]
|
|
101
|
+
const setIterable = new Set()
|
|
102
|
+
setIterable.add(new globalScope.Promise(resolve => resolve(resolveValue)))
|
|
103
|
+
|
|
104
|
+
await expect(globalScope.Promise.race(customIterable)).resolves.toEqual(resolveValue)
|
|
105
|
+
await expect(globalScope.Promise.race(arrayIterable)).resolves.toEqual(resolveValue)
|
|
106
|
+
await expect(globalScope.Promise.race(setIterable)).resolves.toEqual(resolveValue)
|
|
107
|
+
expect(globalScope.Promise.resolve).toHaveBeenCalled()
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test.each([null, undefined])('should not try to iterate a non-iterable %s', async (input) => {
|
|
111
|
+
jest.spyOn(globalScope.Promise, 'resolve')
|
|
112
|
+
|
|
113
|
+
await expect(globalScope.Promise.race(input)).rejects.toThrow()
|
|
114
|
+
expect(globalScope.Promise.resolve).not.toHaveBeenCalled()
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
class CustomIterable {
|
|
119
|
+
#iterables = []
|
|
120
|
+
|
|
121
|
+
constructor (iterables) {
|
|
122
|
+
this.#iterables = iterables
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
[Symbol.iterator] () {
|
|
126
|
+
return {
|
|
127
|
+
index: 0,
|
|
128
|
+
iterables: this.#iterables,
|
|
129
|
+
next () {
|
|
130
|
+
return {
|
|
131
|
+
done: this.index >= this.iterables.length,
|
|
132
|
+
value: this.iterables[this.index++] || undefined
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
[Symbol.iterator] () {
|
|
136
|
+
return this
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -22,9 +22,11 @@ const RAF_NAME = 'requestAnimationFrame'
|
|
|
22
22
|
*/
|
|
23
23
|
export function wrapRaf (sharedEE) {
|
|
24
24
|
const ee = scopedEE(sharedEE)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
|
|
26
|
+
// Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
|
|
27
|
+
// then we increment the count to track # of feats using this at runtime.
|
|
28
|
+
if (!isBrowserScope || wrapped[ee.debugId]++) return ee
|
|
29
|
+
wrapped[ee.debugId] = 1 // otherwise, first feature to wrap RAF
|
|
28
30
|
|
|
29
31
|
var wrapFn = wfn(ee)
|
|
30
32
|
|
|
@@ -26,12 +26,14 @@ const TIMER_FNS = [SET_TIMEOUT, 'setImmediate', SET_INTERVAL, CLEAR_TIMEOUT, 'cl
|
|
|
26
26
|
* @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.
|
|
27
27
|
* @returns {Object} Scoped event emitter with a debug ID of `timer`.
|
|
28
28
|
*/
|
|
29
|
-
//eslint-disable-next-line
|
|
29
|
+
// eslint-disable-next-line
|
|
30
30
|
export function wrapTimer(sharedEE) {
|
|
31
31
|
const ee = scopedEE(sharedEE)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
|
|
33
|
+
// Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
|
|
34
|
+
// then we increment the count to track # of feats using this at runtime.
|
|
35
|
+
if (wrapped[ee.debugId]++) return ee
|
|
36
|
+
wrapped[ee.debugId] = 1 // otherwise, first feature to wrap timer
|
|
35
37
|
|
|
36
38
|
var wrapFn = wfn(ee)
|
|
37
39
|
|
|
@@ -29,9 +29,10 @@ export function wrapXhr (sharedEE) {
|
|
|
29
29
|
var baseEE = sharedEE || contextualEE
|
|
30
30
|
const ee = scopedEE(baseEE)
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
wrapped[ee.debugId]
|
|
32
|
+
// Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
|
|
33
|
+
// then we increment the count to track # of feats using this at runtime.
|
|
34
|
+
if (wrapped[ee.debugId]++) return ee
|
|
35
|
+
wrapped[ee.debugId] = 1 // otherwise, first feature to wrap XHR
|
|
35
36
|
|
|
36
37
|
wrapEvents(baseEE) // wrap-events patches XMLHttpRequest.prototype.addEventListener for us
|
|
37
38
|
var wrapFn = wfn(ee)
|
|
@@ -9,13 +9,13 @@ import { handle } from '../../../common/event-emitter/handle'
|
|
|
9
9
|
import { getConfigurationValue, getInfo } from '../../../common/config/config'
|
|
10
10
|
import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler'
|
|
11
11
|
import { setDenyList, shouldCollectEvent } from '../../../common/deny-list/deny-list'
|
|
12
|
-
import { AggregateBase } from '../../utils/aggregate-base'
|
|
13
12
|
import { FEATURE_NAME } from '../constants'
|
|
14
13
|
import { drain } from '../../../common/drain/drain'
|
|
15
14
|
import { FEATURE_NAMES } from '../../../loaders/features/features'
|
|
16
15
|
import { SUPPORTABILITY_METRIC_CHANNEL } from '../../metrics/constants'
|
|
16
|
+
import { FeatureBase } from '../../utils/feature-base'
|
|
17
17
|
|
|
18
|
-
export class Aggregate extends
|
|
18
|
+
export class Aggregate extends FeatureBase {
|
|
19
19
|
static featureName = FEATURE_NAME
|
|
20
20
|
constructor (agentIdentifier, aggregator) {
|
|
21
21
|
super(agentIdentifier, aggregator, FEATURE_NAME)
|
|
@@ -140,7 +140,7 @@ function subscribeToEvents (agentIdentifier, ee, handler, dt) {
|
|
|
140
140
|
if (evt.type === 'abort' && !(context.loadCaptureCalled)) {
|
|
141
141
|
context.params.aborted = true
|
|
142
142
|
}
|
|
143
|
-
if (evt.type !== 'load' || (context.called === context.totalCbs) && (context.onloadCalled || typeof (xhr.onload) !== 'function') && typeof context.end === 'function') context.end(xhr)
|
|
143
|
+
if (evt.type !== 'load' || ((context.called === context.totalCbs) && (context.onloadCalled || typeof (xhr.onload) !== 'function') && typeof context.end === 'function')) context.end(xhr)
|
|
144
144
|
} catch (e) {
|
|
145
145
|
try {
|
|
146
146
|
ee.emit('internal-error', [e])
|
|
@@ -18,12 +18,12 @@ import { getInfo, getConfigurationValue, getRuntime } from '../../../common/conf
|
|
|
18
18
|
import { now } from '../../../common/timing/now'
|
|
19
19
|
import { globalScope } from '../../../common/util/global-scope'
|
|
20
20
|
|
|
21
|
-
import { AggregateBase } from '../../utils/aggregate-base'
|
|
22
21
|
import { FEATURE_NAME } from '../constants'
|
|
23
22
|
import { drain } from '../../../common/drain/drain'
|
|
24
23
|
import { FEATURE_NAMES } from '../../../loaders/features/features'
|
|
24
|
+
import { FeatureBase } from '../../utils/feature-base'
|
|
25
25
|
|
|
26
|
-
export class Aggregate extends
|
|
26
|
+
export class Aggregate extends FeatureBase {
|
|
27
27
|
static featureName = FEATURE_NAME
|
|
28
28
|
constructor (agentIdentifier, aggregator) {
|
|
29
29
|
super(agentIdentifier, aggregator, FEATURE_NAME)
|
|
@@ -222,6 +222,7 @@ export class Aggregate extends AggregateBase {
|
|
|
222
222
|
|
|
223
223
|
// still send EE events for other features such as above, but stop this one from aggregating internal data
|
|
224
224
|
if (this.blocked) return
|
|
225
|
+
var att = getInfo(this.agentIdentifier).jsAttributes
|
|
225
226
|
if (params._interactionId != null) {
|
|
226
227
|
// hold on to the error until the interaction finishes
|
|
227
228
|
this.errorCache[params._interactionId] = this.errorCache[params._interactionId] || []
|
|
@@ -229,7 +230,6 @@ export class Aggregate extends AggregateBase {
|
|
|
229
230
|
} else {
|
|
230
231
|
// store custom attributes
|
|
231
232
|
var customParams = {}
|
|
232
|
-
var att = getInfo(this.agentIdentifier).jsAttributes
|
|
233
233
|
mapOwn(att, setCustom)
|
|
234
234
|
if (customAttributes) {
|
|
235
235
|
mapOwn(customAttributes, setCustom)
|
|
@@ -24,8 +24,10 @@ export class Instrument extends InstrumentBase {
|
|
|
24
24
|
// skipNext counter to keep track of uncaught
|
|
25
25
|
// errors that will be the same as caught errors.
|
|
26
26
|
this.skipNext = 0
|
|
27
|
-
try {
|
|
28
|
-
|
|
27
|
+
try {
|
|
28
|
+
// this try-catch can be removed when IE11 is completely unsupported & gone
|
|
29
|
+
this.removeOnAbort = new AbortController()
|
|
30
|
+
} catch (e) {}
|
|
29
31
|
|
|
30
32
|
const thisInstrument = this
|
|
31
33
|
thisInstrument.ee.on('fn-start', function (args, obj, methodName) {
|