@openobserve/browser-core 0.2.8
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/LICENSE +201 -0
- package/README.md +3 -0
- package/cjs/boot/init.d.ts +5 -0
- package/cjs/boot/init.js +36 -0
- package/cjs/boot/init.js.map +1 -0
- package/cjs/browser/addEventListener.d.ts +76 -0
- package/cjs/browser/addEventListener.js +52 -0
- package/cjs/browser/addEventListener.js.map +1 -0
- package/cjs/browser/cookie.d.ts +10 -0
- package/cjs/browser/cookie.js +69 -0
- package/cjs/browser/cookie.js.map +1 -0
- package/cjs/browser/fetchObservable.d.ts +23 -0
- package/cjs/browser/fetchObservable.js +74 -0
- package/cjs/browser/fetchObservable.js.map +1 -0
- package/cjs/browser/pageExitObservable.d.ts +14 -0
- package/cjs/browser/pageExitObservable.js +58 -0
- package/cjs/browser/pageExitObservable.js.map +1 -0
- package/cjs/browser/runOnReadyState.d.ts +2 -0
- package/cjs/browser/runOnReadyState.js +15 -0
- package/cjs/browser/runOnReadyState.js.map +1 -0
- package/cjs/browser/types.d.ts +19 -0
- package/cjs/browser/types.js +6 -0
- package/cjs/browser/types.js.map +1 -0
- package/cjs/browser/xhrObservable.d.ts +22 -0
- package/cjs/browser/xhrObservable.js +93 -0
- package/cjs/browser/xhrObservable.js.map +1 -0
- package/cjs/domain/configuration/configuration.d.ts +67 -0
- package/cjs/domain/configuration/configuration.js +95 -0
- package/cjs/domain/configuration/configuration.js.map +1 -0
- package/cjs/domain/configuration/endpointBuilder.d.ts +14 -0
- package/cjs/domain/configuration/endpointBuilder.js +94 -0
- package/cjs/domain/configuration/endpointBuilder.js.map +1 -0
- package/cjs/domain/configuration/index.d.ts +3 -0
- package/cjs/domain/configuration/index.js +25 -0
- package/cjs/domain/configuration/index.js.map +1 -0
- package/cjs/domain/configuration/intakeSites.d.ts +5 -0
- package/cjs/domain/configuration/intakeSites.js +9 -0
- package/cjs/domain/configuration/intakeSites.js.map +1 -0
- package/cjs/domain/configuration/tags.d.ts +4 -0
- package/cjs/domain/configuration/tags.js +39 -0
- package/cjs/domain/configuration/tags.js.map +1 -0
- package/cjs/domain/configuration/transportConfiguration.d.ts +16 -0
- package/cjs/domain/configuration/transportConfiguration.js +42 -0
- package/cjs/domain/configuration/transportConfiguration.js.map +1 -0
- package/cjs/domain/console/consoleObservable.d.ts +11 -0
- package/cjs/domain/console/consoleObservable.js +75 -0
- package/cjs/domain/console/consoleObservable.js.map +1 -0
- package/cjs/domain/deflate/index.d.ts +1 -0
- package/cjs/domain/deflate/index.js +18 -0
- package/cjs/domain/deflate/index.js.map +1 -0
- package/cjs/domain/deflate/types.d.ts +26 -0
- package/cjs/domain/deflate/types.js +3 -0
- package/cjs/domain/deflate/types.js.map +1 -0
- package/cjs/domain/error/error.d.ts +28 -0
- package/cjs/domain/error/error.js +131 -0
- package/cjs/domain/error/error.js.map +1 -0
- package/cjs/domain/error/error.types.d.ts +40 -0
- package/cjs/domain/error/error.types.js +13 -0
- package/cjs/domain/error/error.types.js.map +1 -0
- package/cjs/domain/error/trackRuntimeError.d.ts +5 -0
- package/cjs/domain/error/trackRuntimeError.js +21 -0
- package/cjs/domain/error/trackRuntimeError.js.map +1 -0
- package/cjs/domain/eventRateLimiter/createEventRateLimiter.d.ts +5 -0
- package/cjs/domain/eventRateLimiter/createEventRateLimiter.js +40 -0
- package/cjs/domain/eventRateLimiter/createEventRateLimiter.js.map +1 -0
- package/cjs/domain/report/browser.types.d.ts +24 -0
- package/cjs/domain/report/browser.types.js +3 -0
- package/cjs/domain/report/browser.types.js.map +1 -0
- package/cjs/domain/report/reportObservable.d.ts +15 -0
- package/cjs/domain/report/reportObservable.js +94 -0
- package/cjs/domain/report/reportObservable.js.map +1 -0
- package/cjs/domain/resourceUtils.d.ts +16 -0
- package/cjs/domain/resourceUtils.js +3 -0
- package/cjs/domain/resourceUtils.js.map +1 -0
- package/cjs/domain/session/oldCookiesMigration.d.ts +11 -0
- package/cjs/domain/session/oldCookiesMigration.js +40 -0
- package/cjs/domain/session/oldCookiesMigration.js.map +1 -0
- package/cjs/domain/session/sessionConstants.d.ts +2 -0
- package/cjs/domain/session/sessionConstants.js +7 -0
- package/cjs/domain/session/sessionConstants.js.map +1 -0
- package/cjs/domain/session/sessionManager.d.ts +20 -0
- package/cjs/domain/session/sessionManager.js +65 -0
- package/cjs/domain/session/sessionManager.js.map +1 -0
- package/cjs/domain/session/sessionState.d.ts +11 -0
- package/cjs/domain/session/sessionState.js +45 -0
- package/cjs/domain/session/sessionState.js.map +1 -0
- package/cjs/domain/session/sessionStore.d.ts +34 -0
- package/cjs/domain/session/sessionStore.js +144 -0
- package/cjs/domain/session/sessionStore.js.map +1 -0
- package/cjs/domain/session/sessionStoreOperations.d.ts +15 -0
- package/cjs/domain/session/sessionStoreOperations.js +104 -0
- package/cjs/domain/session/sessionStoreOperations.js.map +1 -0
- package/cjs/domain/session/storeStrategies/sessionInCookie.d.ts +6 -0
- package/cjs/domain/session/storeStrategies/sessionInCookie.js +48 -0
- package/cjs/domain/session/storeStrategies/sessionInCookie.js.map +1 -0
- package/cjs/domain/session/storeStrategies/sessionInLocalStorage.d.ts +3 -0
- package/cjs/domain/session/storeStrategies/sessionInLocalStorage.js +40 -0
- package/cjs/domain/session/storeStrategies/sessionInLocalStorage.js.map +1 -0
- package/cjs/domain/session/storeStrategies/sessionStoreStrategy.d.ts +14 -0
- package/cjs/domain/session/storeStrategies/sessionStoreStrategy.js +5 -0
- package/cjs/domain/session/storeStrategies/sessionStoreStrategy.js.map +1 -0
- package/cjs/domain/synthetics/syntheticsWorkerValues.d.ts +11 -0
- package/cjs/domain/synthetics/syntheticsWorkerValues.js +22 -0
- package/cjs/domain/synthetics/syntheticsWorkerValues.js.map +1 -0
- package/cjs/domain/telemetry/index.d.ts +3 -0
- package/cjs/domain/telemetry/index.js +28 -0
- package/cjs/domain/telemetry/index.js.map +1 -0
- package/cjs/domain/telemetry/rawTelemetryEvent.types.d.ts +11 -0
- package/cjs/domain/telemetry/rawTelemetryEvent.types.js +8 -0
- package/cjs/domain/telemetry/rawTelemetryEvent.types.js.map +1 -0
- package/cjs/domain/telemetry/telemetry.d.ts +112 -0
- package/cjs/domain/telemetry/telemetry.js +146 -0
- package/cjs/domain/telemetry/telemetry.js.map +1 -0
- package/cjs/domain/telemetry/telemetryEvent.types.d.ts +375 -0
- package/cjs/domain/telemetry/telemetryEvent.types.js +7 -0
- package/cjs/domain/telemetry/telemetryEvent.types.js.map +1 -0
- package/cjs/domain/tracekit/computeStackTrace.d.ts +5 -0
- package/cjs/domain/tracekit/computeStackTrace.js +118 -0
- package/cjs/domain/tracekit/computeStackTrace.js.map +1 -0
- package/cjs/domain/tracekit/index.d.ts +3 -0
- package/cjs/domain/tracekit/index.js +8 -0
- package/cjs/domain/tracekit/index.js.map +1 -0
- package/cjs/domain/tracekit/tracekit.d.ts +35 -0
- package/cjs/domain/tracekit/tracekit.js +95 -0
- package/cjs/domain/tracekit/tracekit.js.map +1 -0
- package/cjs/domain/tracekit/types.d.ts +44 -0
- package/cjs/domain/tracekit/types.js +3 -0
- package/cjs/domain/tracekit/types.js.map +1 -0
- package/cjs/domain/user/index.d.ts +2 -0
- package/cjs/domain/user/index.js +19 -0
- package/cjs/domain/user/index.js.map +1 -0
- package/cjs/domain/user/user.d.ts +12 -0
- package/cjs/domain/user/user.js +35 -0
- package/cjs/domain/user/user.js.map +1 -0
- package/cjs/domain/user/user.types.d.ts +6 -0
- package/cjs/domain/user/user.types.js +3 -0
- package/cjs/domain/user/user.types.js.map +1 -0
- package/cjs/index.d.ts +63 -0
- package/cjs/index.js +155 -0
- package/cjs/index.js.map +1 -0
- package/cjs/tools/abstractLifeCycle.d.ts +23 -0
- package/cjs/tools/abstractLifeCycle.js +29 -0
- package/cjs/tools/abstractLifeCycle.js.map +1 -0
- package/cjs/tools/boundedBuffer.d.ts +5 -0
- package/cjs/tools/boundedBuffer.js +22 -0
- package/cjs/tools/boundedBuffer.js.map +1 -0
- package/cjs/tools/catchUserErrors.d.ts +1 -0
- package/cjs/tools/catchUserErrors.js +20 -0
- package/cjs/tools/catchUserErrors.js.map +1 -0
- package/cjs/tools/display.d.ts +35 -0
- package/cjs/tools/display.js +45 -0
- package/cjs/tools/display.js.map +1 -0
- package/cjs/tools/experimentalFeatures.d.ts +24 -0
- package/cjs/tools/experimentalFeatures.js +47 -0
- package/cjs/tools/experimentalFeatures.js.map +1 -0
- package/cjs/tools/getGlobalObject.d.ts +4 -0
- package/cjs/tools/getGlobalObject.js +37 -0
- package/cjs/tools/getGlobalObject.js.map +1 -0
- package/cjs/tools/getZoneJsOriginalValue.d.ts +19 -0
- package/cjs/tools/getZoneJsOriginalValue.js +30 -0
- package/cjs/tools/getZoneJsOriginalValue.js.map +1 -0
- package/cjs/tools/instrumentMethod.d.ts +19 -0
- package/cjs/tools/instrumentMethod.js +83 -0
- package/cjs/tools/instrumentMethod.js.map +1 -0
- package/cjs/tools/matchOption.d.ts +8 -0
- package/cjs/tools/matchOption.js +38 -0
- package/cjs/tools/matchOption.js.map +1 -0
- package/cjs/tools/mergeInto.d.ts +25 -0
- package/cjs/tools/mergeInto.js +105 -0
- package/cjs/tools/mergeInto.js.map +1 -0
- package/cjs/tools/monitor.d.ts +9 -0
- package/cjs/tools/monitor.js +76 -0
- package/cjs/tools/monitor.js.map +1 -0
- package/cjs/tools/observable.d.ts +12 -0
- package/cjs/tools/observable.js +44 -0
- package/cjs/tools/observable.js.map +1 -0
- package/cjs/tools/readBytesFromStream.d.ts +11 -0
- package/cjs/tools/readBytesFromStream.js +64 -0
- package/cjs/tools/readBytesFromStream.js.map +1 -0
- package/cjs/tools/sendToExtension.d.ts +3 -0
- package/cjs/tools/sendToExtension.js +11 -0
- package/cjs/tools/sendToExtension.js.map +1 -0
- package/cjs/tools/serialisation/context.d.ts +6 -0
- package/cjs/tools/serialisation/context.js +3 -0
- package/cjs/tools/serialisation/context.js.map +1 -0
- package/cjs/tools/serialisation/contextManager.d.ts +21 -0
- package/cjs/tools/serialisation/contextManager.js +70 -0
- package/cjs/tools/serialisation/contextManager.js.map +1 -0
- package/cjs/tools/serialisation/heavyCustomerDataWarning.d.ts +8 -0
- package/cjs/tools/serialisation/heavyCustomerDataWarning.js +18 -0
- package/cjs/tools/serialisation/heavyCustomerDataWarning.js.map +1 -0
- package/cjs/tools/serialisation/jsonStringify.d.ts +14 -0
- package/cjs/tools/serialisation/jsonStringify.js +49 -0
- package/cjs/tools/serialisation/jsonStringify.js.map +1 -0
- package/cjs/tools/serialisation/sanitize.d.ts +18 -0
- package/cjs/tools/serialisation/sanitize.js +185 -0
- package/cjs/tools/serialisation/sanitize.js.map +1 -0
- package/cjs/tools/timer.d.ts +5 -0
- package/cjs/tools/timer.js +23 -0
- package/cjs/tools/timer.js.map +1 -0
- package/cjs/tools/utils/arrayUtils.d.ts +1 -0
- package/cjs/tools/utils/arrayUtils.js +11 -0
- package/cjs/tools/utils/arrayUtils.js.map +1 -0
- package/cjs/tools/utils/browserDetection.d.ts +2 -0
- package/cjs/tools/utils/browserDetection.js +12 -0
- package/cjs/tools/utils/browserDetection.js.map +1 -0
- package/cjs/tools/utils/byteUtils.d.ts +4 -0
- package/cjs/tools/utils/byteUtils.js +31 -0
- package/cjs/tools/utils/byteUtils.js.map +1 -0
- package/cjs/tools/utils/functionUtils.d.ts +9 -0
- package/cjs/tools/utils/functionUtils.js +48 -0
- package/cjs/tools/utils/functionUtils.js.map +1 -0
- package/cjs/tools/utils/numberUtils.d.ts +8 -0
- package/cjs/tools/utils/numberUtils.js +24 -0
- package/cjs/tools/utils/numberUtils.js.map +1 -0
- package/cjs/tools/utils/objectUtils.d.ts +10 -0
- package/cjs/tools/utils/objectUtils.js +26 -0
- package/cjs/tools/utils/objectUtils.js.map +1 -0
- package/cjs/tools/utils/polyfills.d.ts +24 -0
- package/cjs/tools/utils/polyfills.js +110 -0
- package/cjs/tools/utils/polyfills.js.map +1 -0
- package/cjs/tools/utils/responseUtils.d.ts +2 -0
- package/cjs/tools/utils/responseUtils.js +18 -0
- package/cjs/tools/utils/responseUtils.js.map +1 -0
- package/cjs/tools/utils/stringUtils.d.ts +7 -0
- package/cjs/tools/utils/stringUtils.js +32 -0
- package/cjs/tools/utils/stringUtils.js.map +1 -0
- package/cjs/tools/utils/timeUtils.d.ts +57 -0
- package/cjs/tools/utils/timeUtils.js +99 -0
- package/cjs/tools/utils/timeUtils.js.map +1 -0
- package/cjs/tools/utils/typeUtils.d.ts +4 -0
- package/cjs/tools/utils/typeUtils.js +17 -0
- package/cjs/tools/utils/typeUtils.js.map +1 -0
- package/cjs/tools/utils/urlPolyfill.d.ts +14 -0
- package/cjs/tools/utils/urlPolyfill.js +92 -0
- package/cjs/tools/utils/urlPolyfill.js.map +1 -0
- package/cjs/tools/valueHistory.d.ts +50 -0
- package/cjs/tools/valueHistory.js +106 -0
- package/cjs/tools/valueHistory.js.map +1 -0
- package/cjs/transport/batch.d.ts +19 -0
- package/cjs/transport/batch.js +79 -0
- package/cjs/transport/batch.js.map +1 -0
- package/cjs/transport/eventBridge.d.ts +12 -0
- package/cjs/transport/eventBridge.js +34 -0
- package/cjs/transport/eventBridge.js.map +1 -0
- package/cjs/transport/flushController.d.ts +48 -0
- package/cjs/transport/flushController.js +97 -0
- package/cjs/transport/flushController.js.map +1 -0
- package/cjs/transport/httpRequest.d.ts +37 -0
- package/cjs/transport/httpRequest.js +91 -0
- package/cjs/transport/httpRequest.js.map +1 -0
- package/cjs/transport/index.d.ts +4 -0
- package/cjs/transport/index.js +13 -0
- package/cjs/transport/index.js.map +1 -0
- package/cjs/transport/sendWithRetryStrategy.d.ts +39 -0
- package/cjs/transport/sendWithRetryStrategy.js +151 -0
- package/cjs/transport/sendWithRetryStrategy.js.map +1 -0
- package/cjs/transport/startBatchWithReplica.d.ts +15 -0
- package/cjs/transport/startBatchWithReplica.js +37 -0
- package/cjs/transport/startBatchWithReplica.js.map +1 -0
- package/esm/boot/init.d.ts +5 -0
- package/esm/boot/init.js +31 -0
- package/esm/boot/init.js.map +1 -0
- package/esm/browser/addEventListener.d.ts +76 -0
- package/esm/browser/addEventListener.js +47 -0
- package/esm/browser/addEventListener.js.map +1 -0
- package/esm/browser/cookie.d.ts +10 -0
- package/esm/browser/cookie.js +61 -0
- package/esm/browser/cookie.js.map +1 -0
- package/esm/browser/fetchObservable.d.ts +23 -0
- package/esm/browser/fetchObservable.js +70 -0
- package/esm/browser/fetchObservable.js.map +1 -0
- package/esm/browser/pageExitObservable.d.ts +14 -0
- package/esm/browser/pageExitObservable.js +53 -0
- package/esm/browser/pageExitObservable.js.map +1 -0
- package/esm/browser/runOnReadyState.d.ts +2 -0
- package/esm/browser/runOnReadyState.js +11 -0
- package/esm/browser/runOnReadyState.js.map +1 -0
- package/esm/browser/types.d.ts +19 -0
- package/esm/browser/types.js +5 -0
- package/esm/browser/types.js.map +1 -0
- package/esm/browser/xhrObservable.d.ts +22 -0
- package/esm/browser/xhrObservable.js +89 -0
- package/esm/browser/xhrObservable.js.map +1 -0
- package/esm/domain/configuration/configuration.d.ts +67 -0
- package/esm/domain/configuration/configuration.js +90 -0
- package/esm/domain/configuration/configuration.js.map +1 -0
- package/esm/domain/configuration/endpointBuilder.d.ts +14 -0
- package/esm/domain/configuration/endpointBuilder.js +90 -0
- package/esm/domain/configuration/endpointBuilder.js.map +1 -0
- package/esm/domain/configuration/index.d.ts +3 -0
- package/esm/domain/configuration/index.js +4 -0
- package/esm/domain/configuration/index.js.map +1 -0
- package/esm/domain/configuration/intakeSites.d.ts +5 -0
- package/esm/domain/configuration/intakeSites.js +6 -0
- package/esm/domain/configuration/intakeSites.js.map +1 -0
- package/esm/domain/configuration/tags.d.ts +4 -0
- package/esm/domain/configuration/tags.js +34 -0
- package/esm/domain/configuration/tags.js.map +1 -0
- package/esm/domain/configuration/transportConfiguration.d.ts +16 -0
- package/esm/domain/configuration/transportConfiguration.js +38 -0
- package/esm/domain/configuration/transportConfiguration.js.map +1 -0
- package/esm/domain/console/consoleObservable.d.ts +11 -0
- package/esm/domain/console/consoleObservable.js +70 -0
- package/esm/domain/console/consoleObservable.js.map +1 -0
- package/esm/domain/deflate/index.d.ts +1 -0
- package/esm/domain/deflate/index.js +2 -0
- package/esm/domain/deflate/index.js.map +1 -0
- package/esm/domain/deflate/types.d.ts +26 -0
- package/esm/domain/deflate/types.js +2 -0
- package/esm/domain/deflate/types.js.map +1 -0
- package/esm/domain/error/error.d.ts +28 -0
- package/esm/domain/error/error.js +121 -0
- package/esm/domain/error/error.js.map +1 -0
- package/esm/domain/error/error.types.d.ts +40 -0
- package/esm/domain/error/error.types.js +10 -0
- package/esm/domain/error/error.types.js.map +1 -0
- package/esm/domain/error/trackRuntimeError.d.ts +5 -0
- package/esm/domain/error/trackRuntimeError.js +17 -0
- package/esm/domain/error/trackRuntimeError.js.map +1 -0
- package/esm/domain/eventRateLimiter/createEventRateLimiter.d.ts +5 -0
- package/esm/domain/eventRateLimiter/createEventRateLimiter.js +36 -0
- package/esm/domain/eventRateLimiter/createEventRateLimiter.js.map +1 -0
- package/esm/domain/report/browser.types.d.ts +24 -0
- package/esm/domain/report/browser.types.js +2 -0
- package/esm/domain/report/browser.types.js.map +1 -0
- package/esm/domain/report/reportObservable.d.ts +15 -0
- package/esm/domain/report/reportObservable.js +90 -0
- package/esm/domain/report/reportObservable.js.map +1 -0
- package/esm/domain/resourceUtils.d.ts +16 -0
- package/esm/domain/resourceUtils.js +2 -0
- package/esm/domain/resourceUtils.js.map +1 -0
- package/esm/domain/session/oldCookiesMigration.d.ts +11 -0
- package/esm/domain/session/oldCookiesMigration.js +36 -0
- package/esm/domain/session/oldCookiesMigration.js.map +1 -0
- package/esm/domain/session/sessionConstants.d.ts +2 -0
- package/esm/domain/session/sessionConstants.js +4 -0
- package/esm/domain/session/sessionConstants.js.map +1 -0
- package/esm/domain/session/sessionManager.d.ts +20 -0
- package/esm/domain/session/sessionManager.js +60 -0
- package/esm/domain/session/sessionManager.js.map +1 -0
- package/esm/domain/session/sessionState.d.ts +11 -0
- package/esm/domain/session/sessionState.js +38 -0
- package/esm/domain/session/sessionState.js.map +1 -0
- package/esm/domain/session/sessionStore.d.ts +34 -0
- package/esm/domain/session/sessionStore.js +139 -0
- package/esm/domain/session/sessionStore.js.map +1 -0
- package/esm/domain/session/sessionStoreOperations.d.ts +15 -0
- package/esm/domain/session/sessionStoreOperations.js +99 -0
- package/esm/domain/session/sessionStoreOperations.js.map +1 -0
- package/esm/domain/session/storeStrategies/sessionInCookie.d.ts +6 -0
- package/esm/domain/session/storeStrategies/sessionInCookie.js +42 -0
- package/esm/domain/session/storeStrategies/sessionInCookie.js.map +1 -0
- package/esm/domain/session/storeStrategies/sessionInLocalStorage.d.ts +3 -0
- package/esm/domain/session/storeStrategies/sessionInLocalStorage.js +35 -0
- package/esm/domain/session/storeStrategies/sessionInLocalStorage.js.map +1 -0
- package/esm/domain/session/storeStrategies/sessionStoreStrategy.d.ts +14 -0
- package/esm/domain/session/storeStrategies/sessionStoreStrategy.js +2 -0
- package/esm/domain/session/storeStrategies/sessionStoreStrategy.js.map +1 -0
- package/esm/domain/synthetics/syntheticsWorkerValues.d.ts +11 -0
- package/esm/domain/synthetics/syntheticsWorkerValues.js +16 -0
- package/esm/domain/synthetics/syntheticsWorkerValues.js.map +1 -0
- package/esm/domain/telemetry/index.d.ts +3 -0
- package/esm/domain/telemetry/index.js +4 -0
- package/esm/domain/telemetry/index.js.map +1 -0
- package/esm/domain/telemetry/rawTelemetryEvent.types.d.ts +11 -0
- package/esm/domain/telemetry/rawTelemetryEvent.types.js +5 -0
- package/esm/domain/telemetry/rawTelemetryEvent.types.js.map +1 -0
- package/esm/domain/telemetry/telemetry.d.ts +112 -0
- package/esm/domain/telemetry/telemetry.js +134 -0
- package/esm/domain/telemetry/telemetry.js.map +1 -0
- package/esm/domain/telemetry/telemetryEvent.types.d.ts +375 -0
- package/esm/domain/telemetry/telemetryEvent.types.js +6 -0
- package/esm/domain/telemetry/telemetryEvent.types.js.map +1 -0
- package/esm/domain/tracekit/computeStackTrace.d.ts +5 -0
- package/esm/domain/tracekit/computeStackTrace.js +114 -0
- package/esm/domain/tracekit/computeStackTrace.js.map +1 -0
- package/esm/domain/tracekit/index.d.ts +3 -0
- package/esm/domain/tracekit/index.js +3 -0
- package/esm/domain/tracekit/index.js.map +1 -0
- package/esm/domain/tracekit/tracekit.d.ts +35 -0
- package/esm/domain/tracekit/tracekit.js +91 -0
- package/esm/domain/tracekit/tracekit.js.map +1 -0
- package/esm/domain/tracekit/types.d.ts +44 -0
- package/esm/domain/tracekit/types.js +2 -0
- package/esm/domain/tracekit/types.js.map +1 -0
- package/esm/domain/user/index.d.ts +2 -0
- package/esm/domain/user/index.js +3 -0
- package/esm/domain/user/index.js.map +1 -0
- package/esm/domain/user/user.d.ts +12 -0
- package/esm/domain/user/user.js +30 -0
- package/esm/domain/user/user.js.map +1 -0
- package/esm/domain/user/user.types.d.ts +6 -0
- package/esm/domain/user/user.types.js +2 -0
- package/esm/domain/user/user.types.js.map +1 -0
- package/esm/index.d.ts +63 -0
- package/esm/index.js +61 -0
- package/esm/index.js.map +1 -0
- package/esm/tools/abstractLifeCycle.d.ts +23 -0
- package/esm/tools/abstractLifeCycle.js +26 -0
- package/esm/tools/abstractLifeCycle.js.map +1 -0
- package/esm/tools/boundedBuffer.d.ts +5 -0
- package/esm/tools/boundedBuffer.js +19 -0
- package/esm/tools/boundedBuffer.js.map +1 -0
- package/esm/tools/catchUserErrors.d.ts +1 -0
- package/esm/tools/catchUserErrors.js +16 -0
- package/esm/tools/catchUserErrors.js.map +1 -0
- package/esm/tools/display.d.ts +35 -0
- package/esm/tools/display.js +41 -0
- package/esm/tools/display.js.map +1 -0
- package/esm/tools/experimentalFeatures.d.ts +24 -0
- package/esm/tools/experimentalFeatures.js +40 -0
- package/esm/tools/experimentalFeatures.js.map +1 -0
- package/esm/tools/getGlobalObject.d.ts +4 -0
- package/esm/tools/getGlobalObject.js +33 -0
- package/esm/tools/getGlobalObject.js.map +1 -0
- package/esm/tools/getZoneJsOriginalValue.d.ts +19 -0
- package/esm/tools/getZoneJsOriginalValue.js +26 -0
- package/esm/tools/getZoneJsOriginalValue.js.map +1 -0
- package/esm/tools/instrumentMethod.d.ts +19 -0
- package/esm/tools/instrumentMethod.js +77 -0
- package/esm/tools/instrumentMethod.js.map +1 -0
- package/esm/tools/matchOption.d.ts +8 -0
- package/esm/tools/matchOption.js +33 -0
- package/esm/tools/matchOption.js.map +1 -0
- package/esm/tools/mergeInto.d.ts +25 -0
- package/esm/tools/mergeInto.js +99 -0
- package/esm/tools/mergeInto.js.map +1 -0
- package/esm/tools/monitor.d.ts +9 -0
- package/esm/tools/monitor.js +66 -0
- package/esm/tools/monitor.js.map +1 -0
- package/esm/tools/observable.d.ts +12 -0
- package/esm/tools/observable.js +40 -0
- package/esm/tools/observable.js.map +1 -0
- package/esm/tools/readBytesFromStream.d.ts +11 -0
- package/esm/tools/readBytesFromStream.js +60 -0
- package/esm/tools/readBytesFromStream.js.map +1 -0
- package/esm/tools/sendToExtension.d.ts +3 -0
- package/esm/tools/sendToExtension.js +7 -0
- package/esm/tools/sendToExtension.js.map +1 -0
- package/esm/tools/serialisation/context.d.ts +6 -0
- package/esm/tools/serialisation/context.js +2 -0
- package/esm/tools/serialisation/context.js.map +1 -0
- package/esm/tools/serialisation/contextManager.d.ts +21 -0
- package/esm/tools/serialisation/contextManager.js +66 -0
- package/esm/tools/serialisation/contextManager.js.map +1 -0
- package/esm/tools/serialisation/heavyCustomerDataWarning.d.ts +8 -0
- package/esm/tools/serialisation/heavyCustomerDataWarning.js +14 -0
- package/esm/tools/serialisation/heavyCustomerDataWarning.js.map +1 -0
- package/esm/tools/serialisation/jsonStringify.d.ts +14 -0
- package/esm/tools/serialisation/jsonStringify.js +44 -0
- package/esm/tools/serialisation/jsonStringify.js.map +1 -0
- package/esm/tools/serialisation/sanitize.d.ts +18 -0
- package/esm/tools/serialisation/sanitize.js +181 -0
- package/esm/tools/serialisation/sanitize.js.map +1 -0
- package/esm/tools/timer.d.ts +5 -0
- package/esm/tools/timer.js +16 -0
- package/esm/tools/timer.js.map +1 -0
- package/esm/tools/utils/arrayUtils.d.ts +1 -0
- package/esm/tools/utils/arrayUtils.js +7 -0
- package/esm/tools/utils/arrayUtils.js.map +1 -0
- package/esm/tools/utils/browserDetection.d.ts +2 -0
- package/esm/tools/utils/browserDetection.js +7 -0
- package/esm/tools/utils/browserDetection.js.map +1 -0
- package/esm/tools/utils/byteUtils.d.ts +4 -0
- package/esm/tools/utils/byteUtils.js +26 -0
- package/esm/tools/utils/byteUtils.js.map +1 -0
- package/esm/tools/utils/functionUtils.d.ts +9 -0
- package/esm/tools/utils/functionUtils.js +43 -0
- package/esm/tools/utils/functionUtils.js.map +1 -0
- package/esm/tools/utils/numberUtils.d.ts +8 -0
- package/esm/tools/utils/numberUtils.js +17 -0
- package/esm/tools/utils/numberUtils.js.map +1 -0
- package/esm/tools/utils/objectUtils.d.ts +10 -0
- package/esm/tools/utils/objectUtils.js +19 -0
- package/esm/tools/utils/objectUtils.js.map +1 -0
- package/esm/tools/utils/polyfills.d.ts +24 -0
- package/esm/tools/utils/polyfills.js +95 -0
- package/esm/tools/utils/polyfills.js.map +1 -0
- package/esm/tools/utils/responseUtils.d.ts +2 -0
- package/esm/tools/utils/responseUtils.js +13 -0
- package/esm/tools/utils/responseUtils.js.map +1 -0
- package/esm/tools/utils/stringUtils.d.ts +7 -0
- package/esm/tools/utils/stringUtils.js +26 -0
- package/esm/tools/utils/stringUtils.js.map +1 -0
- package/esm/tools/utils/timeUtils.d.ts +57 -0
- package/esm/tools/utils/timeUtils.js +82 -0
- package/esm/tools/utils/timeUtils.js.map +1 -0
- package/esm/tools/utils/typeUtils.d.ts +4 -0
- package/esm/tools/utils/typeUtils.js +13 -0
- package/esm/tools/utils/typeUtils.js.map +1 -0
- package/esm/tools/utils/urlPolyfill.d.ts +14 -0
- package/esm/tools/utils/urlPolyfill.js +80 -0
- package/esm/tools/utils/urlPolyfill.js.map +1 -0
- package/esm/tools/valueHistory.d.ts +50 -0
- package/esm/tools/valueHistory.js +103 -0
- package/esm/tools/valueHistory.js.map +1 -0
- package/esm/transport/batch.d.ts +19 -0
- package/esm/transport/batch.js +76 -0
- package/esm/transport/batch.js.map +1 -0
- package/esm/transport/eventBridge.d.ts +12 -0
- package/esm/transport/eventBridge.js +29 -0
- package/esm/transport/eventBridge.js.map +1 -0
- package/esm/transport/flushController.d.ts +48 -0
- package/esm/transport/flushController.js +93 -0
- package/esm/transport/flushController.js.map +1 -0
- package/esm/transport/httpRequest.d.ts +37 -0
- package/esm/transport/httpRequest.js +85 -0
- package/esm/transport/httpRequest.js.map +1 -0
- package/esm/transport/index.d.ts +4 -0
- package/esm/transport/index.js +5 -0
- package/esm/transport/index.js.map +1 -0
- package/esm/transport/sendWithRetryStrategy.d.ts +39 -0
- package/esm/transport/sendWithRetryStrategy.js +146 -0
- package/esm/transport/sendWithRetryStrategy.js.map +1 -0
- package/esm/transport/startBatchWithReplica.d.ts +15 -0
- package/esm/transport/startBatchWithReplica.js +33 -0
- package/esm/transport/startBatchWithReplica.js.map +1 -0
- package/package.json +26 -0
- package/src/boot/init.ts +41 -0
- package/src/browser/addEventListener.ts +136 -0
- package/src/browser/cookie.ts +71 -0
- package/src/browser/fetchObservable.ts +112 -0
- package/src/browser/pageExitObservable.ts +69 -0
- package/src/browser/runOnReadyState.ts +15 -0
- package/src/browser/types.ts +40 -0
- package/src/browser/xhrObservable.ts +127 -0
- package/src/domain/configuration/configuration.ts +191 -0
- package/src/domain/configuration/endpointBuilder.ts +134 -0
- package/src/domain/configuration/index.ts +9 -0
- package/src/domain/configuration/intakeSites.ts +5 -0
- package/src/domain/configuration/tags.ts +43 -0
- package/src/domain/configuration/transportConfiguration.ts +71 -0
- package/src/domain/console/consoleObservable.ts +86 -0
- package/src/domain/deflate/index.ts +1 -0
- package/src/domain/deflate/types.ts +41 -0
- package/src/domain/error/error.ts +159 -0
- package/src/domain/error/error.types.ts +47 -0
- package/src/domain/error/trackRuntimeError.ts +21 -0
- package/src/domain/eventRateLimiter/createEventRateLimiter.ts +46 -0
- package/src/domain/report/browser.types.ts +26 -0
- package/src/domain/report/reportObservable.ts +126 -0
- package/src/domain/resourceUtils.ts +17 -0
- package/src/domain/session/oldCookiesMigration.ts +42 -0
- package/src/domain/session/sessionConstants.ts +4 -0
- package/src/domain/session/sessionManager.ts +98 -0
- package/src/domain/session/sessionState.ts +51 -0
- package/src/domain/session/sessionStore.ts +185 -0
- package/src/domain/session/sessionStoreOperations.ts +112 -0
- package/src/domain/session/storeStrategies/sessionInCookie.ts +56 -0
- package/src/domain/session/storeStrategies/sessionInLocalStorage.ts +41 -0
- package/src/domain/session/storeStrategies/sessionStoreStrategy.ts +12 -0
- package/src/domain/synthetics/syntheticsWorkerValues.ts +27 -0
- package/src/domain/telemetry/index.ts +14 -0
- package/src/domain/telemetry/rawTelemetryEvent.types.ts +14 -0
- package/src/domain/telemetry/telemetry.ts +195 -0
- package/src/domain/telemetry/telemetryEvent.types.ts +382 -0
- package/src/domain/tracekit/computeStackTrace.ts +141 -0
- package/src/domain/tracekit/index.ts +3 -0
- package/src/domain/tracekit/tracekit.ts +96 -0
- package/src/domain/tracekit/types.ts +47 -0
- package/src/domain/user/index.ts +2 -0
- package/src/domain/user/user.ts +33 -0
- package/src/domain/user/user.types.ts +6 -0
- package/src/index.ts +128 -0
- package/src/tools/abstractLifeCycle.ts +45 -0
- package/src/tools/boundedBuffer.ts +17 -0
- package/src/tools/catchUserErrors.ts +11 -0
- package/src/tools/display.ts +51 -0
- package/src/tools/experimentalFeatures.ts +43 -0
- package/src/tools/getGlobalObject.ts +31 -0
- package/src/tools/getZoneJsOriginalValue.ts +38 -0
- package/src/tools/instrumentMethod.ts +109 -0
- package/src/tools/matchOption.ts +32 -0
- package/src/tools/mergeInto.ts +177 -0
- package/src/tools/monitor.ts +68 -0
- package/src/tools/observable.ts +40 -0
- package/src/tools/readBytesFromStream.ts +77 -0
- package/src/tools/sendToExtension.ts +12 -0
- package/src/tools/serialisation/context.ts +8 -0
- package/src/tools/serialisation/contextManager.ts +79 -0
- package/src/tools/serialisation/heavyCustomerDataWarning.ts +26 -0
- package/src/tools/serialisation/jsonStringify.ts +53 -0
- package/src/tools/serialisation/sanitize.ts +255 -0
- package/src/tools/timer.ts +21 -0
- package/src/tools/utils/arrayUtils.ts +7 -0
- package/src/tools/utils/browserDetection.ts +7 -0
- package/src/tools/utils/byteUtils.ts +29 -0
- package/src/tools/utils/functionUtils.ts +47 -0
- package/src/tools/utils/numberUtils.ts +19 -0
- package/src/tools/utils/objectUtils.ts +21 -0
- package/src/tools/utils/polyfills.ts +127 -0
- package/src/tools/utils/responseUtils.ts +12 -0
- package/src/tools/utils/stringUtils.ts +28 -0
- package/src/tools/utils/timeUtils.ts +112 -0
- package/src/tools/utils/typeUtils.ts +12 -0
- package/src/tools/utils/urlPolyfill.ts +86 -0
- package/src/tools/valueHistory.ts +120 -0
- package/src/transport/batch.ts +92 -0
- package/src/transport/eventBridge.ts +42 -0
- package/src/transport/flushController.ts +129 -0
- package/src/transport/httpRequest.ts +150 -0
- package/src/transport/index.ts +4 -0
- package/src/transport/sendWithRetryStrategy.ts +203 -0
- package/src/transport/startBatchWithReplica.ts +52 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Batch } from './batch';
|
|
2
|
+
import { createHttpRequest } from './httpRequest';
|
|
3
|
+
import { createFlushController } from './flushController';
|
|
4
|
+
export function startBatchWithReplica(configuration, primary, replica, reportError, pageExitObservable, sessionExpireObservable) {
|
|
5
|
+
var primaryBatch = createBatch(configuration, primary.endpoint);
|
|
6
|
+
var replicaBatch = replica && createBatch(configuration, replica.endpoint);
|
|
7
|
+
function createBatch(configuration, endpointBuilder) {
|
|
8
|
+
return new Batch(createHttpRequest(configuration, endpointBuilder, configuration.batchBytesLimit, reportError), createFlushController({
|
|
9
|
+
messagesLimit: configuration.batchMessagesLimit,
|
|
10
|
+
bytesLimit: configuration.batchBytesLimit,
|
|
11
|
+
durationLimit: configuration.flushTimeout,
|
|
12
|
+
pageExitObservable: pageExitObservable,
|
|
13
|
+
sessionExpireObservable: sessionExpireObservable,
|
|
14
|
+
}), configuration.messageBytesLimit);
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
flushObservable: primaryBatch.flushController.flushObservable,
|
|
18
|
+
add: function (message, replicated) {
|
|
19
|
+
if (replicated === void 0) { replicated = true; }
|
|
20
|
+
primaryBatch.add(message);
|
|
21
|
+
if (replicaBatch && replicated) {
|
|
22
|
+
replicaBatch.add(replica.transformMessage ? replica.transformMessage(message) : message);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
upsert: function (message, key) {
|
|
26
|
+
primaryBatch.upsert(message, key);
|
|
27
|
+
if (replicaBatch) {
|
|
28
|
+
replicaBatch.upsert(replica.transformMessage ? replica.transformMessage(message) : message, key);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=startBatchWithReplica.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startBatchWithReplica.js","sourceRoot":"","sources":["../../src/transport/startBatchWithReplica.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAEzD,MAAM,UAAU,qBAAqB,CACnC,aAA4B,EAC5B,OAAsC,EACtC,OAAwF,EACxF,WAAsC,EACtC,kBAA6C,EAC7C,uBAAyC;IAEzC,IAAM,YAAY,GAAG,WAAW,CAAC,aAAa,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;IACjE,IAAM,YAAY,GAAG,OAAO,IAAI,WAAW,CAAC,aAAa,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;IAE5E,SAAS,WAAW,CAAC,aAA4B,EAAE,eAAgC;QACjF,OAAO,IAAI,KAAK,CACd,iBAAiB,CAAC,aAAa,EAAE,eAAe,EAAE,aAAa,CAAC,eAAe,EAAE,WAAW,CAAC,EAC7F,qBAAqB,CAAC;YACpB,aAAa,EAAE,aAAa,CAAC,kBAAkB;YAC/C,UAAU,EAAE,aAAa,CAAC,eAAe;YACzC,aAAa,EAAE,aAAa,CAAC,YAAY;YACzC,kBAAkB,oBAAA;YAClB,uBAAuB,yBAAA;SACxB,CAAC,EACF,aAAa,CAAC,iBAAiB,CAChC,CAAA;IACH,CAAC;IAED,OAAO;QACL,eAAe,EAAE,YAAY,CAAC,eAAe,CAAC,eAAe;QAE7D,GAAG,YAAC,OAAU,EAAE,UAAiB;YAAjB,2BAAA,EAAA,iBAAiB;YAC/B,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;YACzB,IAAI,YAAY,IAAI,UAAU,EAAE;gBAC9B,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;aACzF;QACH,CAAC;QAED,MAAM,EAAE,UAAC,OAAU,EAAE,GAAW;YAC9B,YAAY,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;YACjC,IAAI,YAAY,EAAE;gBAChB,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;aACjG;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openobserve/browser-core",
|
|
3
|
+
"version": "0.2.8",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"main": "cjs/index.js",
|
|
6
|
+
"module": "esm/index.js",
|
|
7
|
+
"types": "cjs/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "run-p build:cjs build:esm",
|
|
11
|
+
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json && yarn replace-build-env cjs",
|
|
12
|
+
"build:esm": "rm -rf esm && tsc -p tsconfig.esm.json && yarn replace-build-env esm",
|
|
13
|
+
"replace-build-env": "node ../../scripts/build/replace-build-env.js"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/openobserve/browser-sdk.git",
|
|
18
|
+
"directory": "packages/core"
|
|
19
|
+
},
|
|
20
|
+
"volta": {
|
|
21
|
+
"extends": "../../package.json"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/boot/init.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { catchUserErrors } from '../tools/catchUserErrors'
|
|
2
|
+
import { setDebugMode } from '../tools/monitor'
|
|
3
|
+
import { assign } from '../tools/utils/polyfills'
|
|
4
|
+
|
|
5
|
+
// replaced at build time
|
|
6
|
+
declare const __BUILD_ENV__SDK_VERSION__: string
|
|
7
|
+
|
|
8
|
+
export function makePublicApi<T>(stub: T): T & { onReady(callback: () => void): void; version: string } {
|
|
9
|
+
const publicApi = assign(
|
|
10
|
+
{
|
|
11
|
+
version: __BUILD_ENV__SDK_VERSION__,
|
|
12
|
+
|
|
13
|
+
// This API method is intentionally not monitored, since the only thing executed is the
|
|
14
|
+
// user-provided 'callback'. All SDK usages executed in the callback should be monitored, and
|
|
15
|
+
// we don't want to interfere with the user uncaught exceptions.
|
|
16
|
+
onReady(callback: () => void) {
|
|
17
|
+
callback()
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
stub
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
// Add a "hidden" property to set debug mode. We define it that way to hide it
|
|
24
|
+
// as much as possible but of course it's not a real protection.
|
|
25
|
+
Object.defineProperty(publicApi, '_setDebug', {
|
|
26
|
+
get() {
|
|
27
|
+
return setDebugMode
|
|
28
|
+
},
|
|
29
|
+
enumerable: false,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
return publicApi
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function defineGlobal<Global, Name extends keyof Global>(global: Global, name: Name, api: Global[Name]) {
|
|
36
|
+
const existingGlobalVariable = global[name] as { q?: Array<() => void> } | undefined
|
|
37
|
+
global[name] = api
|
|
38
|
+
if (existingGlobalVariable && existingGlobalVariable.q) {
|
|
39
|
+
existingGlobalVariable.q.forEach((fn) => catchUserErrors(fn, 'onReady callback threw an error:')())
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { monitor } from '../tools/monitor'
|
|
2
|
+
import { getZoneJsOriginalValue } from '../tools/getZoneJsOriginalValue'
|
|
3
|
+
import type { Configuration } from '../domain/configuration'
|
|
4
|
+
import type { VisualViewport, VisualViewportEventMap } from './types'
|
|
5
|
+
|
|
6
|
+
export const enum DOM_EVENT {
|
|
7
|
+
BEFORE_UNLOAD = 'beforeunload',
|
|
8
|
+
CLICK = 'click',
|
|
9
|
+
DBL_CLICK = 'dblclick',
|
|
10
|
+
KEY_DOWN = 'keydown',
|
|
11
|
+
LOAD = 'load',
|
|
12
|
+
POP_STATE = 'popstate',
|
|
13
|
+
SCROLL = 'scroll',
|
|
14
|
+
TOUCH_START = 'touchstart',
|
|
15
|
+
TOUCH_END = 'touchend',
|
|
16
|
+
TOUCH_MOVE = 'touchmove',
|
|
17
|
+
VISIBILITY_CHANGE = 'visibilitychange',
|
|
18
|
+
PAGE_SHOW = 'pageshow',
|
|
19
|
+
FREEZE = 'freeze',
|
|
20
|
+
RESUME = 'resume',
|
|
21
|
+
DOM_CONTENT_LOADED = 'DOMContentLoaded',
|
|
22
|
+
POINTER_DOWN = 'pointerdown',
|
|
23
|
+
POINTER_UP = 'pointerup',
|
|
24
|
+
POINTER_CANCEL = 'pointercancel',
|
|
25
|
+
HASH_CHANGE = 'hashchange',
|
|
26
|
+
PAGE_HIDE = 'pagehide',
|
|
27
|
+
MOUSE_DOWN = 'mousedown',
|
|
28
|
+
MOUSE_UP = 'mouseup',
|
|
29
|
+
MOUSE_MOVE = 'mousemove',
|
|
30
|
+
FOCUS = 'focus',
|
|
31
|
+
BLUR = 'blur',
|
|
32
|
+
CONTEXT_MENU = 'contextmenu',
|
|
33
|
+
RESIZE = 'resize',
|
|
34
|
+
CHANGE = 'change',
|
|
35
|
+
INPUT = 'input',
|
|
36
|
+
PLAY = 'play',
|
|
37
|
+
PAUSE = 'pause',
|
|
38
|
+
SECURITY_POLICY_VIOLATION = 'securitypolicyviolation',
|
|
39
|
+
SELECTION_CHANGE = 'selectionchange',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface AddEventListenerOptions {
|
|
43
|
+
once?: boolean
|
|
44
|
+
capture?: boolean
|
|
45
|
+
passive?: boolean
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type EventMapFor<T> = T extends Window
|
|
49
|
+
? WindowEventMap & {
|
|
50
|
+
// TS 4.9.5 does not support `freeze` and `resume` events yet
|
|
51
|
+
freeze: Event
|
|
52
|
+
resume: Event
|
|
53
|
+
// TS 4.9.5 does not define `visibilitychange` on Window (only Document)
|
|
54
|
+
visibilitychange: Event
|
|
55
|
+
}
|
|
56
|
+
: T extends Document
|
|
57
|
+
? DocumentEventMap
|
|
58
|
+
: T extends HTMLElement
|
|
59
|
+
? HTMLElementEventMap
|
|
60
|
+
: T extends VisualViewport
|
|
61
|
+
? VisualViewportEventMap
|
|
62
|
+
: T extends ShadowRoot
|
|
63
|
+
? // ShadowRootEventMap is not yet defined in our supported TS version. Instead, use
|
|
64
|
+
// GlobalEventHandlersEventMap which is more than enough as we only need to listen for events bubbling
|
|
65
|
+
// through the ShadowRoot like "change" or "input"
|
|
66
|
+
GlobalEventHandlersEventMap
|
|
67
|
+
: T extends XMLHttpRequest
|
|
68
|
+
? XMLHttpRequestEventMap
|
|
69
|
+
: T extends Performance
|
|
70
|
+
? PerformanceEventMap
|
|
71
|
+
: T extends Worker
|
|
72
|
+
? WorkerEventMap
|
|
73
|
+
: Record<never, never>
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Add an event listener to an event target object (Window, Element, mock object...). This provides
|
|
77
|
+
* a few conveniences compared to using `element.addEventListener` directly:
|
|
78
|
+
*
|
|
79
|
+
* * supports IE11 by: using an option object only if needed and emulating the `once` option
|
|
80
|
+
*
|
|
81
|
+
* * wraps the listener with a `monitor` function
|
|
82
|
+
*
|
|
83
|
+
* * returns a `stop` function to remove the listener
|
|
84
|
+
*/
|
|
85
|
+
export function addEventListener<Target extends EventTarget, EventName extends keyof EventMapFor<Target> & string>(
|
|
86
|
+
configuration: Configuration,
|
|
87
|
+
eventTarget: Target,
|
|
88
|
+
eventName: EventName,
|
|
89
|
+
listener: (event: EventMapFor<Target>[EventName]) => void,
|
|
90
|
+
options?: AddEventListenerOptions
|
|
91
|
+
) {
|
|
92
|
+
return addEventListeners(configuration, eventTarget, [eventName], listener, options)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Add event listeners to an event target object (Window, Element, mock object...). This provides
|
|
97
|
+
* a few conveniences compared to using `element.addEventListener` directly:
|
|
98
|
+
*
|
|
99
|
+
* * supports IE11 by: using an option object only if needed and emulating the `once` option
|
|
100
|
+
*
|
|
101
|
+
* * wraps the listener with a `monitor` function
|
|
102
|
+
*
|
|
103
|
+
* * returns a `stop` function to remove the listener
|
|
104
|
+
*
|
|
105
|
+
* * with `once: true`, the listener will be called at most once, even if different events are listened
|
|
106
|
+
*/
|
|
107
|
+
export function addEventListeners<Target extends EventTarget, EventName extends keyof EventMapFor<Target> & string>(
|
|
108
|
+
_: Configuration,
|
|
109
|
+
eventTarget: Target,
|
|
110
|
+
eventNames: EventName[],
|
|
111
|
+
listener: (event: EventMapFor<Target>[EventName]) => void,
|
|
112
|
+
{ once, capture, passive }: AddEventListenerOptions = {}
|
|
113
|
+
) {
|
|
114
|
+
const wrappedListener = monitor(
|
|
115
|
+
once
|
|
116
|
+
? (event: Event) => {
|
|
117
|
+
stop()
|
|
118
|
+
listener(event as EventMapFor<Target>[EventName])
|
|
119
|
+
}
|
|
120
|
+
: (listener as (event: Event) => void)
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
const options = passive ? { capture, passive } : capture
|
|
124
|
+
|
|
125
|
+
const add = getZoneJsOriginalValue(eventTarget, 'addEventListener')
|
|
126
|
+
eventNames.forEach((eventName) => add.call(eventTarget, eventName, wrappedListener, options))
|
|
127
|
+
|
|
128
|
+
function stop() {
|
|
129
|
+
const remove = getZoneJsOriginalValue(eventTarget, 'removeEventListener')
|
|
130
|
+
eventNames.forEach((eventName) => remove.call(eventTarget, eventName, wrappedListener, options))
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
stop,
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { display } from '../tools/display'
|
|
2
|
+
import { ONE_MINUTE, ONE_SECOND } from '../tools/utils/timeUtils'
|
|
3
|
+
import { findCommaSeparatedValue, generateUUID } from '../tools/utils/stringUtils'
|
|
4
|
+
|
|
5
|
+
export interface CookieOptions {
|
|
6
|
+
secure?: boolean
|
|
7
|
+
crossSite?: boolean
|
|
8
|
+
domain?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function setCookie(name: string, value: string, expireDelay: number, options?: CookieOptions) {
|
|
12
|
+
const date = new Date()
|
|
13
|
+
date.setTime(date.getTime() + expireDelay)
|
|
14
|
+
const expires = `expires=${date.toUTCString()}`
|
|
15
|
+
const sameSite = options && options.crossSite ? 'none' : 'strict'
|
|
16
|
+
const domain = options && options.domain ? `;domain=${options.domain}` : ''
|
|
17
|
+
const secure = options && options.secure ? ';secure' : ''
|
|
18
|
+
document.cookie = `${name}=${value};${expires};path=/;samesite=${sameSite}${domain}${secure}`
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getCookie(name: string) {
|
|
22
|
+
return findCommaSeparatedValue(document.cookie, name)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function deleteCookie(name: string, options?: CookieOptions) {
|
|
26
|
+
setCookie(name, '', 0, options)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function areCookiesAuthorized(options: CookieOptions): boolean {
|
|
30
|
+
if (document.cookie === undefined || document.cookie === null) {
|
|
31
|
+
return false
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
// Use a unique cookie name to avoid issues when the SDK is initialized multiple times during
|
|
35
|
+
// the test cookie lifetime
|
|
36
|
+
const testCookieName = `oo_cookie_test_${generateUUID()}`
|
|
37
|
+
const testCookieValue = 'test'
|
|
38
|
+
setCookie(testCookieName, testCookieValue, ONE_MINUTE, options)
|
|
39
|
+
const isCookieCorrectlySet = getCookie(testCookieName) === testCookieValue
|
|
40
|
+
deleteCookie(testCookieName, options)
|
|
41
|
+
return isCookieCorrectlySet
|
|
42
|
+
} catch (error) {
|
|
43
|
+
display.error(error)
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* No API to retrieve it, number of levels for subdomain and suffix are unknown
|
|
50
|
+
* strategy: find the minimal domain on which cookies are allowed to be set
|
|
51
|
+
* https://web.dev/same-site-same-origin/#site
|
|
52
|
+
*/
|
|
53
|
+
let getCurrentSiteCache: string | undefined
|
|
54
|
+
export function getCurrentSite() {
|
|
55
|
+
if (getCurrentSiteCache === undefined) {
|
|
56
|
+
// Use a unique cookie name to avoid issues when the SDK is initialized multiple times during
|
|
57
|
+
// the test cookie lifetime
|
|
58
|
+
const testCookieName = `oo_site_test_${generateUUID()}`
|
|
59
|
+
const testCookieValue = 'test'
|
|
60
|
+
|
|
61
|
+
const domainLevels = window.location.hostname.split('.')
|
|
62
|
+
let candidateDomain = domainLevels.pop()!
|
|
63
|
+
while (domainLevels.length && !getCookie(testCookieName)) {
|
|
64
|
+
candidateDomain = `${domainLevels.pop()!}.${candidateDomain}`
|
|
65
|
+
setCookie(testCookieName, testCookieValue, ONE_SECOND, { domain: candidateDomain })
|
|
66
|
+
}
|
|
67
|
+
deleteCookie(testCookieName, { domain: candidateDomain })
|
|
68
|
+
getCurrentSiteCache = candidateDomain
|
|
69
|
+
}
|
|
70
|
+
return getCurrentSiteCache
|
|
71
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { instrumentMethod } from '../tools/instrumentMethod'
|
|
2
|
+
import { callMonitored, monitor } from '../tools/monitor'
|
|
3
|
+
import { Observable } from '../tools/observable'
|
|
4
|
+
import type { ClocksState } from '../tools/utils/timeUtils'
|
|
5
|
+
import { clocksNow } from '../tools/utils/timeUtils'
|
|
6
|
+
import { normalizeUrl } from '../tools/utils/urlPolyfill'
|
|
7
|
+
|
|
8
|
+
interface FetchContextBase {
|
|
9
|
+
method: string
|
|
10
|
+
startClocks: ClocksState
|
|
11
|
+
input: unknown
|
|
12
|
+
init?: RequestInit
|
|
13
|
+
url: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface FetchStartContext extends FetchContextBase {
|
|
17
|
+
state: 'start'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface FetchResolveContext extends FetchContextBase {
|
|
21
|
+
state: 'resolve'
|
|
22
|
+
status: number
|
|
23
|
+
response?: Response
|
|
24
|
+
responseType?: string
|
|
25
|
+
isAborted: boolean
|
|
26
|
+
error?: Error
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type FetchContext = FetchStartContext | FetchResolveContext
|
|
30
|
+
|
|
31
|
+
let fetchObservable: Observable<FetchContext> | undefined
|
|
32
|
+
|
|
33
|
+
export function initFetchObservable() {
|
|
34
|
+
if (!fetchObservable) {
|
|
35
|
+
fetchObservable = createFetchObservable()
|
|
36
|
+
}
|
|
37
|
+
return fetchObservable
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function createFetchObservable() {
|
|
41
|
+
const observable = new Observable<FetchContext>(() => {
|
|
42
|
+
if (!window.fetch) {
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const { stop } = instrumentMethod(
|
|
47
|
+
window,
|
|
48
|
+
'fetch',
|
|
49
|
+
(originalFetch) =>
|
|
50
|
+
function (input, init) {
|
|
51
|
+
let responsePromise: Promise<Response>
|
|
52
|
+
|
|
53
|
+
const context = callMonitored(beforeSend, null, [observable, input, init])
|
|
54
|
+
if (context) {
|
|
55
|
+
responsePromise = originalFetch.call(this, context.input as RequestInfo, context.init)
|
|
56
|
+
callMonitored(afterSend, null, [observable, responsePromise, context])
|
|
57
|
+
} else {
|
|
58
|
+
responsePromise = originalFetch.call(this, input, init)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return responsePromise
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
return stop
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
return observable
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function beforeSend(observable: Observable<FetchContext>, input: unknown, init?: RequestInit) {
|
|
72
|
+
const method = (init && init.method) || (input instanceof Request && input.method) || 'GET'
|
|
73
|
+
const url = input instanceof Request ? input.url : normalizeUrl(String(input))
|
|
74
|
+
const startClocks = clocksNow()
|
|
75
|
+
|
|
76
|
+
const context: FetchStartContext = {
|
|
77
|
+
state: 'start',
|
|
78
|
+
init,
|
|
79
|
+
input,
|
|
80
|
+
method,
|
|
81
|
+
startClocks,
|
|
82
|
+
url,
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
observable.notify(context)
|
|
86
|
+
|
|
87
|
+
return context
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function afterSend(
|
|
91
|
+
observable: Observable<FetchContext>,
|
|
92
|
+
responsePromise: Promise<Response>,
|
|
93
|
+
startContext: FetchStartContext
|
|
94
|
+
) {
|
|
95
|
+
const reportFetch = (response: Response | Error) => {
|
|
96
|
+
const context = startContext as unknown as FetchResolveContext
|
|
97
|
+
context.state = 'resolve'
|
|
98
|
+
if ('stack' in response || response instanceof Error) {
|
|
99
|
+
context.status = 0
|
|
100
|
+
context.isAborted = response instanceof DOMException && response.code === DOMException.ABORT_ERR
|
|
101
|
+
context.error = response
|
|
102
|
+
} else if ('status' in response) {
|
|
103
|
+
context.response = response
|
|
104
|
+
context.responseType = response.type
|
|
105
|
+
context.status = response.status
|
|
106
|
+
context.isAborted = false
|
|
107
|
+
}
|
|
108
|
+
observable.notify(context)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
responsePromise.then(monitor(reportFetch), monitor(reportFetch))
|
|
112
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { isExperimentalFeatureEnabled, ExperimentalFeature } from '../tools/experimentalFeatures'
|
|
2
|
+
import { Observable } from '../tools/observable'
|
|
3
|
+
import { objectValues, includes } from '../tools/utils/polyfills'
|
|
4
|
+
import { noop } from '../tools/utils/functionUtils'
|
|
5
|
+
import type { Configuration } from '../domain/configuration'
|
|
6
|
+
import { addEventListeners, addEventListener, DOM_EVENT } from './addEventListener'
|
|
7
|
+
|
|
8
|
+
export const PageExitReason = {
|
|
9
|
+
HIDDEN: 'visibility_hidden',
|
|
10
|
+
UNLOADING: 'before_unload',
|
|
11
|
+
PAGEHIDE: 'page_hide',
|
|
12
|
+
FROZEN: 'page_frozen',
|
|
13
|
+
} as const
|
|
14
|
+
|
|
15
|
+
export type PageExitReason = (typeof PageExitReason)[keyof typeof PageExitReason]
|
|
16
|
+
|
|
17
|
+
export interface PageExitEvent {
|
|
18
|
+
reason: PageExitReason
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function createPageExitObservable(configuration: Configuration): Observable<PageExitEvent> {
|
|
22
|
+
const observable = new Observable<PageExitEvent>(() => {
|
|
23
|
+
const pagehideEnabled = isExperimentalFeatureEnabled(ExperimentalFeature.PAGEHIDE)
|
|
24
|
+
const { stop: stopListeners } = addEventListeners(
|
|
25
|
+
configuration,
|
|
26
|
+
window,
|
|
27
|
+
[DOM_EVENT.VISIBILITY_CHANGE, DOM_EVENT.FREEZE, DOM_EVENT.PAGE_HIDE],
|
|
28
|
+
(event) => {
|
|
29
|
+
if (event.type === DOM_EVENT.PAGE_HIDE && pagehideEnabled) {
|
|
30
|
+
/**
|
|
31
|
+
* Only event that detect page unload events while being compatible with the back/forward cache (bfcache)
|
|
32
|
+
*/
|
|
33
|
+
observable.notify({ reason: PageExitReason.PAGEHIDE })
|
|
34
|
+
} else if (event.type === DOM_EVENT.VISIBILITY_CHANGE && document.visibilityState === 'hidden') {
|
|
35
|
+
/**
|
|
36
|
+
* Only event that guarantee to fire on mobile devices when the page transitions to background state
|
|
37
|
+
* (e.g. when user switches to a different application, goes to homescreen, etc), or is being unloaded.
|
|
38
|
+
*/
|
|
39
|
+
observable.notify({ reason: PageExitReason.HIDDEN })
|
|
40
|
+
} else if (event.type === DOM_EVENT.FREEZE) {
|
|
41
|
+
/**
|
|
42
|
+
* After transitioning in background a tab can be freezed to preserve resources. (cf: https://developer.chrome.com/blog/page-lifecycle-api)
|
|
43
|
+
* Allow to collect events happening between hidden and frozen state.
|
|
44
|
+
*/
|
|
45
|
+
observable.notify({ reason: PageExitReason.FROZEN })
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
{ capture: true }
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
let stopBeforeUnloadListener = noop
|
|
52
|
+
if (!pagehideEnabled) {
|
|
53
|
+
stopBeforeUnloadListener = addEventListener(configuration, window, DOM_EVENT.BEFORE_UNLOAD, () => {
|
|
54
|
+
observable.notify({ reason: PageExitReason.UNLOADING })
|
|
55
|
+
}).stop
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return () => {
|
|
59
|
+
stopListeners()
|
|
60
|
+
stopBeforeUnloadListener()
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
return observable
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function isPageExitReason(reason: string | undefined): reason is PageExitReason {
|
|
68
|
+
return includes(objectValues(PageExitReason), reason)
|
|
69
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Configuration } from '../domain/configuration'
|
|
2
|
+
import { DOM_EVENT, addEventListener } from './addEventListener'
|
|
3
|
+
|
|
4
|
+
export function runOnReadyState(
|
|
5
|
+
configuration: Configuration,
|
|
6
|
+
expectedReadyState: 'complete' | 'interactive',
|
|
7
|
+
callback: () => void
|
|
8
|
+
) {
|
|
9
|
+
if (document.readyState === expectedReadyState || document.readyState === 'complete') {
|
|
10
|
+
callback()
|
|
11
|
+
} else {
|
|
12
|
+
const eventName = expectedReadyState === 'complete' ? DOM_EVENT.LOAD : DOM_EVENT.DOM_CONTENT_LOADED
|
|
13
|
+
addEventListener(configuration, window, eventName, callback, { once: true })
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Those types come from the official TypeScript DOM library, but are not included in our minimal
|
|
2
|
+
// supported TS version.
|
|
3
|
+
// https://github.com/microsoft/TypeScript/blob/13c374a868c926f6a907666a5599992c1351b773/src/lib/dom.generated.d.ts#L15399-L15418
|
|
4
|
+
|
|
5
|
+
export interface VisualViewportEventMap {
|
|
6
|
+
resize: Event
|
|
7
|
+
scroll: Event
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface VisualViewport extends EventTarget {
|
|
11
|
+
readonly height: number
|
|
12
|
+
readonly offsetLeft: number
|
|
13
|
+
readonly offsetTop: number
|
|
14
|
+
onresize: ((this: VisualViewport, ev: Event) => any) | null
|
|
15
|
+
onscroll: ((this: VisualViewport, ev: Event) => any) | null
|
|
16
|
+
readonly pageLeft: number
|
|
17
|
+
readonly pageTop: number
|
|
18
|
+
readonly scale: number
|
|
19
|
+
readonly width: number
|
|
20
|
+
addEventListener<K extends keyof VisualViewportEventMap>(
|
|
21
|
+
type: K,
|
|
22
|
+
listener: (this: VisualViewport, ev: VisualViewportEventMap[K]) => any,
|
|
23
|
+
options?: boolean | AddEventListenerOptions
|
|
24
|
+
): void
|
|
25
|
+
addEventListener(
|
|
26
|
+
type: string,
|
|
27
|
+
listener: EventListenerOrEventListenerObject,
|
|
28
|
+
options?: boolean | AddEventListenerOptions
|
|
29
|
+
): void
|
|
30
|
+
removeEventListener<K extends keyof VisualViewportEventMap>(
|
|
31
|
+
type: K,
|
|
32
|
+
listener: (this: VisualViewport, ev: VisualViewportEventMap[K]) => any,
|
|
33
|
+
options?: boolean | EventListenerOptions
|
|
34
|
+
): void
|
|
35
|
+
removeEventListener(
|
|
36
|
+
type: string,
|
|
37
|
+
listener: EventListenerOrEventListenerObject,
|
|
38
|
+
options?: boolean | EventListenerOptions
|
|
39
|
+
): void
|
|
40
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { instrumentMethodAndCallOriginal } from '../tools/instrumentMethod'
|
|
2
|
+
import { Observable } from '../tools/observable'
|
|
3
|
+
import type { Duration, RelativeTime, ClocksState } from '../tools/utils/timeUtils'
|
|
4
|
+
import { elapsed, relativeNow, clocksNow, timeStampNow } from '../tools/utils/timeUtils'
|
|
5
|
+
import { normalizeUrl } from '../tools/utils/urlPolyfill'
|
|
6
|
+
import { shallowClone } from '../tools/utils/objectUtils'
|
|
7
|
+
import type { Configuration } from '../domain/configuration'
|
|
8
|
+
import { addEventListener } from './addEventListener'
|
|
9
|
+
|
|
10
|
+
export interface XhrOpenContext {
|
|
11
|
+
state: 'open'
|
|
12
|
+
method: string
|
|
13
|
+
url: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface XhrStartContext extends Omit<XhrOpenContext, 'state'> {
|
|
17
|
+
state: 'start'
|
|
18
|
+
startTime: RelativeTime // deprecated
|
|
19
|
+
startClocks: ClocksState
|
|
20
|
+
isAborted: boolean
|
|
21
|
+
xhr: XMLHttpRequest
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface XhrCompleteContext extends Omit<XhrStartContext, 'state'> {
|
|
25
|
+
state: 'complete'
|
|
26
|
+
duration: Duration
|
|
27
|
+
status: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type XhrContext = XhrOpenContext | XhrStartContext | XhrCompleteContext
|
|
31
|
+
|
|
32
|
+
let xhrObservable: Observable<XhrContext> | undefined
|
|
33
|
+
const xhrContexts = new WeakMap<XMLHttpRequest, XhrContext>()
|
|
34
|
+
|
|
35
|
+
export function initXhrObservable(configuration: Configuration) {
|
|
36
|
+
if (!xhrObservable) {
|
|
37
|
+
xhrObservable = createXhrObservable(configuration)
|
|
38
|
+
}
|
|
39
|
+
return xhrObservable
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function createXhrObservable(configuration: Configuration) {
|
|
43
|
+
const observable = new Observable<XhrContext>(() => {
|
|
44
|
+
const { stop: stopInstrumentingStart } = instrumentMethodAndCallOriginal(XMLHttpRequest.prototype, 'open', {
|
|
45
|
+
before: openXhr,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const { stop: stopInstrumentingSend } = instrumentMethodAndCallOriginal(XMLHttpRequest.prototype, 'send', {
|
|
49
|
+
before() {
|
|
50
|
+
sendXhr.call(this, configuration, observable)
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const { stop: stopInstrumentingAbort } = instrumentMethodAndCallOriginal(XMLHttpRequest.prototype, 'abort', {
|
|
55
|
+
before: abortXhr,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
return () => {
|
|
59
|
+
stopInstrumentingStart()
|
|
60
|
+
stopInstrumentingSend()
|
|
61
|
+
stopInstrumentingAbort()
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
return observable
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function openXhr(this: XMLHttpRequest, method: string, url: string | URL | undefined | null) {
|
|
68
|
+
xhrContexts.set(this, {
|
|
69
|
+
state: 'open',
|
|
70
|
+
method,
|
|
71
|
+
url: normalizeUrl(String(url)),
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function sendXhr(this: XMLHttpRequest, configuration: Configuration, observable: Observable<XhrContext>) {
|
|
76
|
+
const context = xhrContexts.get(this)
|
|
77
|
+
if (!context) {
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const startContext = context as XhrStartContext
|
|
82
|
+
startContext.state = 'start'
|
|
83
|
+
startContext.startTime = relativeNow()
|
|
84
|
+
startContext.startClocks = clocksNow()
|
|
85
|
+
startContext.isAborted = false
|
|
86
|
+
startContext.xhr = this
|
|
87
|
+
|
|
88
|
+
let hasBeenReported = false
|
|
89
|
+
|
|
90
|
+
const { stop: stopInstrumentingOnReadyStateChange } = instrumentMethodAndCallOriginal(this, 'onreadystatechange', {
|
|
91
|
+
before() {
|
|
92
|
+
if (this.readyState === XMLHttpRequest.DONE) {
|
|
93
|
+
// Try to report the XHR as soon as possible, because the XHR may be mutated by the
|
|
94
|
+
// application during a future event. For example, Angular is calling .abort() on
|
|
95
|
+
// completed requests during a onreadystatechange event, so the status becomes '0'
|
|
96
|
+
// before the request is collected.
|
|
97
|
+
onEnd()
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const onEnd = () => {
|
|
103
|
+
unsubscribeLoadEndListener()
|
|
104
|
+
stopInstrumentingOnReadyStateChange()
|
|
105
|
+
if (hasBeenReported) {
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
hasBeenReported = true
|
|
109
|
+
|
|
110
|
+
const completeContext = context as XhrCompleteContext
|
|
111
|
+
completeContext.state = 'complete'
|
|
112
|
+
completeContext.duration = elapsed(startContext.startClocks.timeStamp, timeStampNow())
|
|
113
|
+
completeContext.status = this.status
|
|
114
|
+
observable.notify(shallowClone(completeContext))
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const { stop: unsubscribeLoadEndListener } = addEventListener(configuration, this, 'loadend', onEnd)
|
|
118
|
+
|
|
119
|
+
observable.notify(startContext)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function abortXhr(this: XMLHttpRequest) {
|
|
123
|
+
const context = xhrContexts.get(this) as XhrStartContext | undefined
|
|
124
|
+
if (context) {
|
|
125
|
+
context.isAborted = true
|
|
126
|
+
}
|
|
127
|
+
}
|