@newrelic/browser-agent 1.237.1 → 1.239.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/dist/cjs/common/config/state/init.js +21 -13
- package/dist/cjs/common/config/state/runtime.js +0 -4
- package/dist/cjs/common/constants/env.cdn.js +1 -1
- package/dist/cjs/common/constants/env.npm.js +1 -1
- package/dist/cjs/common/constants/runtime.js +3 -3
- package/dist/cjs/common/constants/shared-channel.js +3 -1
- package/dist/cjs/common/deny-list/deny-list.js +3 -9
- package/dist/cjs/common/drain/drain.js +1 -1
- package/dist/cjs/common/event-emitter/contextual-ee.js +24 -32
- package/dist/cjs/common/event-emitter/event-context.js +12 -0
- package/dist/cjs/common/harvest/harvest-scheduler.js +2 -4
- package/dist/cjs/common/harvest/harvest.js +4 -7
- package/dist/cjs/common/ids/bundle-id.js +19 -0
- package/dist/cjs/common/serialize/bel-serializer.js +1 -1
- package/dist/cjs/common/session/session-entity.js +16 -12
- package/dist/cjs/common/storage/first-party-cookies.js +5 -4
- package/dist/cjs/common/storage/local-storage.js +3 -2
- package/dist/cjs/common/timer/interaction-timer.js +14 -6
- package/dist/cjs/common/timing/nav-timing.js +1 -1
- package/dist/cjs/common/unload/eol.js +4 -30
- package/dist/cjs/common/util/feature-flags.js +14 -15
- package/dist/cjs/common/util/invoke.js +3 -1
- package/dist/cjs/common/util/obfuscate.js +3 -5
- package/dist/cjs/common/util/traverse.js +1 -0
- package/dist/cjs/common/window/page-visibility.js +1 -2
- package/dist/cjs/common/wrap/wrap-events.js +3 -2
- package/dist/cjs/common/wrap/wrap-fetch.js +1 -3
- package/dist/cjs/common/wrap/wrap-function.js +15 -46
- package/dist/cjs/common/wrap/wrap-jsonp.js +1 -1
- package/dist/cjs/common/wrap/wrap-mutation.js +1 -2
- package/dist/cjs/common/wrap/wrap-promise.js +2 -3
- package/dist/cjs/common/wrap/wrap-xhr.js +23 -27
- package/dist/cjs/features/ajax/aggregate/index.js +5 -7
- package/dist/cjs/features/ajax/instrument/distributed-tracing.js +8 -12
- package/dist/cjs/features/ajax/instrument/index.js +66 -24
- package/dist/cjs/features/jserrors/aggregate/canonical-function-name.js +0 -1
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +4 -4
- package/dist/cjs/features/jserrors/aggregate/index.js +4 -5
- package/dist/cjs/features/metrics/aggregate/framework-detection.js +103 -7
- package/dist/cjs/features/metrics/aggregate/index.js +20 -37
- package/dist/cjs/features/metrics/instrument/index.js +0 -2
- package/dist/cjs/features/page_action/aggregate/index.js +17 -19
- package/dist/cjs/features/page_view_event/aggregate/index.js +1 -2
- package/dist/cjs/features/page_view_event/instrument/index.js +4 -2
- package/dist/cjs/features/page_view_timing/aggregate/index.js +6 -7
- package/dist/cjs/features/session_replay/aggregate/index.js +5 -3
- package/dist/cjs/features/session_trace/aggregate/index.js +22 -16
- package/dist/cjs/features/spa/aggregate/index.js +14 -20
- package/dist/cjs/features/spa/aggregate/interaction.js +0 -2
- package/dist/cjs/features/spa/aggregate/serializer.js +1 -1
- package/dist/cjs/features/utils/aggregate-base.js +4 -0
- package/dist/cjs/features/utils/handler-cache.js +3 -1
- package/dist/cjs/features/utils/instrument-base.js +24 -6
- package/dist/cjs/loaders/agent-base.js +23 -0
- package/dist/cjs/loaders/agent.js +7 -7
- package/dist/cjs/loaders/api/api.js +34 -4
- package/dist/cjs/loaders/api/apiAsync.js +19 -20
- package/dist/cjs/loaders/api/interaction-types.js +11 -4
- package/dist/cjs/loaders/configure/configure.js +3 -0
- package/dist/cjs/loaders/micro-agent.js +20 -3
- package/dist/esm/common/config/state/init.js +21 -13
- package/dist/esm/common/config/state/runtime.js +0 -4
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/common/constants/runtime.js +1 -1
- package/dist/esm/common/constants/shared-channel.js +3 -1
- package/dist/esm/common/deny-list/deny-list.js +3 -9
- package/dist/esm/common/drain/drain.js +1 -1
- package/dist/esm/common/event-emitter/contextual-ee.js +22 -29
- package/dist/esm/common/event-emitter/event-context.js +5 -0
- package/dist/esm/common/harvest/harvest-scheduler.js +2 -4
- package/dist/esm/common/harvest/harvest.js +4 -7
- package/dist/esm/common/ids/bundle-id.js +13 -0
- package/dist/esm/common/serialize/bel-serializer.js +1 -1
- package/dist/esm/common/session/session-entity.js +16 -12
- package/dist/esm/common/storage/first-party-cookies.js +5 -4
- package/dist/esm/common/storage/local-storage.js +3 -2
- package/dist/esm/common/timer/interaction-timer.js +14 -6
- package/dist/esm/common/timing/nav-timing.js +1 -1
- package/dist/esm/common/unload/eol.js +5 -31
- package/dist/esm/common/util/feature-flags.js +14 -15
- package/dist/esm/common/util/invoke.js +3 -1
- package/dist/esm/common/util/obfuscate.js +3 -5
- package/dist/esm/common/util/traverse.js +1 -0
- package/dist/esm/common/window/page-visibility.js +1 -2
- package/dist/esm/common/wrap/wrap-events.js +4 -3
- package/dist/esm/common/wrap/wrap-fetch.js +2 -4
- package/dist/esm/common/wrap/wrap-function.js +15 -44
- package/dist/esm/common/wrap/wrap-jsonp.js +1 -1
- package/dist/esm/common/wrap/wrap-mutation.js +2 -3
- package/dist/esm/common/wrap/wrap-promise.js +3 -4
- package/dist/esm/common/wrap/wrap-xhr.js +23 -27
- package/dist/esm/features/ajax/aggregate/index.js +5 -7
- package/dist/esm/features/ajax/instrument/distributed-tracing.js +8 -12
- package/dist/esm/features/ajax/instrument/index.js +67 -25
- package/dist/esm/features/jserrors/aggregate/canonical-function-name.js +0 -1
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +4 -4
- package/dist/esm/features/jserrors/aggregate/index.js +4 -5
- package/dist/esm/features/metrics/aggregate/framework-detection.js +103 -7
- package/dist/esm/features/metrics/aggregate/index.js +22 -39
- package/dist/esm/features/metrics/instrument/index.js +1 -3
- package/dist/esm/features/page_action/aggregate/index.js +17 -19
- package/dist/esm/features/page_view_event/aggregate/index.js +1 -2
- package/dist/esm/features/page_view_event/instrument/index.js +4 -2
- package/dist/esm/features/page_view_timing/aggregate/index.js +7 -8
- package/dist/esm/features/session_replay/aggregate/index.js +4 -2
- package/dist/esm/features/session_trace/aggregate/index.js +22 -16
- package/dist/esm/features/spa/aggregate/index.js +14 -20
- package/dist/esm/features/spa/aggregate/interaction.js +0 -2
- package/dist/esm/features/spa/aggregate/serializer.js +1 -1
- package/dist/esm/features/utils/aggregate-base.js +4 -0
- package/dist/esm/features/utils/handler-cache.js +3 -1
- package/dist/esm/features/utils/instrument-base.js +24 -6
- package/dist/esm/loaders/agent-base.js +23 -0
- package/dist/esm/loaders/agent.js +7 -7
- package/dist/esm/loaders/api/api.js +34 -4
- package/dist/esm/loaders/api/apiAsync.js +19 -20
- package/dist/esm/loaders/api/interaction-types.js +11 -4
- package/dist/esm/loaders/configure/configure.js +3 -0
- package/dist/esm/loaders/features/enabled-features.js +1 -1
- package/dist/esm/loaders/micro-agent.js +21 -4
- 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/runtime.d.ts +1 -1
- package/dist/types/common/constants/runtime.d.ts.map +1 -1
- package/dist/types/common/event-emitter/contextual-ee.d.ts +22 -2
- package/dist/types/common/event-emitter/contextual-ee.d.ts.map +1 -1
- package/dist/types/common/event-emitter/event-context.d.ts +5 -0
- package/dist/types/common/event-emitter/event-context.d.ts.map +1 -0
- package/dist/types/common/event-emitter/register-handler.d.ts +1 -1
- 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/bundle-id.d.ts +5 -0
- package/dist/types/common/ids/bundle-id.d.ts.map +1 -0
- package/dist/types/common/session/session-entity.d.ts +12 -15
- package/dist/types/common/session/session-entity.d.ts.map +1 -1
- package/dist/types/common/storage/first-party-cookies.d.ts +1 -1
- package/dist/types/common/storage/first-party-cookies.d.ts.map +1 -1
- package/dist/types/common/storage/local-storage.d.ts.map +1 -1
- package/dist/types/common/timer/interaction-timer.d.ts +3 -0
- package/dist/types/common/timer/interaction-timer.d.ts.map +1 -1
- package/dist/types/common/unload/eol.d.ts +1 -2
- package/dist/types/common/unload/eol.d.ts.map +1 -1
- package/dist/types/common/util/feature-flags.d.ts.map +1 -1
- package/dist/types/common/util/obfuscate.d.ts.map +1 -1
- package/dist/types/common/util/traverse.d.ts.map +1 -1
- package/dist/types/common/window/nreum.d.ts +2 -2
- package/dist/types/common/window/page-visibility.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-events.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-function.d.ts +1 -19
- package/dist/types/common/wrap/wrap-function.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-xhr.d.ts.map +1 -1
- package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/ajax/instrument/distributed-tracing.d.ts +1 -1
- package/dist/types/features/ajax/instrument/distributed-tracing.d.ts.map +1 -1
- package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/metrics/aggregate/framework-detection.d.ts.map +1 -1
- package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/metrics/instrument/index.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.map +1 -1
- package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/aggregate/index.d.ts +5 -0
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/spa/aggregate/interaction.d.ts.map +1 -1
- package/dist/types/features/utils/aggregate-base.d.ts +1 -0
- package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
- package/dist/types/features/utils/handler-cache.d.ts.map +1 -1
- package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
- package/dist/types/loaders/agent-base.d.ts +15 -0
- package/dist/types/loaders/agent-base.d.ts.map +1 -1
- package/dist/types/loaders/agent.d.ts +1 -1
- package/dist/types/loaders/agent.d.ts.map +1 -1
- package/dist/types/loaders/api/api.d.ts +7 -0
- 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/api/interaction-types.d.ts +18 -7
- package/dist/types/loaders/api/interaction-types.d.ts.map +1 -1
- package/dist/types/loaders/configure/configure.d.ts +2 -0
- package/dist/types/loaders/configure/configure.d.ts.map +1 -1
- package/dist/types/loaders/features/features.d.ts +9 -9
- package/dist/types/loaders/micro-agent.d.ts +7 -1
- package/dist/types/loaders/micro-agent.d.ts.map +1 -1
- package/package.json +62 -38
- package/src/common/aggregate/aggregator.test.js +107 -0
- package/src/common/config/state/configurable.test.js +73 -0
- package/src/common/config/state/info.test.js +31 -0
- package/src/common/config/state/init.js +13 -12
- package/src/common/config/state/init.test.js +28 -0
- package/src/common/config/state/loader-config.test.js +21 -0
- package/src/common/config/state/runtime.js +0 -2
- package/src/common/config/state/runtime.test.js +21 -0
- package/src/common/constants/__mocks__/runtime.js +1 -1
- package/src/common/constants/runtime.js +1 -1
- package/src/common/constants/runtime.test.js +2 -2
- package/src/common/constants/shared-channel.js +1 -1
- package/src/common/deny-list/deny-list.js +3 -11
- package/src/common/deny-list/deny-list.test.js +103 -30
- package/src/common/drain/drain.js +1 -1
- package/src/common/drain/drain.test.js +74 -0
- package/src/common/event-emitter/{contextual-ee.test.js → contextual-ee.component-test.js} +15 -32
- package/src/common/event-emitter/contextual-ee.js +26 -37
- package/src/common/event-emitter/event-context.js +5 -0
- package/src/common/harvest/harvest-scheduler.js +2 -5
- package/src/common/harvest/harvest-scheduler.test.js +2 -6
- package/src/common/harvest/harvest.js +4 -7
- package/src/common/harvest/harvest.test.js +1 -3
- package/src/common/ids/__mocks__/bundle-id.js +2 -0
- package/src/common/ids/__mocks__/unique-id.js +17 -0
- package/src/common/ids/bundle-id.js +13 -0
- package/src/common/ids/id.test.js +6 -6
- package/src/common/serialize/bel-serializer.js +1 -1
- package/src/common/session/session-entity.component-test.js +3 -2
- package/src/common/session/session-entity.js +11 -9
- package/src/common/storage/first-party-cookies.js +5 -4
- package/src/common/storage/local-storage.js +3 -2
- package/src/common/timer/interaction-timer.component-test.js +52 -7
- package/src/common/timer/interaction-timer.js +15 -6
- package/src/common/timer/timer.test.js +0 -1
- package/src/common/timing/nav-timing.js +1 -1
- package/src/common/unload/eol.js +5 -31
- package/src/common/url/__mocks__/parse-url.js +15 -0
- package/src/common/url/{encode.component-test.js → encode.test.js} +1 -0
- package/src/common/util/__mocks__/get-or-set.js +5 -0
- package/src/common/util/__mocks__/invoke.js +1 -0
- package/src/common/util/data-size.test.js +0 -1
- package/src/common/util/feature-flags.js +15 -17
- package/src/common/util/feature-flags.test.js +4 -8
- package/src/common/util/invoke.js +1 -1
- package/src/common/util/obfuscate.js +3 -5
- package/src/common/util/submit-data.test.js +1 -1
- package/src/common/util/traverse.js +1 -0
- package/src/common/window/__mocks__/nreum.js +12 -0
- package/src/common/window/page-visibility.js +1 -2
- package/src/common/wrap/wrap-events.js +4 -3
- package/src/common/wrap/wrap-fetch.js +2 -4
- package/src/common/wrap/wrap-function.js +16 -44
- package/src/common/wrap/wrap-jsonp.js +1 -1
- package/src/common/wrap/wrap-mutation.js +2 -3
- package/src/common/wrap/{wrap-promise.test.js → wrap-promise.component-test.js} +2 -32
- package/src/common/wrap/wrap-promise.js +3 -4
- package/src/common/wrap/wrap-xhr.js +24 -28
- package/src/features/ajax/aggregate/index.js +5 -7
- package/src/features/ajax/instrument/distributed-tracing.js +8 -12
- package/src/features/ajax/instrument/distributed-tracing.test.js +375 -0
- package/src/features/ajax/instrument/index.js +62 -27
- package/src/features/jserrors/aggregate/canonical-function-name.js +0 -2
- package/src/features/jserrors/aggregate/compute-stack-trace.js +4 -4
- package/src/features/jserrors/aggregate/compute-stack-trace.test.js +1 -1
- package/src/features/jserrors/aggregate/index.js +4 -5
- package/src/features/metrics/aggregate/framework-detection.js +129 -8
- package/src/features/metrics/aggregate/framework-detection.test.js +213 -82
- package/src/features/metrics/aggregate/index.js +22 -45
- package/src/features/metrics/instrument/index.js +1 -3
- package/src/features/page_action/aggregate/index.js +12 -13
- package/src/features/page_view_event/aggregate/index.js +1 -2
- package/src/features/page_view_event/instrument/index.js +2 -2
- package/src/features/page_view_timing/aggregate/index.js +7 -8
- package/src/features/session_replay/aggregate/index.component-test.js +3 -15
- package/src/features/session_replay/aggregate/index.js +4 -2
- package/src/features/session_trace/aggregate/index.js +22 -16
- package/src/features/spa/aggregate/index.js +14 -20
- package/src/features/spa/aggregate/interaction.js +0 -2
- package/src/features/spa/aggregate/serializer.js +1 -1
- package/src/features/utils/aggregate-base.js +5 -0
- package/src/features/utils/aggregate-base.test.js +2 -1
- package/src/features/utils/handler-cache.js +3 -2
- package/src/features/utils/instrument-base.js +25 -6
- package/src/features/utils/instrument-base.test.js +2 -2
- package/src/loaders/agent-base.js +23 -0
- package/src/loaders/agent.js +7 -7
- package/src/loaders/api/api.component-test.js +45 -0
- package/src/loaders/api/api.js +34 -4
- package/src/loaders/api/api.test.js +85 -0
- package/src/loaders/api/apiAsync.js +19 -20
- package/src/loaders/api/apiAsync.test.js +17 -0
- package/src/loaders/api/interaction-types.js +11 -4
- package/src/loaders/configure/configure.js +3 -0
- package/src/loaders/features/enabled-features.js +1 -1
- package/src/loaders/micro-agent.js +22 -4
- package/dist/cjs/features/metrics/aggregate/endpoint-map.js +0 -14
- package/dist/cjs/features/metrics/aggregate/polyfill-detection.es5.js +0 -14
- package/dist/cjs/features/metrics/aggregate/polyfill-detection.js +0 -53
- package/dist/esm/features/metrics/aggregate/endpoint-map.js +0 -7
- package/dist/esm/features/metrics/aggregate/polyfill-detection.es5.js +0 -8
- package/dist/esm/features/metrics/aggregate/polyfill-detection.js +0 -47
- package/dist/types/features/metrics/aggregate/endpoint-map.d.ts +0 -8
- package/dist/types/features/metrics/aggregate/endpoint-map.d.ts.map +0 -1
- package/dist/types/features/metrics/aggregate/polyfill-detection.d.ts +0 -6
- package/dist/types/features/metrics/aggregate/polyfill-detection.d.ts.map +0 -1
- package/dist/types/features/metrics/aggregate/polyfill-detection.es5.d.ts +0 -7
- package/dist/types/features/metrics/aggregate/polyfill-detection.es5.d.ts.map +0 -1
- package/src/features/metrics/aggregate/endpoint-map.js +0 -7
- package/src/features/metrics/aggregate/polyfill-detection.es5.js +0 -8
- package/src/features/metrics/aggregate/polyfill-detection.es5.test.js +0 -16
- package/src/features/metrics/aggregate/polyfill-detection.js +0 -48
- package/src/features/metrics/aggregate/polyfill-detection.test.js +0 -163
- /package/src/common/url/{protocol.component-test.js → protocol.test.js} +0 -0
|
@@ -42,10 +42,8 @@ export class SessionEntity {
|
|
|
42
42
|
* expiresMs and inactiveMs are used to "expire" the session, but can be overridden in the constructor. Pass 0 to disable expiration timers.
|
|
43
43
|
*/
|
|
44
44
|
constructor (opts) {
|
|
45
|
-
|
|
46
|
-
}
|
|
45
|
+
const { agentIdentifier, key, storage } = opts
|
|
47
46
|
|
|
48
|
-
setup ({ agentIdentifier, key, storage, value = generateRandomHexString(16), expiresMs = DEFAULT_EXPIRES_MS, inactiveMs = DEFAULT_INACTIVE_MS }) {
|
|
49
47
|
if (!agentIdentifier || !key || !storage) {
|
|
50
48
|
throw new Error(`Missing required field(s):${!agentIdentifier ? ' agentID' : ''}${!key ? ' key' : ''}${!storage ? ' storage' : ''}`)
|
|
51
49
|
}
|
|
@@ -53,20 +51,24 @@ export class SessionEntity {
|
|
|
53
51
|
this.storage = storage
|
|
54
52
|
this.state = {}
|
|
55
53
|
|
|
56
|
-
this.sync(model)
|
|
57
|
-
|
|
58
54
|
// key is intended to act as the k=v pair
|
|
59
55
|
this.key = key
|
|
56
|
+
|
|
57
|
+
this.ee = ee.get(agentIdentifier)
|
|
58
|
+
wrapEvents(this.ee)
|
|
59
|
+
this.setup(opts)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setup ({ value = generateRandomHexString(16), expiresMs = DEFAULT_EXPIRES_MS, inactiveMs = DEFAULT_INACTIVE_MS }) {
|
|
63
|
+
this.state = {}
|
|
64
|
+
this.sync(model)
|
|
65
|
+
|
|
60
66
|
// value is intended to act as the primary value of the k=v pair
|
|
61
67
|
this.state.value = value
|
|
62
68
|
|
|
63
69
|
this.expiresMs = expiresMs
|
|
64
70
|
this.inactiveMs = inactiveMs
|
|
65
71
|
|
|
66
|
-
this.ee = ee.get(agentIdentifier)
|
|
67
|
-
|
|
68
|
-
wrapEvents(this.ee)
|
|
69
|
-
|
|
70
72
|
// the first time the session entity class is instantiated, we check the storage API for an existing
|
|
71
73
|
// object. If it exists, the values inside the object are used to inform the timers that run locally.
|
|
72
74
|
// if the initial read is empty, it allows us to set a "fresh" "new" session immediately.
|
|
@@ -8,24 +8,25 @@ export class FirstPartyCookies {
|
|
|
8
8
|
var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'))
|
|
9
9
|
if (match) return match[2]
|
|
10
10
|
} catch (err) {
|
|
11
|
+
// Error is ignored
|
|
11
12
|
return ''
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
set (key, value) {
|
|
16
17
|
try {
|
|
17
|
-
const cookie = `${key}=${value}; Domain=${domain}; Path=/`
|
|
18
|
+
const cookie = `${key}=${value}; Domain=${this.domain}; Path=/`
|
|
18
19
|
document.cookie = cookie
|
|
19
20
|
} catch (err) {
|
|
20
|
-
|
|
21
|
+
// Error is ignored
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
remove (key) {
|
|
25
26
|
try {
|
|
26
|
-
|
|
27
|
+
document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; Domain=${this.domain}; Path=/`
|
|
27
28
|
} catch (err) {
|
|
28
|
-
|
|
29
|
+
// Error is ignored
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
}
|
|
@@ -5,6 +5,7 @@ export class LocalStorage {
|
|
|
5
5
|
// Cast it back to undefined if it doesnt exist
|
|
6
6
|
return localStorage.getItem(key) || undefined
|
|
7
7
|
} catch (err) {
|
|
8
|
+
// Error is ignored
|
|
8
9
|
return ''
|
|
9
10
|
}
|
|
10
11
|
}
|
|
@@ -14,7 +15,7 @@ export class LocalStorage {
|
|
|
14
15
|
if (value === undefined || value === null) return this.remove(key)
|
|
15
16
|
return localStorage.setItem(key, value)
|
|
16
17
|
} catch (err) {
|
|
17
|
-
|
|
18
|
+
// Error is ignored
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -22,7 +23,7 @@ export class LocalStorage {
|
|
|
22
23
|
try {
|
|
23
24
|
localStorage.removeItem(key)
|
|
24
25
|
} catch (err) {
|
|
25
|
-
|
|
26
|
+
// Error is ignored
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
}
|
|
@@ -41,29 +41,25 @@ describe('constructor', () => {
|
|
|
41
41
|
})
|
|
42
42
|
|
|
43
43
|
test('refresh type timers set event listeners', () => {
|
|
44
|
-
// eslint-disable-next-line
|
|
45
44
|
let ee = { on: jest.fn().mockImplementation((evt, cb) => { cb([{ type: 'click' }]) }) }
|
|
46
45
|
let it = new InteractionTimer({ onEnd: jest.fn(), onRefresh: jest.fn(), ee }, 100)
|
|
47
46
|
// scroll, keypress, click
|
|
48
47
|
expect(ee.on).toHaveBeenCalledTimes(1)
|
|
49
48
|
expect(it.onRefresh).toHaveBeenCalledTimes(1)
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
ee = { on: jest.fn().mockImplementation((evt, cb) => { cb([{ type: 'scroll' }]) }) }
|
|
50
|
+
ee = { on: jest.fn().mockImplementation((evt, cb) => { cb([{ type: 'scroll' }]) }) }
|
|
53
51
|
it = new InteractionTimer({ onEnd: jest.fn(), onRefresh: jest.fn(), ee }, 100)
|
|
54
52
|
// scroll, keypress, click
|
|
55
53
|
expect(ee.on).toHaveBeenCalledTimes(1)
|
|
56
54
|
expect(it.onRefresh).toHaveBeenCalledTimes(1)
|
|
57
55
|
|
|
58
|
-
|
|
59
|
-
ee = { on: jest.fn().mockImplementation((evt, cb) => { cb([{ type: 'keydown' }]) }) }
|
|
56
|
+
ee = { on: jest.fn().mockImplementation((evt, cb) => { cb([{ type: 'keydown' }]) }) }
|
|
60
57
|
it = new InteractionTimer({ onEnd: jest.fn(), onRefresh: jest.fn(), ee }, 100)
|
|
61
58
|
// scroll, keypress, click
|
|
62
59
|
expect(ee.on).toHaveBeenCalledTimes(1)
|
|
63
60
|
expect(it.onRefresh).toHaveBeenCalledTimes(1)
|
|
64
61
|
|
|
65
62
|
const aelSpy = jest.spyOn(document, 'addEventListener')
|
|
66
|
-
// eslint-disable-next-line
|
|
67
63
|
ee = { on: jest.fn().mockImplementation((evt, cb) => { cb([{ type: 'keydown' }]) }) }
|
|
68
64
|
it = new InteractionTimer({ onEnd: jest.fn(), onRefresh: jest.fn(), ee }, 100)
|
|
69
65
|
// visibility change
|
|
@@ -81,7 +77,6 @@ describe('create()', () => {
|
|
|
81
77
|
})
|
|
82
78
|
|
|
83
79
|
test('Create can fallback to use defaults', () => {
|
|
84
|
-
let called = 0
|
|
85
80
|
const timer1 = new InteractionTimer({ onEnd: jest.fn() }, 100)
|
|
86
81
|
timer1.create()
|
|
87
82
|
|
|
@@ -136,6 +131,26 @@ describe('pause()', () => {
|
|
|
136
131
|
})
|
|
137
132
|
})
|
|
138
133
|
|
|
134
|
+
describe('resume()', () => {
|
|
135
|
+
test('resume allows the callback continue firing', () => {
|
|
136
|
+
const timer = new InteractionTimer({ onEnd: jest.fn() }, 100)
|
|
137
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0)
|
|
138
|
+
timer.pause()
|
|
139
|
+
jest.advanceTimersByTime(150)
|
|
140
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0)
|
|
141
|
+
timer.resume()
|
|
142
|
+
jest.advanceTimersByTime(150)
|
|
143
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(1)
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
test('resume fires the refresh callback', () => {
|
|
147
|
+
const timer = new InteractionTimer({ onEnd: jest.fn(), onRefresh: jest.fn() }, 100)
|
|
148
|
+
timer.pause()
|
|
149
|
+
timer.resume()
|
|
150
|
+
expect(timer.onRefresh).toHaveBeenCalledTimes(1)
|
|
151
|
+
})
|
|
152
|
+
})
|
|
153
|
+
|
|
139
154
|
describe('clear()', () => {
|
|
140
155
|
test('clear prevents the callback from firing and deletes the pointer', () => {
|
|
141
156
|
const timer = new InteractionTimer({ onEnd: jest.fn() }, 100)
|
|
@@ -165,3 +180,33 @@ describe('isValid', () => {
|
|
|
165
180
|
expect(timer.isValid()).toEqual(false)
|
|
166
181
|
})
|
|
167
182
|
})
|
|
183
|
+
|
|
184
|
+
describe('abort()', () => {
|
|
185
|
+
test('should unregister the event emitter listener', () => {
|
|
186
|
+
const ee = { on: jest.fn(), removeEventListener: jest.fn() }
|
|
187
|
+
const it = new InteractionTimer({ onEnd: jest.fn(), onRefresh: jest.fn(), ee }, 100)
|
|
188
|
+
|
|
189
|
+
it.abort()
|
|
190
|
+
|
|
191
|
+
expect(ee.on).toHaveBeenCalledTimes(1)
|
|
192
|
+
expect(ee.on).toHaveBeenCalledWith('fn-end', expect.any(Function))
|
|
193
|
+
|
|
194
|
+
expect(ee.removeEventListener).toHaveBeenCalledTimes(1)
|
|
195
|
+
expect(ee.removeEventListener).toHaveBeenCalledWith('fn-end', expect.any(Function))
|
|
196
|
+
|
|
197
|
+
// Verify the same function is passed to both methods
|
|
198
|
+
expect(jest.mocked(ee.on).mock.calls[0][1]).toEqual(jest.mocked(ee.removeEventListener).mock.calls[0][1])
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
test('should not attempt to unregister the event emitter listener when an event emitter was not supplied', () => {
|
|
202
|
+
const it = new InteractionTimer({ onEnd: jest.fn(), onRefresh: jest.fn() }, 100)
|
|
203
|
+
|
|
204
|
+
expect(it.ee).toBeUndefined()
|
|
205
|
+
expect(it.refreshHandler).toBeUndefined()
|
|
206
|
+
|
|
207
|
+
it.abort()
|
|
208
|
+
|
|
209
|
+
expect(it.ee).toBeUndefined()
|
|
210
|
+
expect(it.refreshHandler).toBeUndefined()
|
|
211
|
+
})
|
|
212
|
+
})
|
|
@@ -24,12 +24,14 @@ export class InteractionTimer extends Timer {
|
|
|
24
24
|
|
|
25
25
|
if (isBrowserScope && opts.ee) {
|
|
26
26
|
if (opts.ee) {
|
|
27
|
+
this.ee = opts.ee
|
|
27
28
|
const debouncedRefresh = debounce(this.refresh.bind(this), 500, { leading: true })
|
|
28
|
-
|
|
29
|
+
this.refreshHandler = (evts) => {
|
|
29
30
|
if (opts.refreshEvents.includes(evts?.[0]?.type)) {
|
|
30
31
|
debouncedRefresh()
|
|
31
32
|
}
|
|
32
|
-
}
|
|
33
|
+
}
|
|
34
|
+
opts.ee.on('fn-end', this.refreshHandler)
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
// watch for the vis state changing. If the page is hidden, the local inactivity timer should be paused
|
|
@@ -43,10 +45,7 @@ export class InteractionTimer extends Timer {
|
|
|
43
45
|
subscribeToVisibilityChange((state) => {
|
|
44
46
|
if (state === 'hidden') this.pause()
|
|
45
47
|
// vis change --> visible is treated like a new interaction with the page
|
|
46
|
-
else
|
|
47
|
-
this.refresh()
|
|
48
|
-
this.onResume() // emit resume event after state updated
|
|
49
|
-
}
|
|
48
|
+
else this.resume()
|
|
50
49
|
}, false, false, this.abortController?.signal)
|
|
51
50
|
}
|
|
52
51
|
}
|
|
@@ -54,6 +53,11 @@ export class InteractionTimer extends Timer {
|
|
|
54
53
|
abort () {
|
|
55
54
|
this.clear()
|
|
56
55
|
this.abortController?.abort()
|
|
56
|
+
|
|
57
|
+
if (this.refreshHandler) {
|
|
58
|
+
this.ee.removeEventListener('fn-end', this.refreshHandler)
|
|
59
|
+
this.refreshHandler = this.ee = null
|
|
60
|
+
}
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
pause () {
|
|
@@ -62,6 +66,11 @@ export class InteractionTimer extends Timer {
|
|
|
62
66
|
this.remainingMs = this.initialMs - (Date.now() - this.startTimestamp)
|
|
63
67
|
}
|
|
64
68
|
|
|
69
|
+
resume () {
|
|
70
|
+
this.refresh()
|
|
71
|
+
this.onResume() // emit resume event after state updated
|
|
72
|
+
}
|
|
73
|
+
|
|
65
74
|
refresh (cb, ms) {
|
|
66
75
|
this.clear()
|
|
67
76
|
this.timer = this.create(cb, ms)
|
|
@@ -28,7 +28,7 @@ var DOM_CONTENT_LOAD_EVENT = 'domContentLoadedEvent'
|
|
|
28
28
|
export var navTimingValues = []
|
|
29
29
|
|
|
30
30
|
function getPntType (type) {
|
|
31
|
-
if (typeof type
|
|
31
|
+
if (typeof type === 'number') return type
|
|
32
32
|
const types = {
|
|
33
33
|
navigate: undefined,
|
|
34
34
|
reload: 1,
|
package/src/common/unload/eol.js
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { windowAddEventListener } from '../event-listener/event-listener-opts'
|
|
6
|
-
import {
|
|
7
|
-
import { ffVersion, globalScope, isWorkerScope, isBrowserScope } from '../constants/runtime'
|
|
6
|
+
import { globalScope, isWorkerScope, isBrowserScope } from '../constants/runtime'
|
|
8
7
|
import { subscribeToVisibilityChange } from '../window/page-visibility'
|
|
9
8
|
|
|
10
9
|
if (isWorkerScope) {
|
|
@@ -23,37 +22,12 @@ if (isWorkerScope) {
|
|
|
23
22
|
* Subscribes a provided callback to the time/event when the agent should treat it as end-of-life.
|
|
24
23
|
* This is used, for example, to submit a final harvest and send all remaining data on best-effort.
|
|
25
24
|
* @param {function} cb - func to run before or during the last reliable event or time of an env's life span
|
|
26
|
-
* @param {boolean} allowBFCache - (temp) feature flag to gate new v1222 BFC support
|
|
27
25
|
*/
|
|
28
|
-
export function subscribeToEOL (cb
|
|
26
|
+
export function subscribeToEOL (cb) {
|
|
29
27
|
if (isBrowserScope) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// --this ought to be removed once support for version below 14.5 phases out
|
|
34
|
-
} else {
|
|
35
|
-
var oneCall = single(cb)
|
|
36
|
-
|
|
37
|
-
// Firefox has a bug wherein a slow-loading resource loaded from the 'pagehide'
|
|
38
|
-
// or 'unload' event will delay the 'load' event firing on the next page load.
|
|
39
|
-
// In Firefox versions that support sendBeacon, this doesn't matter, because
|
|
40
|
-
// we'll use it instead of an image load for our final harvest.
|
|
41
|
-
//
|
|
42
|
-
// Some Safari versions never fire the 'unload' event for pages that are being
|
|
43
|
-
// put into the WebKit page cache, so we *need* to use the pagehide event for
|
|
44
|
-
// the final submission from Safari.
|
|
45
|
-
//
|
|
46
|
-
// Generally speaking, we will try to submit our final harvest from either
|
|
47
|
-
// pagehide or unload, whichever comes first, but in Firefox, we need to avoid
|
|
48
|
-
// attempting to submit from pagehide to ensure that we don't slow down loading
|
|
49
|
-
// of the next page.
|
|
50
|
-
if (!ffVersion || navigator.sendBeacon) {
|
|
51
|
-
windowAddEventListener('pagehide', oneCall)
|
|
52
|
-
} else {
|
|
53
|
-
windowAddEventListener('beforeunload', oneCall)
|
|
54
|
-
}
|
|
55
|
-
windowAddEventListener('unload', oneCall)
|
|
56
|
-
}
|
|
28
|
+
subscribeToVisibilityChange(cb, true) // when user switches tab or hides window, esp. mobile scenario
|
|
29
|
+
windowAddEventListener('pagehide', cb) // when user navigates away, and because safari iOS v14.4- doesn't fully support vis change
|
|
30
|
+
// --this ought to be removed once support for version below 14.5 phases out
|
|
57
31
|
} else if (isWorkerScope) {
|
|
58
32
|
globalScope.cleanupTasks.push(cb) // close() should run these tasks before quitting thread
|
|
59
33
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function parseUrl (url) {
|
|
2
|
+
try {
|
|
3
|
+
const result = new URL(url)
|
|
4
|
+
|
|
5
|
+
return {
|
|
6
|
+
hostname: result.hostname,
|
|
7
|
+
port: result.port || result.protocol.startsWith('https') ? '443' : '80',
|
|
8
|
+
pathname: result.pathname,
|
|
9
|
+
protocol: result.protocol.replace(':', ''),
|
|
10
|
+
sameOrigin: false
|
|
11
|
+
}
|
|
12
|
+
} catch (err) {
|
|
13
|
+
return {}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const single = jest.fn(cb => cb)
|
|
@@ -47,7 +47,6 @@ describe('dataSize', () => {
|
|
|
47
47
|
const input = {
|
|
48
48
|
[faker.datatype.uuid()]: faker.lorem.sentence()
|
|
49
49
|
}
|
|
50
|
-
const expectedSize = faker.datatype.number({ min: 1000, max: 10000 })
|
|
51
50
|
|
|
52
51
|
jest.spyOn(stringifyModule, 'stringify').mockImplementation(() => { throw new Error(faker.lorem.sentence()) })
|
|
53
52
|
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { ee } from '../event-emitter/contextual-ee'
|
|
6
6
|
import { handle } from '../event-emitter/handle'
|
|
7
|
-
import { drain } from '../drain/drain'
|
|
8
7
|
import { FEATURE_NAMES } from '../../loaders/features/features'
|
|
9
8
|
|
|
10
9
|
const bucketMap = {
|
|
@@ -15,26 +14,25 @@ const bucketMap = {
|
|
|
15
14
|
sr: [FEATURE_NAMES.sessionReplay, FEATURE_NAMES.sessionTrace]
|
|
16
15
|
}
|
|
17
16
|
|
|
17
|
+
const sentIds = new Set()
|
|
18
|
+
|
|
18
19
|
/** Note that this function only processes each unique flag ONCE, with the first occurrence of each flag and numeric value determining its switch on/off setting. */
|
|
19
20
|
export function activateFeatures (flags, agentIdentifier) {
|
|
20
21
|
const sharedEE = ee.get(agentIdentifier)
|
|
21
22
|
if (!(flags && typeof flags === 'object')) return
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
activatedFeatures[flag] = Boolean(num)
|
|
37
|
-
})
|
|
24
|
+
if (!sentIds.has(agentIdentifier)) {
|
|
25
|
+
Object.entries(flags).forEach(([flag, num]) => {
|
|
26
|
+
if (bucketMap[flag]) {
|
|
27
|
+
bucketMap[flag].forEach(feat => {
|
|
28
|
+
if (!num) handle('block-' + flag, [], undefined, feat, sharedEE)
|
|
29
|
+
else handle('feat-' + flag, [], undefined, feat, sharedEE)
|
|
30
|
+
handle('rumresp-' + flag, [Boolean(num)], undefined, feat, sharedEE) // this is a duplicate of feat-/block- but makes awaiting for 1 event easier than 2
|
|
31
|
+
})
|
|
32
|
+
} else if (num) handle('feat-' + flag, [], undefined, undefined, sharedEE) // not sure what other flags are overlooked, but there's a test for ones not in the map --
|
|
33
|
+
activatedFeatures[flag] = Boolean(num)
|
|
34
|
+
})
|
|
35
|
+
}
|
|
38
36
|
|
|
39
37
|
// Let the features waiting on their respective flags know that RUM response was received and that any missing flags are interpreted as bad entitlement / "off".
|
|
40
38
|
// Hence, those features will not be hanging forever if their flags aren't included in the response.
|
|
@@ -44,7 +42,7 @@ export function activateFeatures (flags, agentIdentifier) {
|
|
|
44
42
|
activatedFeatures[flag] = false
|
|
45
43
|
}
|
|
46
44
|
})
|
|
47
|
-
|
|
45
|
+
sentIds.add(agentIdentifier)
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
export const activatedFeatures = {}
|
|
@@ -48,7 +48,7 @@ const bucketMap = {
|
|
|
48
48
|
|
|
49
49
|
test('emits the right events when feature flag = 1', () => {
|
|
50
50
|
const flags = {}
|
|
51
|
-
Object.keys(bucketMap).forEach(flag => flags[flag] = 1)
|
|
51
|
+
Object.keys(bucketMap).forEach(flag => { flags[flag] = 1 })
|
|
52
52
|
activateFeatures(flags, agentIdentifier)
|
|
53
53
|
|
|
54
54
|
const sharedEE = jest.mocked(eventEmitterModule.ee.get).mock.results[0].value
|
|
@@ -57,15 +57,14 @@ test('emits the right events when feature flag = 1', () => {
|
|
|
57
57
|
expect(handleModule.handle).toHaveBeenCalledTimes(14)
|
|
58
58
|
expect(handleModule.handle).toHaveBeenNthCalledWith(1, 'feat-stn', [], undefined, FEATURE_NAMES.sessionTrace, sharedEE)
|
|
59
59
|
expect(handleModule.handle).toHaveBeenLastCalledWith('rumresp-sr', [true], undefined, FEATURE_NAMES.sessionTrace, sharedEE)
|
|
60
|
-
expect(drainModule.drain).toHaveBeenCalledWith(agentIdentifier, 'page_view_event')
|
|
61
60
|
|
|
62
|
-
Object.keys(flags).forEach(flag => flags[flag] = true)
|
|
61
|
+
Object.keys(flags).forEach(flag => { flags[flag] = true })
|
|
63
62
|
expect(activatedFeatures).toEqual(flags)
|
|
64
63
|
})
|
|
65
64
|
|
|
66
65
|
test('emits the right events when feature flag = 0', () => {
|
|
67
66
|
const flags = {}
|
|
68
|
-
Object.keys(bucketMap).forEach(flag => flags[flag] = 0)
|
|
67
|
+
Object.keys(bucketMap).forEach(flag => { flags[flag] = 0 })
|
|
69
68
|
activateFeatures(flags, agentIdentifier)
|
|
70
69
|
|
|
71
70
|
const sharedEE = jest.mocked(eventEmitterModule.ee.get).mock.results[0].value
|
|
@@ -74,9 +73,8 @@ test('emits the right events when feature flag = 0', () => {
|
|
|
74
73
|
expect(handleModule.handle).toHaveBeenCalledTimes(14)
|
|
75
74
|
expect(handleModule.handle).toHaveBeenNthCalledWith(1, 'block-stn', [], undefined, FEATURE_NAMES.sessionTrace, sharedEE)
|
|
76
75
|
expect(handleModule.handle).toHaveBeenLastCalledWith('rumresp-sr', [false], undefined, FEATURE_NAMES.sessionTrace, sharedEE)
|
|
77
|
-
expect(drainModule.drain).toHaveBeenCalledWith(agentIdentifier, 'page_view_event')
|
|
78
76
|
|
|
79
|
-
Object.keys(flags).forEach(flag => flags[flag] = false)
|
|
77
|
+
Object.keys(flags).forEach(flag => { flags[flag] = false })
|
|
80
78
|
expect(activatedFeatures).toEqual(flags)
|
|
81
79
|
})
|
|
82
80
|
|
|
@@ -92,7 +90,5 @@ test('only the first activate of the same feature is respected', () => {
|
|
|
92
90
|
expect(handleModule.handle).toHaveBeenNthCalledWith(1, 'feat-stn', [], undefined, 'session_trace', sharedEE1)
|
|
93
91
|
expect(handleModule.handle).toHaveBeenNthCalledWith(2, 'rumresp-stn', [true], undefined, 'session_trace', sharedEE1)
|
|
94
92
|
expect(handleModule.handle).not.toHaveBeenNthCalledWith(1, 'feat-stn', [], undefined, 'session_trace', sharedEE2)
|
|
95
|
-
expect(drainModule.drain).toHaveBeenCalledWith(agentIdentifier, 'page_view_event')
|
|
96
|
-
expect(drainModule.drain).toHaveBeenCalledTimes(2)
|
|
97
93
|
expect(activatedFeatures.stn).toBeTruthy()
|
|
98
94
|
})
|
|
@@ -26,7 +26,7 @@ export function debounce (func, timeout = 500, options = {}) {
|
|
|
26
26
|
return (...args) => {
|
|
27
27
|
if (leading && timer === undefined) {
|
|
28
28
|
func.apply(this, args)
|
|
29
|
-
timer = setTimeout(() => timer = clearTimeout(timer), timeout)
|
|
29
|
+
timer = setTimeout(() => { timer = clearTimeout(timer) }, timeout)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
if (!leading) {
|
|
@@ -57,11 +57,9 @@ export function validateRules (rules) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
var replacement = rules[i].replacement
|
|
60
|
-
if (replacement) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
invalidReplacementDetected = true
|
|
64
|
-
}
|
|
60
|
+
if (replacement && typeof replacement !== 'string') {
|
|
61
|
+
warn('An obfuscation replacement rule contains a "replacement" value with an invalid type (must be a string)')
|
|
62
|
+
invalidReplacementDetected = true
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
65
|
|
|
@@ -66,7 +66,7 @@ describe('xhr', () => {
|
|
|
66
66
|
this._withCredentials = false
|
|
67
67
|
Object.defineProperty(this, 'withCredentials', {
|
|
68
68
|
get: jest.fn(() => this._withCredentials),
|
|
69
|
-
set: jest.fn((val) => this._withCredentials = val)
|
|
69
|
+
set: jest.fn((val) => { this._withCredentials = val })
|
|
70
70
|
})
|
|
71
71
|
})
|
|
72
72
|
})
|
|
@@ -19,6 +19,7 @@ export function applyFnToProps (obj, fn, type = 'string', ignoreKeys = []) {
|
|
|
19
19
|
if (typeof obj[property] === 'object') {
|
|
20
20
|
applyFnToProps(obj[property], fn, type, ignoreKeys)
|
|
21
21
|
} else {
|
|
22
|
+
// eslint-disable-next-line valid-typeof
|
|
22
23
|
if (typeof obj[property] === type && !ignoreKeys.includes(property)) obj[property] = fn(obj[property])
|
|
23
24
|
}
|
|
24
25
|
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const defaults = {}
|
|
2
|
+
export const gosNREUM = jest.fn(() => ({}))
|
|
3
|
+
export const gosNREUMInfo = jest.fn(() => ({}))
|
|
4
|
+
export const gosNREUMLoaderConfig = jest.fn(() => ({}))
|
|
5
|
+
export const gosNREUMInit = jest.fn(() => ({}))
|
|
6
|
+
export const gosNREUMOriginals = jest.fn(() => ({}))
|
|
7
|
+
export const gosNREUMInitializedAgents = jest.fn(() => ({}))
|
|
8
|
+
export const addToNREUM = jest.fn(() => ({}))
|
|
9
|
+
export const NREUMinitialized = jest.fn(() => ({}))
|
|
10
|
+
export const gosCDN = jest.fn(() => (newrelicGlob))
|
|
11
|
+
|
|
12
|
+
const newrelicGlob = {}
|
|
@@ -12,11 +12,10 @@ import { documentAddEventListener } from '../event-listener/event-listener-opts'
|
|
|
12
12
|
*/
|
|
13
13
|
export function subscribeToVisibilityChange (cb, toHiddenOnly = false, capture, abortSignal) {
|
|
14
14
|
documentAddEventListener('visibilitychange', handleVisibilityChange, capture, abortSignal)
|
|
15
|
-
return
|
|
16
15
|
|
|
17
16
|
function handleVisibilityChange () {
|
|
18
17
|
if (toHiddenOnly) { // trigger cb on change to hidden state only
|
|
19
|
-
if (document.visibilityState
|
|
18
|
+
if (document.visibilityState === 'hidden') cb()
|
|
20
19
|
return
|
|
21
20
|
}
|
|
22
21
|
cb(document.visibilityState)
|
|
@@ -7,15 +7,16 @@
|
|
|
7
7
|
* This module is used directly by: session_trace.
|
|
8
8
|
* It is also called by -> wrapXhr <-, so see "wrap-xhr.js" for features that use this indirectly.
|
|
9
9
|
*/
|
|
10
|
-
import { ee as baseEE } from '../event-emitter/contextual-ee'
|
|
10
|
+
import { ee as baseEE, contextId } from '../event-emitter/contextual-ee'
|
|
11
11
|
import { createWrapperWithEmitter as wfn } from './wrap-function'
|
|
12
12
|
import { getOrSet } from '../util/get-or-set'
|
|
13
13
|
import { globalScope, isBrowserScope } from '../constants/runtime'
|
|
14
14
|
|
|
15
15
|
const wrapped = {}
|
|
16
|
-
const XHR = XMLHttpRequest
|
|
16
|
+
const XHR = globalScope.XMLHttpRequest
|
|
17
17
|
const ADD_EVENT_LISTENER = 'addEventListener'
|
|
18
18
|
const REMOVE_EVENT_LISTENER = 'removeEventListener'
|
|
19
|
+
const flag = `nr@wrapped:${contextId}`
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Wraps `addEventListener` and `removeEventListener` on: global scope; the prototype of `XMLHttpRequest`, and
|
|
@@ -48,7 +49,7 @@ export function wrapEvents (sharedEE) {
|
|
|
48
49
|
return
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
var wrapped = getOrSet(originalListener,
|
|
52
|
+
var wrapped = getOrSet(originalListener, flag, function () {
|
|
52
53
|
var listener = {
|
|
53
54
|
object: wrapHandleEvent,
|
|
54
55
|
function: originalListener
|
|
@@ -6,9 +6,8 @@
|
|
|
6
6
|
* @file Wraps `fetch` and related methods for instrumentation.
|
|
7
7
|
* This module is used by: ajax, spa.
|
|
8
8
|
*/
|
|
9
|
-
import { ee as baseEE } from '../event-emitter/contextual-ee'
|
|
9
|
+
import { ee as baseEE, contextId } from '../event-emitter/contextual-ee'
|
|
10
10
|
import { globalScope } from '../constants/runtime'
|
|
11
|
-
import { flag } from './wrap-function'
|
|
12
11
|
|
|
13
12
|
var prefix = 'fetch-'
|
|
14
13
|
var bodyPrefix = prefix + 'body-'
|
|
@@ -16,7 +15,6 @@ var bodyMethods = ['arrayBuffer', 'blob', 'json', 'text', 'formData']
|
|
|
16
15
|
var Req = globalScope.Request
|
|
17
16
|
var Res = globalScope.Response
|
|
18
17
|
var proto = 'prototype'
|
|
19
|
-
var ctxId = 'nr@context'
|
|
20
18
|
|
|
21
19
|
const wrapped = {}
|
|
22
20
|
|
|
@@ -76,7 +74,7 @@ export function wrapFetch (sharedEE) {
|
|
|
76
74
|
// we are wrapping args in an array so we can preserve the reference
|
|
77
75
|
ee.emit(prefix + 'before-start', [args], ctx)
|
|
78
76
|
var dtPayload
|
|
79
|
-
if (ctx[
|
|
77
|
+
if (ctx[contextId] && ctx[contextId].dt) dtPayload = ctx[contextId].dt
|
|
80
78
|
|
|
81
79
|
var origPromiseFromFetch = fn.apply(this, args)
|
|
82
80
|
|