@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,31 @@
|
|
|
1
|
+
|
|
2
|
+
export class Timer {
|
|
3
|
+
constructor (opts, ms) {
|
|
4
|
+
if (!opts.onEnd) throw new Error('onEnd handler is required')
|
|
5
|
+
if (!ms) throw new Error('ms duration is required')
|
|
6
|
+
this.onEnd = opts.onEnd
|
|
7
|
+
this.initialMs = ms
|
|
8
|
+
this.startTimestamp = Date.now()
|
|
9
|
+
|
|
10
|
+
this.timer = this.create(this.onEnd, ms)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
create (cb, ms) {
|
|
14
|
+
if (this.timer) this.clear()
|
|
15
|
+
return setTimeout(() => cb ? cb() : this.onEnd(), ms || this.initialMs)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
clear () {
|
|
19
|
+
clearTimeout(this.timer)
|
|
20
|
+
this.timer = null
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
end () {
|
|
24
|
+
this.clear()
|
|
25
|
+
this.onEnd()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
isValid () {
|
|
29
|
+
return this.initialMs - (Date.now() - this.startTimestamp) > 0
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Timer } from './timer'
|
|
2
|
+
|
|
3
|
+
jest.useFakeTimers()
|
|
4
|
+
|
|
5
|
+
let now
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
now = Date.now()
|
|
9
|
+
jest.setSystemTime(now)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
jest.clearAllMocks()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
describe('constructor', () => {
|
|
17
|
+
test('appropriate properties are set with valid values -- no refresh', () => {
|
|
18
|
+
const timer = new Timer({ onEnd: jest.fn() }, 100)
|
|
19
|
+
const requiredKeys = ['onEnd', 'initialMs', 'startTimestamp', 'timer']
|
|
20
|
+
expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('appropriate properties are set with valid values -- with refresh', () => {
|
|
24
|
+
const timer = new Timer({ onEnd: jest.fn() }, 100)
|
|
25
|
+
const requiredKeys = ['onEnd', 'initialMs', 'startTimestamp', 'timer']
|
|
26
|
+
expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('required keys are enforced', () => {
|
|
30
|
+
try {
|
|
31
|
+
new Timer({}, 100)
|
|
32
|
+
} catch (e) {
|
|
33
|
+
expect(e).toEqual(new Error('onEnd handler is required'))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
new Timer({ onEnd: jest.fn() })
|
|
38
|
+
} catch (e) {
|
|
39
|
+
expect(e).toEqual(new Error('ms duration is required'))
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
describe('create()', () => {
|
|
45
|
+
test('Create sets a timeout that can execute a cb', () => {
|
|
46
|
+
const timer = new Timer({ onEnd: jest.fn() }, 100)
|
|
47
|
+
expect(timer.timer).toBeTruthy()
|
|
48
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0)
|
|
49
|
+
jest.runOnlyPendingTimers()
|
|
50
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(1)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('Create can fallback to use defaults', () => {
|
|
54
|
+
let called = 0
|
|
55
|
+
const timer1 = new Timer({ onEnd: jest.fn() }, 100)
|
|
56
|
+
timer1.create()
|
|
57
|
+
|
|
58
|
+
const timer2 = new Timer({ onEnd: jest.fn() }, 100)
|
|
59
|
+
timer2.create(timer2.onEnd)
|
|
60
|
+
|
|
61
|
+
const timer3 = new Timer({ onEnd: jest.fn() }, 100)
|
|
62
|
+
timer3.create(undefined, 100)
|
|
63
|
+
|
|
64
|
+
jest.runAllTimers(200)
|
|
65
|
+
|
|
66
|
+
expect(timer1.onEnd).toHaveBeenCalledTimes(1)
|
|
67
|
+
expect(timer2.onEnd).toHaveBeenCalledTimes(1)
|
|
68
|
+
expect(timer3.onEnd).toHaveBeenCalledTimes(1)
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
describe('clear()', () => {
|
|
73
|
+
test('clear prevents the callback from firing and deletes the pointer', () => {
|
|
74
|
+
const timer = new Timer({ onEnd: jest.fn() }, 100)
|
|
75
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0)
|
|
76
|
+
timer.clear()
|
|
77
|
+
jest.advanceTimersByTime(150)
|
|
78
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0)
|
|
79
|
+
expect(timer.timer).toEqual(null)
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
describe('end()', () => {
|
|
84
|
+
test('end clears the callback and calls the onEnd callback', () => {
|
|
85
|
+
const timer = new Timer({ onEnd: jest.fn() }, 100)
|
|
86
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0)
|
|
87
|
+
timer.end()
|
|
88
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(1)
|
|
89
|
+
expect(timer.timer).toEqual(null)
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
describe('isValid', () => {
|
|
94
|
+
test('isValid validates timeStamps', () => {
|
|
95
|
+
const timer = new Timer({ onEnd: jest.fn() }, 100)
|
|
96
|
+
expect(timer.isValid()).toEqual(true)
|
|
97
|
+
timer.startTimestamp -= 100
|
|
98
|
+
expect(timer.isValid()).toEqual(false)
|
|
99
|
+
})
|
|
100
|
+
})
|
|
@@ -27,44 +27,64 @@ var DOM_CONTENT_LOAD_EVENT = 'domContentLoadedEvent'
|
|
|
27
27
|
|
|
28
28
|
export var navTimingValues = []
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
function getPntType (type) {
|
|
31
|
+
if (typeof type == 'number') return type
|
|
32
|
+
const types = {
|
|
33
|
+
navigate: undefined,
|
|
34
|
+
reload: 1,
|
|
35
|
+
back_forward: 2,
|
|
36
|
+
prerender: 3
|
|
37
|
+
}
|
|
38
|
+
return types[type]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function addPT (offset, pt, v = {}, isL1Api = false) {
|
|
42
|
+
if (!pt) return
|
|
31
43
|
v.of = offset
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
handleValue(v.of, v, 'n', true)
|
|
45
|
+
handleValue(pt[UNLOAD_EVENT + START], v, 'u', isL1Api)
|
|
46
|
+
handleValue(pt[REDIRECT + START], v, 'r', isL1Api)
|
|
47
|
+
handleValue(pt[UNLOAD_EVENT + END], v, 'ue', isL1Api)
|
|
48
|
+
handleValue(pt[REDIRECT + END], v, 're', isL1Api)
|
|
49
|
+
handleValue(pt['fetch' + START], v, 'f', isL1Api)
|
|
50
|
+
handleValue(pt[DOMAIN_LOOKUP + START], v, 'dn', isL1Api)
|
|
51
|
+
handleValue(pt[DOMAIN_LOOKUP + END], v, 'dne', isL1Api)
|
|
52
|
+
handleValue(pt['c' + ONNECT + START], v, 'c', isL1Api)
|
|
53
|
+
handleValue(pt['secureC' + ONNECT + 'ion' + START], v, 's', isL1Api)
|
|
54
|
+
handleValue(pt['c' + ONNECT + END], v, 'ce', isL1Api)
|
|
55
|
+
handleValue(pt[REQUEST + START], v, 'rq', isL1Api)
|
|
56
|
+
handleValue(pt[RESPONSE + START], v, 'rp', isL1Api)
|
|
57
|
+
handleValue(pt[RESPONSE + END], v, 'rpe', isL1Api)
|
|
58
|
+
handleValue(pt.domLoading, v, 'dl', isL1Api)
|
|
59
|
+
handleValue(pt.domInteractive, v, 'di', isL1Api)
|
|
60
|
+
handleValue(pt[DOM_CONTENT_LOAD_EVENT + START], v, 'ds', isL1Api)
|
|
61
|
+
handleValue(pt[DOM_CONTENT_LOAD_EVENT + END], v, 'de', isL1Api)
|
|
62
|
+
handleValue(pt.domComplete, v, 'dc', isL1Api)
|
|
63
|
+
handleValue(pt[LOAD_EVENT + START], v, 'l', isL1Api)
|
|
64
|
+
handleValue(pt[LOAD_EVENT + END], v, 'le', isL1Api)
|
|
53
65
|
return v
|
|
54
66
|
}
|
|
55
67
|
|
|
56
68
|
// Add Performance Navigation values to the given object
|
|
57
69
|
export function addPN (pn, v) {
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
handleValue(getPntType(pn.type), v, 'ty')
|
|
71
|
+
handleValue(pn.redirectCount, v, 'rc')
|
|
60
72
|
return v
|
|
61
73
|
}
|
|
62
74
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
75
|
+
function handleValue (value, obj, prop, isOldApi) {
|
|
76
|
+
/*
|
|
77
|
+
For L2 Timing API, the value will already be a relative-to-previous-document DOMHighResTimeStamp.
|
|
78
|
+
For L1 (deprecated) Timing, the value is an UNIX epoch timestamp, which we will convert to a relative time using our offset.
|
|
79
|
+
PNT.type is reported as undefined, 1, 2, etc -- note that zero-value properties will be recorded as 'undefined', however DEM interprets undefined "types" as "navigate"
|
|
80
|
+
*/
|
|
81
|
+
if (typeof value === 'number' && value > 0) { // note that zero-value properties will be recorded as 'undefined'
|
|
82
|
+
if (isOldApi) {
|
|
83
|
+
const offset = obj?.of > 0 ? obj.of : 0 // expect an epoch timestamp, if called by addPT
|
|
84
|
+
value = Math.max(value - offset, 0)
|
|
85
|
+
}
|
|
86
|
+
value = Math.round(value)
|
|
87
|
+
obj[prop] = value
|
|
68
88
|
}
|
|
69
|
-
navTimingValues.push(
|
|
89
|
+
navTimingValues.push(value)
|
|
70
90
|
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { addPT, addPN, navTimingValues } from './nav-timing'
|
|
2
|
+
|
|
3
|
+
const offset = 123
|
|
4
|
+
const testValues = {
|
|
5
|
+
unloadEventStart: 1,
|
|
6
|
+
redirectStart: 2,
|
|
7
|
+
unloadEventEnd: 3,
|
|
8
|
+
redirectEnd: 4,
|
|
9
|
+
fetchStart: 5,
|
|
10
|
+
domainLookupStart: 6,
|
|
11
|
+
domainLookupEnd: 7,
|
|
12
|
+
connectStart: 8,
|
|
13
|
+
secureConnectionStart: 9,
|
|
14
|
+
connectEnd: 10,
|
|
15
|
+
requestStart: 11,
|
|
16
|
+
responseStart: 12,
|
|
17
|
+
responseEnd: 13,
|
|
18
|
+
domLoading: 14,
|
|
19
|
+
domInteractive: 15,
|
|
20
|
+
domContentLoadedEventStart: 16,
|
|
21
|
+
domContentLoadedEventEnd: 17,
|
|
22
|
+
domComplete: 18,
|
|
23
|
+
loadEventStart: 19,
|
|
24
|
+
loadEventEnd: 20,
|
|
25
|
+
type: 'reload',
|
|
26
|
+
redirectCount: 22
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const legacyTestValues = {
|
|
30
|
+
unloadEventStart: offset + 1,
|
|
31
|
+
redirectStart: offset + 2,
|
|
32
|
+
unloadEventEnd: offset + 3,
|
|
33
|
+
redirectEnd: offset + 4,
|
|
34
|
+
fetchStart: offset + 5,
|
|
35
|
+
domainLookupStart: offset + 6,
|
|
36
|
+
domainLookupEnd: offset + 7,
|
|
37
|
+
connectStart: offset + 8,
|
|
38
|
+
secureConnectionStart: offset + 9,
|
|
39
|
+
connectEnd: offset + 10,
|
|
40
|
+
requestStart: offset + 11,
|
|
41
|
+
responseStart: offset + 12,
|
|
42
|
+
responseEnd: offset + 13,
|
|
43
|
+
domLoading: offset + 14,
|
|
44
|
+
domInteractive: offset + 15,
|
|
45
|
+
domContentLoadedEventStart: offset + 16,
|
|
46
|
+
domContentLoadedEventEnd: offset + 17,
|
|
47
|
+
domComplete: offset + 18,
|
|
48
|
+
loadEventStart: offset + 19,
|
|
49
|
+
loadEventEnd: offset + 20,
|
|
50
|
+
type: 'reload',
|
|
51
|
+
redirectCount: offset + 22
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const expectedPT = {
|
|
55
|
+
of: offset,
|
|
56
|
+
n: 0,
|
|
57
|
+
u: 1,
|
|
58
|
+
r: 2,
|
|
59
|
+
ue: 3,
|
|
60
|
+
re: 4,
|
|
61
|
+
f: 5,
|
|
62
|
+
dn: 6,
|
|
63
|
+
dne: 7,
|
|
64
|
+
c: 8,
|
|
65
|
+
s: 9,
|
|
66
|
+
ce: 10,
|
|
67
|
+
rq: 11,
|
|
68
|
+
rp: 12,
|
|
69
|
+
rpe: 13,
|
|
70
|
+
dl: 14,
|
|
71
|
+
di: 15,
|
|
72
|
+
ds: 16,
|
|
73
|
+
de: 17,
|
|
74
|
+
dc: 18,
|
|
75
|
+
l: 19,
|
|
76
|
+
le: 20
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const expectedPN = {
|
|
80
|
+
ty: 1,
|
|
81
|
+
rc: 22
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
describe('addPT()', () => {
|
|
85
|
+
test('an output object is populated with valid values', () => {
|
|
86
|
+
const output = addPT(offset, testValues, {})
|
|
87
|
+
expect(output).toEqual(expectedPT)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('an object with invalid values is handled', () => {
|
|
91
|
+
const output = addPT(offset, { ...testValues, invalidValue: 'test' }, {})
|
|
92
|
+
expect(output).toEqual(expectedPT)
|
|
93
|
+
|
|
94
|
+
const output2 = addPT(offset, { ...testValues, loadEventEnd: -1 }, {})
|
|
95
|
+
let expected = { ...expectedPT }
|
|
96
|
+
delete expected.le
|
|
97
|
+
expect(output2).toEqual(expected)
|
|
98
|
+
|
|
99
|
+
const output3 = addPT(offset, { ...testValues, loadEventEnd: 'test' }, {})
|
|
100
|
+
expected = { ...expectedPT }
|
|
101
|
+
delete expected.le
|
|
102
|
+
expect(output3).toEqual(expected)
|
|
103
|
+
|
|
104
|
+
const output4 = addPT(offset, { ...testValues, loadEventEnd: null }, {})
|
|
105
|
+
expected = { ...expectedPT }
|
|
106
|
+
delete expected.le
|
|
107
|
+
expect(output4).toEqual(expected)
|
|
108
|
+
|
|
109
|
+
const legacyoutput = addPT(offset, { ...legacyTestValues, invalidValue: 'test' }, {}, true)
|
|
110
|
+
expect(legacyoutput).toEqual(expectedPT)
|
|
111
|
+
|
|
112
|
+
const legacyoutput2 = addPT(offset, { ...legacyTestValues, loadEventEnd: -1 }, {}, true)
|
|
113
|
+
let legacyexpected = { ...expectedPT }
|
|
114
|
+
delete legacyexpected.le
|
|
115
|
+
expect(legacyoutput2).toEqual(expected)
|
|
116
|
+
|
|
117
|
+
const legacyoutput3 = addPT(offset, { ...legacyTestValues, loadEventEnd: 'test' }, {}, true)
|
|
118
|
+
legacyexpected = { ...expectedPT }
|
|
119
|
+
delete legacyexpected.le
|
|
120
|
+
expect(legacyoutput3).toEqual(legacyexpected)
|
|
121
|
+
|
|
122
|
+
const legacyoutput4 = addPT(offset, { ...legacyTestValues, loadEventEnd: null }, {}, true)
|
|
123
|
+
legacyexpected = { ...expectedPT }
|
|
124
|
+
delete legacyexpected.le
|
|
125
|
+
expect(legacyoutput4).toEqual(legacyexpected)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
test('rounds values to integers', () => {
|
|
129
|
+
const output = addPT(offset, { unloadEventStart: 3.14159 }, {})
|
|
130
|
+
expect(output.u).toEqual(3)
|
|
131
|
+
|
|
132
|
+
const legacyoutput = addPT(0, { unloadEventStart: 3.14159 }, {}, true)
|
|
133
|
+
expect(legacyoutput.u).toEqual(3)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('adds entries to navTimingValues', () => {
|
|
137
|
+
const beforeLength = navTimingValues.length
|
|
138
|
+
addPT(offset, { testValues }, {})
|
|
139
|
+
const afterLength = navTimingValues.length
|
|
140
|
+
expect(afterLength - beforeLength).toEqual(21) // 20 + value of n
|
|
141
|
+
|
|
142
|
+
const legacybeforeLength = navTimingValues.length
|
|
143
|
+
addPT(offset, { legacyTestValues }, {}, true)
|
|
144
|
+
const legacyafterLength = navTimingValues.length
|
|
145
|
+
expect(legacyafterLength - legacybeforeLength).toEqual(21) // 20 + value of n
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
describe('addPN()', () => {
|
|
150
|
+
test('an output object is populated with valid values', () => {
|
|
151
|
+
const output = addPN(testValues, {})
|
|
152
|
+
expect(output).toEqual(expectedPN)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
test('adds entries to navTimingValues', () => {
|
|
156
|
+
const beforeLength = navTimingValues.length
|
|
157
|
+
addPN(offset, { testValues }, {})
|
|
158
|
+
const afterLength = navTimingValues.length
|
|
159
|
+
expect(afterLength - beforeLength).toEqual(2)
|
|
160
|
+
})
|
|
161
|
+
})
|
package/src/common/unload/eol.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { ffVersion } from '../browser-version/firefox-version'
|
|
6
6
|
import { windowAddEventListener } from '../event-listener/event-listener-opts'
|
|
7
|
-
import { single } from '../util/
|
|
7
|
+
import { single } from '../util/invoke'
|
|
8
8
|
import { globalScope, isWorkerScope, isBrowserScope } from '../util/global-scope'
|
|
9
9
|
import { subscribeToVisibilityChange } from '../window/page-visibility'
|
|
10
10
|
|
|
@@ -55,8 +55,7 @@ export function subscribeToEOL (cb, allowBFCache) {
|
|
|
55
55
|
}
|
|
56
56
|
windowAddEventListener('unload', oneCall)
|
|
57
57
|
}
|
|
58
|
-
}
|
|
59
|
-
else if (isWorkerScope) {
|
|
58
|
+
} else if (isWorkerScope) {
|
|
60
59
|
globalScope.cleanupTasks.push(cb) // close() should run these tasks before quitting thread
|
|
61
60
|
}
|
|
62
61
|
// By default (for other env), this fn has no effect.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { cleanURL } from './clean-url'
|
|
2
|
+
|
|
3
|
+
test.each([
|
|
4
|
+
['http://domain.com/path?query=5', 'http://domain.com/path'],
|
|
5
|
+
['http://domain.com/path#fragment', 'http://domain.com/path'],
|
|
6
|
+
['http://domain.com/path?query=5#fragment', 'http://domain.com/path'],
|
|
7
|
+
['http://domain.com/path?query=5?dumb#fragment', 'http://domain.com/path'],
|
|
8
|
+
['http://domain.com/path?query=5#fragment#dumb', 'http://domain.com/path'],
|
|
9
|
+
['http://domain.com/path?query=5#fragment#dumb?additional_query', 'http://domain.com/path'],
|
|
10
|
+
['http://domain.com/path?query=5#fragment/silly/dumber#dumbest?additional_query=silly#what_is_this_even', 'http://domain.com/path']
|
|
11
|
+
])('cleanURL should remove hash', (input, expected) => {
|
|
12
|
+
expect(cleanURL(input)).toEqual(expected)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test.each([
|
|
16
|
+
['http://domain.com/path?query=5', 'http://domain.com/path'],
|
|
17
|
+
['http://domain.com/path#fragment', 'http://domain.com/path#fragment'],
|
|
18
|
+
['http://domain.com/path?query=5#fragment', 'http://domain.com/path#fragment'],
|
|
19
|
+
['http://domain.com/path?query=5?dumb#fragment', 'http://domain.com/path#fragment'],
|
|
20
|
+
['http://domain.com/path?query=5#fragment#dumb', 'http://domain.com/path#fragment#dumb'],
|
|
21
|
+
['http://domain.com/path?query=5#fragment#dumb?additional_query', 'http://domain.com/path#fragment#dumb'],
|
|
22
|
+
['http://domain.com/path?query=5#fragment/silly/dumber#dumbest?additional_query=silly#what_is_this_even', 'http://domain.com/path#fragment/silly/dumber#dumbest']
|
|
23
|
+
])('cleanURL should retain hash if second argument is true', (input, expected) => {
|
|
24
|
+
expect(cleanURL(input, true)).toEqual(expected)
|
|
25
|
+
})
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import * as encode from './encode'
|
|
2
|
+
|
|
3
|
+
describe('query string encoding', () => {
|
|
4
|
+
test('escapes string components except safe characters', () => {
|
|
5
|
+
const input = 'Asdf:, :, /@$;'
|
|
6
|
+
const expected = 'Asdf:,%20:,%20/@$;'
|
|
7
|
+
|
|
8
|
+
expect(encode.qs(input)).toEqual(expected)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
test('null and undefined value returns \'null\'', () => {
|
|
12
|
+
expect(encode.qs(null)).toEqual('null')
|
|
13
|
+
expect(encode.qs(undefined)).toEqual('null')
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
describe('fromArray encoding', () => {
|
|
18
|
+
test('cuts cleanly at end of byte', () => {
|
|
19
|
+
const input = ['a', 'b', 'c']
|
|
20
|
+
const expected = 'ab'
|
|
21
|
+
|
|
22
|
+
expect(encode.fromArray(input, 2)).toEqual(expected)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test('fall back to largest whole chunk', () => {
|
|
26
|
+
const input = ['aa', 'bb', 'cc']
|
|
27
|
+
const expected = 'aabb'
|
|
28
|
+
|
|
29
|
+
expect(encode.fromArray(input, 5)).toEqual(expected)
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
describe('object encoding', () => {
|
|
34
|
+
test('cuts cleanly at end of byte', () => {
|
|
35
|
+
const input = { foo: [1, 2, 3] }
|
|
36
|
+
const expected = '&foo=%5B1,2%5D'
|
|
37
|
+
|
|
38
|
+
expect(encode.obj(input, 12)).toEqual(expected)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('fall back to largest whole chunk', () => {
|
|
42
|
+
const input = { bar: ['a', 'b', 'c'] }
|
|
43
|
+
const expected = '&bar=%5B%22a%22,%22b%22%5D'
|
|
44
|
+
|
|
45
|
+
expect(encode.obj(input, 30)).toEqual(expected)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('handles circular objects', () => {
|
|
49
|
+
const circular = {}
|
|
50
|
+
circular.circular = circular
|
|
51
|
+
const input = { bar: ['a', circular, 'c'] }
|
|
52
|
+
const expected = '&bar=%5B%22a%22,%7B%7D,%22c%22%5D'
|
|
53
|
+
|
|
54
|
+
expect(encode.obj(input, 1000)).toEqual(expected)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('handles circular arrays', () => {
|
|
58
|
+
const circular = []
|
|
59
|
+
circular.push(circular)
|
|
60
|
+
const input = { bar: ['a', circular, 'c'] }
|
|
61
|
+
const expected = '&bar=%5B%22a%22,%5Bnull%5D,%22c%22%5D'
|
|
62
|
+
|
|
63
|
+
expect(encode.obj(input, 1000)).toEqual(expected)
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
describe('encode key value pairs as query params', () => {
|
|
68
|
+
test('ignores input when value is null or undefined', () => {
|
|
69
|
+
expect(encode.param('foo', null)).toEqual('')
|
|
70
|
+
expect(encode.param('foo', undefined)).toEqual('')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('encodes key value pair correctly', () => {
|
|
74
|
+
expect(encode.param('foo', 'bar')).toEqual('&foo=bar')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('ignores input when value is not a string', () => {
|
|
78
|
+
expect(encode.param('foo', {})).toEqual('')
|
|
79
|
+
})
|
|
80
|
+
})
|
|
@@ -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,15 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker'
|
|
2
|
+
import { getLocation } from './location'
|
|
3
|
+
|
|
4
|
+
test('should always return a string', () => {
|
|
5
|
+
jest.spyOn(window, 'location', 'get').mockReturnValue({})
|
|
6
|
+
|
|
7
|
+
expect(typeof getLocation()).toEqual('string')
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
test('should return window location', () => {
|
|
11
|
+
const expected = faker.internet.url()
|
|
12
|
+
jest.spyOn(window, 'location', 'get').mockReturnValue(expected)
|
|
13
|
+
|
|
14
|
+
expect(getLocation()).toEqual(expected)
|
|
15
|
+
})
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
afterEach(() => {
|
|
2
|
+
jest.resetModules()
|
|
3
|
+
jest.clearAllMocks()
|
|
4
|
+
})
|
|
5
|
+
|
|
6
|
+
const urlTests = [
|
|
7
|
+
{
|
|
8
|
+
input: 'http://example.com/path/name?qs=5&a=b',
|
|
9
|
+
expected: {
|
|
10
|
+
hostname: 'example.com',
|
|
11
|
+
pathname: '/path/name',
|
|
12
|
+
protocol: 'http',
|
|
13
|
+
port: '80',
|
|
14
|
+
sameOrigin: false
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
input: 'http://foo:bar@example.com:8080/path/@name?qs=5&a=b',
|
|
19
|
+
expected: {
|
|
20
|
+
hostname: 'example.com',
|
|
21
|
+
pathname: '/path/@name',
|
|
22
|
+
protocol: 'http',
|
|
23
|
+
port: '8080',
|
|
24
|
+
sameOrigin: false
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
input: 'https://foo:bar@example.com/path/name?qs=5&a=b',
|
|
29
|
+
expected: {
|
|
30
|
+
hostname: 'example.com',
|
|
31
|
+
pathname: '/path/name',
|
|
32
|
+
protocol: 'https',
|
|
33
|
+
port: '443',
|
|
34
|
+
sameOrigin: false
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
input: '/path/name?qs=5&a=b',
|
|
39
|
+
expected: {
|
|
40
|
+
hostname: location.hostname,
|
|
41
|
+
pathname: '/path/name',
|
|
42
|
+
protocol: location.protocol.split(':')[0],
|
|
43
|
+
port: '80',
|
|
44
|
+
sameOrigin: true
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
input: location.protocol + '//' + location.hostname + ':' + location.port + '/path/name?qs=5&a=b',
|
|
49
|
+
expected: {
|
|
50
|
+
hostname: location.hostname,
|
|
51
|
+
pathname: '/path/name',
|
|
52
|
+
protocol: location.protocol.split(':')[0],
|
|
53
|
+
port: '80',
|
|
54
|
+
sameOrigin: true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
input: 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==',
|
|
59
|
+
expected: {
|
|
60
|
+
protocol: 'data'
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
test.each(urlTests)('verify url parsing inside browser scope', async ({ input, expected }) => {
|
|
66
|
+
jest.doMock('../util/global-scope', () => ({
|
|
67
|
+
__esModule: true,
|
|
68
|
+
isBrowserScope: true,
|
|
69
|
+
globalScope: global
|
|
70
|
+
}))
|
|
71
|
+
|
|
72
|
+
const { parseUrl } = await import('./parse-url')
|
|
73
|
+
expect(parseUrl(input)).toEqual(expected)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test.each(urlTests)('verify url parsing outside browser scope', async ({ input, expected }) => {
|
|
77
|
+
jest.doMock('../util/global-scope', () => ({
|
|
78
|
+
__esModule: true,
|
|
79
|
+
isBrowserScope: false,
|
|
80
|
+
globalScope: global
|
|
81
|
+
}))
|
|
82
|
+
|
|
83
|
+
const { parseUrl } = await import('./parse-url')
|
|
84
|
+
expect(parseUrl(input)).toEqual(expected)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('should cache parsed urls', async () => {
|
|
88
|
+
jest.doMock('../util/global-scope', () => ({
|
|
89
|
+
__esModule: true,
|
|
90
|
+
isBrowserScope: true,
|
|
91
|
+
globalScope: global
|
|
92
|
+
}))
|
|
93
|
+
|
|
94
|
+
const input = 'http://example.com/'
|
|
95
|
+
const expected = {
|
|
96
|
+
hostname: 'example.com',
|
|
97
|
+
pathname: '/',
|
|
98
|
+
protocol: 'http',
|
|
99
|
+
port: '80',
|
|
100
|
+
sameOrigin: false
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
jest.spyOn(document, 'createElement')
|
|
104
|
+
|
|
105
|
+
const { parseUrl } = await import('./parse-url')
|
|
106
|
+
parseUrl(input)
|
|
107
|
+
|
|
108
|
+
expect(parseUrl(input)).toEqual(expected)
|
|
109
|
+
expect(document.createElement).toHaveBeenCalledTimes(1)
|
|
110
|
+
})
|
|
@@ -2,18 +2,8 @@
|
|
|
2
2
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { globalScope } from '../util/global-scope'
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
supportabilityMetricSent: false
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function isFileProtocol () {
|
|
13
|
-
let isFile = Boolean(getGlobalScope()?.location?.protocol === 'file:')
|
|
14
|
-
if (isFile) {
|
|
15
|
-
//metrics.recordSupportability('Generic/FileProtocol/Detected') -- may be implemented later? Probably make sure it's once per window
|
|
16
|
-
protocol.supportabilityMetricSent = true
|
|
17
|
-
}
|
|
18
|
-
return isFile
|
|
7
|
+
export function isFileProtocol () {
|
|
8
|
+
return Boolean(globalScope?.location?.protocol === 'file:')
|
|
19
9
|
}
|