@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,70 @@
|
|
|
1
|
+
import * as encode from './encode';
|
|
2
|
+
describe('query string encoding', () => {
|
|
3
|
+
test('escapes string components except safe characters', () => {
|
|
4
|
+
const input = 'Asdf:, :, /@$;';
|
|
5
|
+
const expected = 'Asdf:,%20:,%20/@$;';
|
|
6
|
+
expect(encode.qs(input)).toEqual(expected);
|
|
7
|
+
});
|
|
8
|
+
test('null and undefined value returns \'null\'', () => {
|
|
9
|
+
expect(encode.qs(null)).toEqual('null');
|
|
10
|
+
expect(encode.qs(undefined)).toEqual('null');
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
describe('fromArray encoding', () => {
|
|
14
|
+
test('cuts cleanly at end of byte', () => {
|
|
15
|
+
const input = ['a', 'b', 'c'];
|
|
16
|
+
const expected = 'ab';
|
|
17
|
+
expect(encode.fromArray(input, 2)).toEqual(expected);
|
|
18
|
+
});
|
|
19
|
+
test('fall back to largest whole chunk', () => {
|
|
20
|
+
const input = ['aa', 'bb', 'cc'];
|
|
21
|
+
const expected = 'aabb';
|
|
22
|
+
expect(encode.fromArray(input, 5)).toEqual(expected);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe('object encoding', () => {
|
|
26
|
+
test('cuts cleanly at end of byte', () => {
|
|
27
|
+
const input = {
|
|
28
|
+
foo: [1, 2, 3]
|
|
29
|
+
};
|
|
30
|
+
const expected = '&foo=%5B1,2%5D';
|
|
31
|
+
expect(encode.obj(input, 12)).toEqual(expected);
|
|
32
|
+
});
|
|
33
|
+
test('fall back to largest whole chunk', () => {
|
|
34
|
+
const input = {
|
|
35
|
+
bar: ['a', 'b', 'c']
|
|
36
|
+
};
|
|
37
|
+
const expected = '&bar=%5B%22a%22,%22b%22%5D';
|
|
38
|
+
expect(encode.obj(input, 30)).toEqual(expected);
|
|
39
|
+
});
|
|
40
|
+
test('handles circular objects', () => {
|
|
41
|
+
const circular = {};
|
|
42
|
+
circular.circular = circular;
|
|
43
|
+
const input = {
|
|
44
|
+
bar: ['a', circular, 'c']
|
|
45
|
+
};
|
|
46
|
+
const expected = '&bar=%5B%22a%22,%7B%7D,%22c%22%5D';
|
|
47
|
+
expect(encode.obj(input, 1000)).toEqual(expected);
|
|
48
|
+
});
|
|
49
|
+
test('handles circular arrays', () => {
|
|
50
|
+
const circular = [];
|
|
51
|
+
circular.push(circular);
|
|
52
|
+
const input = {
|
|
53
|
+
bar: ['a', circular, 'c']
|
|
54
|
+
};
|
|
55
|
+
const expected = '&bar=%5B%22a%22,%5Bnull%5D,%22c%22%5D';
|
|
56
|
+
expect(encode.obj(input, 1000)).toEqual(expected);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe('encode key value pairs as query params', () => {
|
|
60
|
+
test('ignores input when value is null or undefined', () => {
|
|
61
|
+
expect(encode.param('foo', null)).toEqual('');
|
|
62
|
+
expect(encode.param('foo', undefined)).toEqual('');
|
|
63
|
+
});
|
|
64
|
+
test('encodes key value pair correctly', () => {
|
|
65
|
+
expect(encode.param('foo', 'bar')).toEqual('&foo=bar');
|
|
66
|
+
});
|
|
67
|
+
test('ignores input when value is not a string', () => {
|
|
68
|
+
expect(encode.param('foo', {})).toEqual('');
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* This method only exists to support testing in JIL and can be removed once tests are migrated to WDIO.
|
|
8
|
+
* @returns global scope location
|
|
9
|
+
*/
|
|
6
10
|
export function getLocation() {
|
|
7
11
|
return '' + location;
|
|
8
12
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker';
|
|
2
|
+
import { getLocation } from './location';
|
|
3
|
+
test('should always return a string', () => {
|
|
4
|
+
jest.spyOn(window, 'location', 'get').mockReturnValue({});
|
|
5
|
+
expect(typeof getLocation()).toEqual('string');
|
|
6
|
+
});
|
|
7
|
+
test('should return window location', () => {
|
|
8
|
+
const expected = faker.internet.url();
|
|
9
|
+
jest.spyOn(window, 'location', 'get').mockReturnValue(expected);
|
|
10
|
+
expect(getLocation()).toEqual(expected);
|
|
11
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
afterEach(() => {
|
|
2
|
+
jest.resetModules();
|
|
3
|
+
jest.clearAllMocks();
|
|
4
|
+
});
|
|
5
|
+
const urlTests = [{
|
|
6
|
+
input: 'http://example.com/path/name?qs=5&a=b',
|
|
7
|
+
expected: {
|
|
8
|
+
hostname: 'example.com',
|
|
9
|
+
pathname: '/path/name',
|
|
10
|
+
protocol: 'http',
|
|
11
|
+
port: '80',
|
|
12
|
+
sameOrigin: false
|
|
13
|
+
}
|
|
14
|
+
}, {
|
|
15
|
+
input: 'http://foo:bar@example.com:8080/path/@name?qs=5&a=b',
|
|
16
|
+
expected: {
|
|
17
|
+
hostname: 'example.com',
|
|
18
|
+
pathname: '/path/@name',
|
|
19
|
+
protocol: 'http',
|
|
20
|
+
port: '8080',
|
|
21
|
+
sameOrigin: false
|
|
22
|
+
}
|
|
23
|
+
}, {
|
|
24
|
+
input: 'https://foo:bar@example.com/path/name?qs=5&a=b',
|
|
25
|
+
expected: {
|
|
26
|
+
hostname: 'example.com',
|
|
27
|
+
pathname: '/path/name',
|
|
28
|
+
protocol: 'https',
|
|
29
|
+
port: '443',
|
|
30
|
+
sameOrigin: false
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
input: '/path/name?qs=5&a=b',
|
|
34
|
+
expected: {
|
|
35
|
+
hostname: location.hostname,
|
|
36
|
+
pathname: '/path/name',
|
|
37
|
+
protocol: location.protocol.split(':')[0],
|
|
38
|
+
port: '80',
|
|
39
|
+
sameOrigin: true
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
input: location.protocol + '//' + location.hostname + ':' + location.port + '/path/name?qs=5&a=b',
|
|
43
|
+
expected: {
|
|
44
|
+
hostname: location.hostname,
|
|
45
|
+
pathname: '/path/name',
|
|
46
|
+
protocol: location.protocol.split(':')[0],
|
|
47
|
+
port: '80',
|
|
48
|
+
sameOrigin: true
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
input: 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==',
|
|
52
|
+
expected: {
|
|
53
|
+
protocol: 'data'
|
|
54
|
+
}
|
|
55
|
+
}];
|
|
56
|
+
test.each(urlTests)('verify url parsing inside browser scope', async _ref => {
|
|
57
|
+
let {
|
|
58
|
+
input,
|
|
59
|
+
expected
|
|
60
|
+
} = _ref;
|
|
61
|
+
jest.doMock('../util/global-scope', () => ({
|
|
62
|
+
__esModule: true,
|
|
63
|
+
isBrowserScope: true,
|
|
64
|
+
globalScope: global
|
|
65
|
+
}));
|
|
66
|
+
const {
|
|
67
|
+
parseUrl
|
|
68
|
+
} = await import('./parse-url');
|
|
69
|
+
expect(parseUrl(input)).toEqual(expected);
|
|
70
|
+
});
|
|
71
|
+
test.each(urlTests)('verify url parsing outside browser scope', async _ref2 => {
|
|
72
|
+
let {
|
|
73
|
+
input,
|
|
74
|
+
expected
|
|
75
|
+
} = _ref2;
|
|
76
|
+
jest.doMock('../util/global-scope', () => ({
|
|
77
|
+
__esModule: true,
|
|
78
|
+
isBrowserScope: false,
|
|
79
|
+
globalScope: global
|
|
80
|
+
}));
|
|
81
|
+
const {
|
|
82
|
+
parseUrl
|
|
83
|
+
} = await import('./parse-url');
|
|
84
|
+
expect(parseUrl(input)).toEqual(expected);
|
|
85
|
+
});
|
|
86
|
+
test('should cache parsed urls', async () => {
|
|
87
|
+
jest.doMock('../util/global-scope', () => ({
|
|
88
|
+
__esModule: true,
|
|
89
|
+
isBrowserScope: true,
|
|
90
|
+
globalScope: global
|
|
91
|
+
}));
|
|
92
|
+
const input = 'http://example.com/';
|
|
93
|
+
const expected = {
|
|
94
|
+
hostname: 'example.com',
|
|
95
|
+
pathname: '/',
|
|
96
|
+
protocol: 'http',
|
|
97
|
+
port: '80',
|
|
98
|
+
sameOrigin: false
|
|
99
|
+
};
|
|
100
|
+
jest.spyOn(document, 'createElement');
|
|
101
|
+
const {
|
|
102
|
+
parseUrl
|
|
103
|
+
} = await import('./parse-url');
|
|
104
|
+
parseUrl(input);
|
|
105
|
+
expect(parseUrl(input)).toEqual(expected);
|
|
106
|
+
expect(document.createElement).toHaveBeenCalledTimes(1);
|
|
107
|
+
});
|
|
@@ -2,16 +2,7 @@
|
|
|
2
2
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
supportabilityMetricSent: false
|
|
9
|
-
};
|
|
10
|
-
function isFileProtocol() {
|
|
11
|
-
let isFile = Boolean(getGlobalScope()?.location?.protocol === 'file:');
|
|
12
|
-
if (isFile) {
|
|
13
|
-
//metrics.recordSupportability('Generic/FileProtocol/Detected') -- may be implemented later? Probably make sure it's once per window
|
|
14
|
-
protocol.supportabilityMetricSent = true;
|
|
15
|
-
}
|
|
16
|
-
return isFile;
|
|
5
|
+
import { globalScope } from '../util/global-scope';
|
|
6
|
+
export function isFileProtocol() {
|
|
7
|
+
return Boolean(globalScope?.location?.protocol === 'file:');
|
|
17
8
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker';
|
|
2
|
+
import { isFileProtocol } from './protocol';
|
|
3
|
+
test('should return true when location url contains file protocol', () => {
|
|
4
|
+
jest.spyOn(window, 'location', 'get').mockReturnValue({
|
|
5
|
+
protocol: 'file:'
|
|
6
|
+
});
|
|
7
|
+
expect(isFileProtocol()).toEqual(true);
|
|
8
|
+
});
|
|
9
|
+
test('should return false when location url does not contains file protocol', () => {
|
|
10
|
+
jest.spyOn(window, 'location', 'get').mockReturnValue({
|
|
11
|
+
protocol: 'http:'
|
|
12
|
+
});
|
|
13
|
+
expect(isFileProtocol()).toEqual(false);
|
|
14
|
+
});
|
|
@@ -4,6 +4,13 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { stringify } from './stringify';
|
|
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
|
+
*/
|
|
7
14
|
export function dataSize(data) {
|
|
8
15
|
if (typeof data === 'string' && data.length) return data.length;
|
|
9
16
|
if (typeof data !== 'object') return undefined;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { dataSize } from './data-size';
|
|
2
|
+
describe('dataSize', () => {
|
|
3
|
+
test('returns length of string', () => {
|
|
4
|
+
const str = 'Hello, world!';
|
|
5
|
+
expect(dataSize(str)).toBe(str.length);
|
|
6
|
+
});
|
|
7
|
+
test('returns undefined for non-object, number, or empty string', () => {
|
|
8
|
+
expect(dataSize(Infinity)).toBeUndefined();
|
|
9
|
+
expect(dataSize(12345)).toBeUndefined(); // might not actually be by design, but this is how it works today
|
|
10
|
+
expect(dataSize('')).toBeUndefined();
|
|
11
|
+
});
|
|
12
|
+
test('returns byte length of ArrayBuffer object', () => {
|
|
13
|
+
const buffer = new ArrayBuffer(8);
|
|
14
|
+
expect(dataSize(buffer)).toBe(8);
|
|
15
|
+
});
|
|
16
|
+
test('returns size of Blob object', () => {
|
|
17
|
+
const blob = new Blob(['Hello, world!'], {
|
|
18
|
+
type: 'text/plain'
|
|
19
|
+
});
|
|
20
|
+
expect(dataSize(blob)).toBe(blob.size);
|
|
21
|
+
});
|
|
22
|
+
test('returns undefined for FormData object', () => {
|
|
23
|
+
const formData = new FormData();
|
|
24
|
+
expect(dataSize(formData)).toBeUndefined();
|
|
25
|
+
});
|
|
26
|
+
test('returns length of JSON string representation of object', () => {
|
|
27
|
+
const obj = {
|
|
28
|
+
str: 'Hello, world!',
|
|
29
|
+
num: 12345,
|
|
30
|
+
nestedObj: {
|
|
31
|
+
arr: [1, 2, 3]
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const expectedSize = JSON.stringify(obj).length;
|
|
35
|
+
expect(dataSize(obj)).toBe(expectedSize);
|
|
36
|
+
});
|
|
37
|
+
test('returns undefined for object with toJSON method that throws an error', () => {
|
|
38
|
+
const obj = {
|
|
39
|
+
toJSON: () => {
|
|
40
|
+
throw new Error('Error in toJSON');
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
expect(dataSize(obj)).toBeUndefined();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
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) {
|
|
24
|
+
var _this = this;
|
|
25
|
+
let timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
|
|
26
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
27
|
+
const leading = options?.leading || false;
|
|
28
|
+
let timer;
|
|
29
|
+
return function () {
|
|
30
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
31
|
+
args[_key] = arguments[_key];
|
|
32
|
+
}
|
|
33
|
+
if (leading && timer === undefined) {
|
|
34
|
+
func.apply(_this, args);
|
|
35
|
+
timer = setTimeout(() => timer = clearTimeout(timer), timeout);
|
|
36
|
+
}
|
|
37
|
+
if (!leading) {
|
|
38
|
+
clearTimeout(timer);
|
|
39
|
+
timer = setTimeout(() => {
|
|
40
|
+
func.apply(_this, args);
|
|
41
|
+
}, timeout);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Reduce the invocation of the supplied function so that it is only invoked
|
|
48
|
+
* once.
|
|
49
|
+
* @param {function} func Function whose invocation should be limited so it is only invoked
|
|
50
|
+
* once.
|
|
51
|
+
* @returns {function} A wrapping function that will ensure the provided function
|
|
52
|
+
* is invoked only once.
|
|
53
|
+
*/
|
|
54
|
+
export function single(func) {
|
|
55
|
+
var _this2 = this;
|
|
56
|
+
let called = false;
|
|
57
|
+
return function () {
|
|
58
|
+
if (!called) {
|
|
59
|
+
called = true;
|
|
60
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
61
|
+
args[_key2] = arguments[_key2];
|
|
62
|
+
}
|
|
63
|
+
func.apply(_this2, args);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { debounce, single } from './invoke';
|
|
2
|
+
jest.useFakeTimers();
|
|
3
|
+
describe('debounce', () => {
|
|
4
|
+
test('should run the supplied function after 100ms', () => {
|
|
5
|
+
let mockCallback = jest.fn();
|
|
6
|
+
let debouncedMethod = debounce(mockCallback, 100);
|
|
7
|
+
execFnTimes(debouncedMethod, 100);
|
|
8
|
+
expect(mockCallback).not.toHaveBeenCalled();
|
|
9
|
+
jest.advanceTimersByTime(1000);
|
|
10
|
+
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
11
|
+
});
|
|
12
|
+
test('should rerun the supplied function when called again after 100ms', () => {
|
|
13
|
+
let mockCallback = jest.fn();
|
|
14
|
+
let debouncedMethod = debounce(mockCallback, 100);
|
|
15
|
+
execFnTimes(debouncedMethod, 100);
|
|
16
|
+
jest.advanceTimersByTime(200);
|
|
17
|
+
execFnTimes(debouncedMethod, 100);
|
|
18
|
+
jest.advanceTimersByTime(2000);
|
|
19
|
+
expect(mockCallback).toHaveBeenCalledTimes(2);
|
|
20
|
+
});
|
|
21
|
+
test('should run the supplied function on the first event and debounce subsequent events', () => {
|
|
22
|
+
let mockCallback = jest.fn();
|
|
23
|
+
let debouncedMethod = debounce(mockCallback, 100, {
|
|
24
|
+
leading: true
|
|
25
|
+
});
|
|
26
|
+
execFnTimes(debouncedMethod, 100);
|
|
27
|
+
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
28
|
+
jest.advanceTimersByTime(200);
|
|
29
|
+
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
30
|
+
execFnTimes(debouncedMethod, 100);
|
|
31
|
+
jest.advanceTimersByTime(200);
|
|
32
|
+
expect(mockCallback).toHaveBeenCalledTimes(2);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe('single', () => {
|
|
36
|
+
test('should run the supplied function only once', () => {
|
|
37
|
+
let mockCallback = jest.fn();
|
|
38
|
+
let singleMethod = single(mockCallback, 100);
|
|
39
|
+
execFnTimes(singleMethod, 100);
|
|
40
|
+
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
function execFnTimes(fn, count) {
|
|
44
|
+
for (let i = 0; i < count; i++) {
|
|
45
|
+
fn();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -8,7 +8,7 @@ test('enumerates the object properties', () => {
|
|
|
8
8
|
expect(callback).toHaveBeenCalledWith('foo', 'bar');
|
|
9
9
|
});
|
|
10
10
|
test('return array of results from callback invocation', () => {
|
|
11
|
-
const callback = jest.fn((key, value) =>
|
|
11
|
+
const callback = jest.fn((key, value) => "".concat(key, ":").concat(value));
|
|
12
12
|
const input = {
|
|
13
13
|
foo: 'bar',
|
|
14
14
|
biz: 'baz'
|
|
@@ -19,7 +19,7 @@ test('return array of results from callback invocation', () => {
|
|
|
19
19
|
expect(result).toContain('biz:baz');
|
|
20
20
|
});
|
|
21
21
|
test('does not iterate symbol properties', () => {
|
|
22
|
-
const callback = jest.fn((key, value) =>
|
|
22
|
+
const callback = jest.fn((key, value) => "".concat(key, ":").concat(value));
|
|
23
23
|
const input = {
|
|
24
24
|
foo: 'bar',
|
|
25
25
|
[Symbol.for('biz')]: 'baz'
|
|
@@ -32,7 +32,7 @@ test('does not iterate inherited properties', () => {
|
|
|
32
32
|
F.prototype = {
|
|
33
33
|
biz: 'baz'
|
|
34
34
|
};
|
|
35
|
-
const callback = jest.fn((key, value) =>
|
|
35
|
+
const callback = jest.fn((key, value) => "".concat(key, ":").concat(value));
|
|
36
36
|
const input = new F();
|
|
37
37
|
input.foo = 'bar';
|
|
38
38
|
const result = mapOwn(input, callback);
|
|
@@ -1,16 +1,12 @@
|
|
|
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
|
var fileProtocolRule = {
|
|
6
6
|
regex: /^file:\/\/(.*)/,
|
|
7
7
|
replacement: 'file://OBFUSCATED'
|
|
8
8
|
};
|
|
9
9
|
export class Obfuscator extends SharedContext {
|
|
10
|
-
constructor(parent) {
|
|
11
|
-
super(parent); // gets any allowed properties from the parent and stores them in `sharedContext`
|
|
12
|
-
}
|
|
13
|
-
|
|
14
10
|
shouldObfuscate() {
|
|
15
11
|
return getRules(this.sharedContext.agentIdentifier).length > 0;
|
|
16
12
|
}
|
|
@@ -37,7 +33,7 @@ export function getRules(agentIdentifier) {
|
|
|
37
33
|
var rules = [];
|
|
38
34
|
var configRules = getConfigurationValue(agentIdentifier, 'obfuscate') || [];
|
|
39
35
|
rules = rules.concat(configRules);
|
|
40
|
-
if (
|
|
36
|
+
if (isFileProtocol()) rules.push(fileProtocolRule);
|
|
41
37
|
// could add additional runtime/environment-specific rules here
|
|
42
38
|
|
|
43
39
|
return rules;
|
|
@@ -12,12 +12,15 @@ import { documentAddEventListener } from '../event-listener/event-listener-opts'
|
|
|
12
12
|
*/
|
|
13
13
|
export function subscribeToVisibilityChange(cb) {
|
|
14
14
|
let toHiddenOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
15
|
-
|
|
15
|
+
let capture = arguments.length > 2 ? arguments[2] : undefined;
|
|
16
|
+
let abortSignal = arguments.length > 3 ? arguments[3] : undefined;
|
|
17
|
+
documentAddEventListener('visibilitychange', handleVisibilityChange, capture, abortSignal);
|
|
16
18
|
return;
|
|
17
19
|
function handleVisibilityChange() {
|
|
18
20
|
if (toHiddenOnly) {
|
|
19
21
|
// trigger cb on change to hidden state only
|
|
20
|
-
if (document.visibilityState == 'hidden') cb();
|
|
22
|
+
if (document.visibilityState == 'hidden') cb();
|
|
23
|
+
return;
|
|
21
24
|
}
|
|
22
25
|
cb(document.visibilityState);
|
|
23
26
|
}
|
|
@@ -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';
|
|
@@ -12,4 +11,4 @@ import { wrapPromise } from './wrap-promise';
|
|
|
12
11
|
import { wrapRaf } from './wrap-raf';
|
|
13
12
|
import { wrapTimer } from './wrap-timer';
|
|
14
13
|
import { wrapXhr } from './wrap-xhr';
|
|
15
|
-
export {
|
|
14
|
+
export { wrapEvents, wrapFetch, wrapHistory, wrapJsonP, wrapMutation, wrapPromise, wrapRaf, wrapTimer, wrapXhr };
|
|
@@ -25,19 +25,16 @@ const REMOVE_EVENT_LISTENER = 'removeEventListener';
|
|
|
25
25
|
*/
|
|
26
26
|
export function wrapEvents(sharedEE) {
|
|
27
27
|
var ee = scopedEE(sharedEE);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
wrapped[ee.debugId] = 1;
|
|
28
|
+
|
|
29
|
+
// Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
|
|
30
|
+
// then we increment the count to track # of feats using this at runtime.
|
|
31
|
+
if (wrapped[ee.debugId]++) return ee;
|
|
32
|
+
wrapped[ee.debugId] = 1; // otherwise, first feature to wrap events
|
|
34
33
|
var wrapFn = wfn(ee, true);
|
|
35
34
|
|
|
36
35
|
// Guard against instrumenting environments w/o necessary features
|
|
37
36
|
if ('getPrototypeOf' in Object) {
|
|
38
|
-
if (isBrowserScope)
|
|
39
|
-
findEventListenerProtoAndCb(document, wrapNode);
|
|
40
|
-
}
|
|
37
|
+
if (isBrowserScope) findEventListenerProtoAndCb(document, wrapNode);
|
|
41
38
|
findEventListenerProtoAndCb(globalScope, wrapNode);
|
|
42
39
|
findEventListenerProtoAndCb(XHR.prototype, wrapNode);
|
|
43
40
|
}
|
|
@@ -32,12 +32,12 @@ export function wrapFetch(sharedEE) {
|
|
|
32
32
|
if (!(Req && Res && globalScope.fetch)) {
|
|
33
33
|
return ee;
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
|
|
36
|
+
// Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
|
|
37
|
+
// then we increment the count to track # of feats using this at runtime.
|
|
38
|
+
if (wrapped[ee.debugId]++) return ee;
|
|
39
|
+
wrapped[ee.debugId] = 1; // otherwise, first feature to wrap fetch
|
|
40
|
+
|
|
41
41
|
bodyMethods.forEach(method => {
|
|
42
42
|
wrapPromiseMethod(Req[proto], method, bodyPrefix);
|
|
43
43
|
wrapPromiseMethod(Res[proto], method, bodyPrefix);
|
|
@@ -20,12 +20,13 @@ const HISTORY_FNS = ['pushState', 'replaceState'];
|
|
|
20
20
|
*/
|
|
21
21
|
export function wrapHistory(sharedEE) {
|
|
22
22
|
const ee = scopedEE(sharedEE);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
wrapped[ee.debugId] = 1;
|
|
23
|
+
|
|
24
|
+
// Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
|
|
25
|
+
// then we increment the count to track # of feats using this at runtime. History API is only
|
|
26
|
+
// available in browser DOM context.
|
|
27
|
+
if (!isBrowserScope || wrapped[ee.debugId]++) return ee;
|
|
28
|
+
wrapped[ee.debugId] = 1; // otherwise, first feature to wrap history
|
|
29
|
+
|
|
29
30
|
var wrapFn = wfn(ee);
|
|
30
31
|
/*
|
|
31
32
|
* For objects that will be instantiated more than once, we wrap the object's prototype methods. The history object
|
|
@@ -22,12 +22,13 @@ const domInsertMethods = ['appendChild', 'insertBefore', 'replaceChild'];
|
|
|
22
22
|
*/
|
|
23
23
|
export function wrapJsonP(sharedEE) {
|
|
24
24
|
const ee = scopedEE(sharedEE);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
wrapped[ee.debugId] = true;
|
|
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. JSONP deals with DOM
|
|
28
|
+
// tags so browser window env is required.
|
|
29
|
+
if (!isBrowserScope || wrapped[ee.debugId]) return ee;
|
|
30
|
+
wrapped[ee.debugId] = true; // otherwise, first feature to wrap JSONP
|
|
31
|
+
|
|
31
32
|
var wrapFn = wfn(ee);
|
|
32
33
|
var CALLBACK_REGEX = /[?&](?:callback|cb)=([^&#]+)/;
|
|
33
34
|
var PARENT_REGEX = /(.*)\.([^.]+)/;
|
|
@@ -21,12 +21,13 @@ const wrapped = {};
|
|
|
21
21
|
*/
|
|
22
22
|
export function wrapMutation(sharedEE) {
|
|
23
23
|
const ee = scopedEE(sharedEE);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
wrapped[ee.debugId] = true;
|
|
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. Mutations API is only
|
|
27
|
+
// available in browser DOM context.
|
|
28
|
+
if (!isBrowserScope || wrapped[ee.debugId]) return ee;
|
|
29
|
+
wrapped[ee.debugId] = true; // otherwise, first feature to wrap mutations
|
|
30
|
+
|
|
30
31
|
var wrapFn = wfn(ee);
|
|
31
32
|
var OriginalObserver = originals.MO;
|
|
32
33
|
if (OriginalObserver) {
|
|
@@ -22,10 +22,12 @@ const wrapped = {};
|
|
|
22
22
|
*/
|
|
23
23
|
export function wrapPromise(sharedEE) {
|
|
24
24
|
const promiseEE = scopedEE(sharedEE);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
wrapped[promiseEE.debugId]
|
|
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 (wrapped[promiseEE.debugId]) return promiseEE;
|
|
29
|
+
wrapped[promiseEE.debugId] = true; // otherwise, first feature to wrap promise
|
|
30
|
+
|
|
29
31
|
var getContext = getOrSetContext;
|
|
30
32
|
var promiseWrapper = wrapFn(promiseEE);
|
|
31
33
|
var prevPromiseObj = originals.PR;
|
|
@@ -67,8 +69,7 @@ export function wrapPromise(sharedEE) {
|
|
|
67
69
|
WrappedPromise[method] = function (subPromises) {
|
|
68
70
|
// use our own wrapped version of "Promise.all" and ".race" static fns
|
|
69
71
|
let finalized = false;
|
|
70
|
-
subPromises
|
|
71
|
-
// eslint-disable-next-line
|
|
72
|
+
Array.from(subPromises || []).forEach(sub => {
|
|
72
73
|
this.resolve(sub).then(setNrId(method === 'all'), setNrId(false));
|
|
73
74
|
});
|
|
74
75
|
const origFnCallWithThis = prevStaticFn.apply(this, arguments);
|