Socket
Socket
Sign inDemoInstall

@datadog/browser-rum-core

Package Overview
Dependencies
Maintainers
1
Versions
179
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datadog/browser-rum-core - npm Package Compare versions

Comparing version 5.23.0 to 5.23.3

cjs/browser/performanceUtils.d.ts

6

cjs/boot/preStartRum.js

@@ -11,3 +11,3 @@ "use strict";

var ignoreInitIfSyntheticsWillInjectRum = _a.ignoreInitIfSyntheticsWillInjectRum, startDeflateWorker = _a.startDeflateWorker;
var bufferApiCalls = new browser_core_1.BoundedBuffer();
var bufferApiCalls = (0, browser_core_1.createBoundedBuffer)();
var firstStartViewCall;

@@ -100,5 +100,3 @@ var deflateWorker;

}
if ((0, browser_core_1.isExperimentalFeatureEnabled)(browser_core_1.ExperimentalFeature.PLUGINS)) {
(0, plugins_1.callPluginsMethod)(initConfiguration.plugins, 'onInit', { initConfiguration: initConfiguration, publicApi: publicApi });
}
(0, plugins_1.callPluginsMethod)(initConfiguration.betaPlugins, 'onInit', { initConfiguration: initConfiguration, publicApi: publicApi });
if (initConfiguration.remoteConfigurationId &&

@@ -105,0 +103,0 @@ (0, browser_core_1.isExperimentalFeatureEnabled)(browser_core_1.ExperimentalFeature.REMOTE_CONFIGURATION)) {

@@ -32,4 +32,4 @@ "use strict";

name: (0, browser_core_1.sanitize)(name),
context: (0, browser_core_1.sanitize)(options === null || options === void 0 ? void 0 : options.context),
details: (0, browser_core_1.sanitize)(options === null || options === void 0 ? void 0 : options.details),
context: (0, browser_core_1.sanitize)(options && options.context),
details: (0, browser_core_1.sanitize)(options && options.details),
});

@@ -44,4 +44,4 @@ });

duration: options.duration,
context: (0, browser_core_1.sanitize)(options === null || options === void 0 ? void 0 : options.context),
details: (0, browser_core_1.sanitize)(options === null || options === void 0 ? void 0 : options.details),
context: (0, browser_core_1.sanitize)(options && options.context),
details: (0, browser_core_1.sanitize)(options && options.details),
});

@@ -156,3 +156,3 @@ });

recorderApi.start(options);
(0, browser_core_1.addTelemetryUsage)({ feature: 'start-session-replay-recording', force: options === null || options === void 0 ? void 0 : options.force });
(0, browser_core_1.addTelemetryUsage)({ feature: 'start-session-replay-recording', force: options && options.force });
}),

@@ -159,0 +159,0 @@ stopSessionReplayRecording: (0, browser_core_1.monitor)(function () { return recorderApi.stop(); }),

@@ -16,3 +16,3 @@ "use strict";

return function (cookieName, callback) {
var listener = (0, browser_core_1.addEventListener)(configuration, window.cookieStore, browser_core_1.DOM_EVENT.CHANGE, function (event) {
var listener = (0, browser_core_1.addEventListener)(configuration, window.cookieStore, "change" /* DOM_EVENT.CHANGE */, function (event) {
// Based on our experimentation, we're assuming that entries for the same cookie cannot be in both the 'changed' and 'deleted' arrays.

@@ -19,0 +19,0 @@ // However, due to ambiguity in the specification, we asked for clarification: https://github.com/WICG/cookie-store/issues/226

@@ -36,3 +36,3 @@ "use strict";

}).stop;
var removeListener = (0, browser_core_1.addEventListener)(configuration, window, browser_core_1.DOM_EVENT.POP_STATE, onHistoryChange).stop;
var removeListener = (0, browser_core_1.addEventListener)(configuration, window, "popstate" /* DOM_EVENT.POP_STATE */, onHistoryChange).stop;
return {

@@ -47,4 +47,4 @@ stop: function () {

function trackHash(configuration, onHashChange) {
return (0, browser_core_1.addEventListener)(configuration, window, browser_core_1.DOM_EVENT.HASH_CHANGE, onHashChange);
return (0, browser_core_1.addEventListener)(configuration, window, "hashchange" /* DOM_EVENT.HASH_CHANGE */, onHashChange);
}
//# sourceMappingURL=locationChangeObservable.js.map

@@ -5,3 +5,2 @@ "use strict";

var browser_core_1 = require("@datadog/browser-core");
var resourceUtils_1 = require("../domain/resource/resourceUtils");
var performanceObservable_1 = require("./performanceObservable");

@@ -23,7 +22,3 @@ function supportPerformanceObject() {

});
var mainEntries = [
performanceObservable_1.RumPerformanceEntryType.NAVIGATION,
performanceObservable_1.RumPerformanceEntryType.LONG_TASK,
performanceObservable_1.RumPerformanceEntryType.PAINT,
];
var mainEntries = [performanceObservable_1.RumPerformanceEntryType.LONG_TASK, performanceObservable_1.RumPerformanceEntryType.PAINT];
var experimentalEntries = [

@@ -57,4 +52,15 @@ performanceObservable_1.RumPerformanceEntryType.LARGEST_CONTENTFUL_PAINT,

var mainObserver_1 = new PerformanceObserver(handlePerformanceEntryList_1);
mainObserver_1.observe({ entryTypes: mainEntries });
cleanupTasks.push(function () { return mainObserver_1.disconnect(); });
try {
mainObserver_1.observe({ entryTypes: mainEntries });
cleanupTasks.push(function () { return mainObserver_1.disconnect(); });
}
catch (_a) {
// Old versions of Safari are throwing "entryTypes contained only unsupported types"
// errors when observing only unsupported entry types.
//
// We could use `supportPerformanceTimingEvent` to make sure we don't invoke
// `observer.observe` with an unsupported entry type, but Safari 11 and 12 don't support
// `Performance.supportedEntryTypes`, so doing so would lose support for these versions
// even if they do support the entry type.
}
if (supportPerformanceObject() && 'addEventListener' in performance) {

@@ -68,7 +74,2 @@ // https://bugzilla.mozilla.org/show_bug.cgi?id=1559377

}
if (!(0, performanceObservable_1.supportPerformanceTimingEvent)(performanceObservable_1.RumPerformanceEntryType.NAVIGATION)) {
retrieveNavigationTiming(configuration, function (timing) {
handleRumPerformanceEntries(lifeCycle, [timing]);
});
}
if (!(0, performanceObservable_1.supportPerformanceTimingEvent)(performanceObservable_1.RumPerformanceEntryType.FIRST_INPUT)) {

@@ -86,13 +87,2 @@ var stopFirstInputTiming = retrieveFirstInputTiming(configuration, function (timing) {

}
function retrieveNavigationTiming(configuration, callback) {
function sendFakeTiming() {
callback((0, browser_core_1.assign)((0, resourceUtils_1.computeRelativePerformanceTiming)(), {
entryType: performanceObservable_1.RumPerformanceEntryType.NAVIGATION,
}));
}
(0, browser_core_1.runOnReadyState)(configuration, 'complete', function () {
// Send it a bit after the actual load event, so the "loadEventEnd" timing is accurate
(0, browser_core_1.setTimeout)(sendFakeTiming);
});
}
/**

@@ -105,3 +95,3 @@ * first-input timing entry polyfill based on

var timingSent = false;
var removeEventListeners = (0, browser_core_1.addEventListeners)(configuration, window, [browser_core_1.DOM_EVENT.CLICK, browser_core_1.DOM_EVENT.MOUSE_DOWN, browser_core_1.DOM_EVENT.KEY_DOWN, browser_core_1.DOM_EVENT.TOUCH_START, browser_core_1.DOM_EVENT.POINTER_DOWN], function (evt) {
var removeEventListeners = (0, browser_core_1.addEventListeners)(configuration, window, ["click" /* DOM_EVENT.CLICK */, "mousedown" /* DOM_EVENT.MOUSE_DOWN */, "keydown" /* DOM_EVENT.KEY_DOWN */, "touchstart" /* DOM_EVENT.TOUCH_START */, "pointerdown" /* DOM_EVENT.POINTER_DOWN */], function (evt) {
// Only count cancelable events, which should trigger behavior important to the user.

@@ -122,3 +112,3 @@ if (!evt.cancelable) {

};
if (evt.type === browser_core_1.DOM_EVENT.POINTER_DOWN) {
if (evt.type === "pointerdown" /* DOM_EVENT.POINTER_DOWN */) {
sendTimingIfPointerIsNotCancelled(configuration, timing);

@@ -138,4 +128,4 @@ }

function sendTimingIfPointerIsNotCancelled(configuration, timing) {
(0, browser_core_1.addEventListeners)(configuration, window, [browser_core_1.DOM_EVENT.POINTER_UP, browser_core_1.DOM_EVENT.POINTER_CANCEL], function (event) {
if (event.type === browser_core_1.DOM_EVENT.POINTER_UP) {
(0, browser_core_1.addEventListeners)(configuration, window, ["pointerup" /* DOM_EVENT.POINTER_UP */, "pointercancel" /* DOM_EVENT.POINTER_CANCEL */], function (event) {
if (event.type === "pointerup" /* DOM_EVENT.POINTER_UP */) {
sendTiming(timing);

@@ -165,10 +155,6 @@ }

});
var rumAllowedPerformanceEntries = rumPerformanceEntries.filter(function (entry) { return !isIncompleteNavigation(entry); });
if (rumAllowedPerformanceEntries.length) {
lifeCycle.notify(0 /* LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED */, rumAllowedPerformanceEntries);
if (rumPerformanceEntries.length) {
lifeCycle.notify(0 /* LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED */, rumPerformanceEntries);
}
}
function isIncompleteNavigation(entry) {
return entry.entryType === performanceObservable_1.RumPerformanceEntryType.NAVIGATION && entry.loadEventEnd <= 0;
}
//# sourceMappingURL=performanceCollection.js.map

@@ -24,50 +24,60 @@ "use strict";

return new browser_core_1.Observable(function (observable) {
var observer;
if (!window.PerformanceObserver) {
return;
}
var handlePerformanceEntries = function (entries) {
var rumPerformanceEntries = filterRumPerformanceEntries(configuration, entries);
if (rumPerformanceEntries.length > 0) {
observable.notify(rumPerformanceEntries);
}
};
var timeoutId;
if (window.PerformanceObserver) {
var isObserverInitializing_1 = true;
var handlePerformanceEntries_1 = function (entries) {
var rumPerformanceEntries = filterRumPerformanceEntries(configuration, entries);
if (rumPerformanceEntries.length > 0) {
observable.notify(rumPerformanceEntries);
var isObserverInitializing = true;
var observer = new PerformanceObserver((0, browser_core_1.monitor)(function (entries) {
// In Safari the performance observer callback is synchronous.
// Because the buffered performance entry list can be quite large we delay the computation to prevent the SDK from blocking the main thread on init
if (isObserverInitializing) {
timeoutId = (0, browser_core_1.setTimeout)(function () { return handlePerformanceEntries(entries.getEntries()); });
}
else {
handlePerformanceEntries(entries.getEntries());
}
}));
try {
observer.observe(options);
}
catch (_a) {
// Some old browser versions (<= chrome 74 ) don't support the PerformanceObserver type and buffered options
// In these cases, fallback to getEntriesByType and PerformanceObserver with entryTypes
// TODO: remove this fallback in the next major version
var fallbackSupportedEntryTypes = [
RumPerformanceEntryType.RESOURCE,
RumPerformanceEntryType.NAVIGATION,
RumPerformanceEntryType.LONG_TASK,
RumPerformanceEntryType.PAINT,
];
if ((0, browser_core_1.includes)(fallbackSupportedEntryTypes, options.type)) {
if (options.buffered) {
timeoutId = (0, browser_core_1.setTimeout)(function () { return handlePerformanceEntries(performance.getEntriesByType(options.type)); });
}
};
observer = new PerformanceObserver((0, browser_core_1.monitor)(function (entries) {
// In Safari the performance observer callback is synchronous.
// Because the buffered performance entry list can be quite large we delay the computation to prevent the SDK from blocking the main thread on init
if (isObserverInitializing_1) {
timeoutId = (0, browser_core_1.setTimeout)(function () { return handlePerformanceEntries_1(entries.getEntries()); });
try {
observer.observe({ entryTypes: [options.type] });
}
else {
handlePerformanceEntries_1(entries.getEntries());
catch (_b) {
// Old versions of Safari are throwing "entryTypes contained only unsupported types"
// errors when observing only unsupported entry types.
//
// We could use `supportPerformanceTimingEvent` to make sure we don't invoke
// `observer.observe` with an unsupported entry type, but Safari 11 and 12 don't support
// `Performance.supportedEntryTypes`, so doing so would lose support for these versions
// even if they do support the entry type.
return;
}
}));
try {
observer.observe(options);
}
catch (_a) {
// Some old browser versions (<= chrome 74 ) don't support the PerformanceObserver type and buffered options
// In these cases, fallback to getEntriesByType and PerformanceObserver with entryTypes
// TODO: remove this fallback in the next major version
var fallbackSupportedEntryTypes = [
RumPerformanceEntryType.RESOURCE,
RumPerformanceEntryType.NAVIGATION,
RumPerformanceEntryType.LONG_TASK,
RumPerformanceEntryType.PAINT,
];
if ((0, browser_core_1.includes)(fallbackSupportedEntryTypes, options.type)) {
if (options.buffered) {
timeoutId = (0, browser_core_1.setTimeout)(function () { return handlePerformanceEntries_1(performance.getEntriesByType(options.type)); });
}
observer.observe({ entryTypes: [options.type] });
}
}
isObserverInitializing_1 = false;
}
isObserverInitializing = false;
manageResourceTimingBufferFull(configuration);
return function () {
observer === null || observer === void 0 ? void 0 : observer.disconnect();
if (timeoutId) {
(0, browser_core_1.clearTimeout)(timeoutId);
}
observer.disconnect();
(0, browser_core_1.clearTimeout)(timeoutId);
};

@@ -97,7 +107,7 @@ });

function filterRumPerformanceEntries(configuration, entries) {
return entries.filter(function (entry) { return isAllowedResource(configuration, entry); });
return entries.filter(function (entry) { return !isForbiddenResource(configuration, entry); });
}
function isAllowedResource(configuration, entry) {
return entry.entryType === RumPerformanceEntryType.RESOURCE && (0, resourceUtils_1.isAllowedRequestUrl)(configuration, entry.name);
function isForbiddenResource(configuration, entry) {
return entry.entryType === RumPerformanceEntryType.RESOURCE && !(0, resourceUtils_1.isAllowedRequestUrl)(configuration, entry.name);
}
//# sourceMappingURL=performanceObservable.js.map

@@ -62,7 +62,6 @@ "use strict";

function getClassList(element) {
var _a;
if (element.classList) {
return element.classList;
}
var classes = (_a = element.getAttribute('class')) === null || _a === void 0 ? void 0 : _a.trim();
var classes = (element.getAttribute('class') || '').trim();
return classes ? classes.split(/\s+/) : [];

@@ -72,2 +71,3 @@ }

var PLACEHOLDER = 1;
// eslint-disable-next-line no-restricted-syntax
var WeakSet = /** @class */ (function () {

@@ -74,0 +74,0 @@ function WeakSet(initialValues) {

@@ -19,3 +19,3 @@ "use strict";

}, 200).throttled;
return (0, browser_core_1.addEventListener)(configuration, window, browser_core_1.DOM_EVENT.RESIZE, updateDimension, { capture: true, passive: true })
return (0, browser_core_1.addEventListener)(configuration, window, "resize" /* DOM_EVENT.RESIZE */, updateDimension, { capture: true, passive: true })
.stop;

@@ -22,0 +22,0 @@ });

@@ -15,3 +15,3 @@ "use strict";

var listeners = [
(0, browser_core_1.addEventListener)(configuration, window, browser_core_1.DOM_EVENT.POINTER_DOWN, function (event) {
(0, browser_core_1.addEventListener)(configuration, window, "pointerdown" /* DOM_EVENT.POINTER_DOWN */, function (event) {
if (isValidPointerEvent(event)) {

@@ -27,3 +27,3 @@ selectionEmptyAtPointerDown = isSelectionEmpty();

}, { capture: true }),
(0, browser_core_1.addEventListener)(configuration, window, browser_core_1.DOM_EVENT.SELECTION_CHANGE, function () {
(0, browser_core_1.addEventListener)(configuration, window, "selectionchange" /* DOM_EVENT.SELECTION_CHANGE */, function () {
if (!selectionEmptyAtPointerDown || !isSelectionEmpty()) {

@@ -33,6 +33,6 @@ userActivity.selection = true;

}, { capture: true }),
(0, browser_core_1.addEventListener)(configuration, window, browser_core_1.DOM_EVENT.SCROLL, function () {
(0, browser_core_1.addEventListener)(configuration, window, "scroll" /* DOM_EVENT.SCROLL */, function () {
userActivity.scroll = true;
}, { capture: true, passive: true }),
(0, browser_core_1.addEventListener)(configuration, window, browser_core_1.DOM_EVENT.POINTER_UP, function (event) {
(0, browser_core_1.addEventListener)(configuration, window, "pointerup" /* DOM_EVENT.POINTER_UP */, function (event) {
if (isValidPointerEvent(event) && clickContext) {

@@ -45,3 +45,3 @@ // Use a scoped variable to make sure the value is not changed by other clicks

}, { capture: true }),
(0, browser_core_1.addEventListener)(configuration, window, browser_core_1.DOM_EVENT.INPUT, function () {
(0, browser_core_1.addEventListener)(configuration, window, "input" /* DOM_EVENT.INPUT */, function () {
userActivity.input = true;

@@ -48,0 +48,0 @@ }, { capture: true }),

@@ -1,3 +0,3 @@

import type { Duration, ClocksState, RelativeTime, TimeStamp } from '@datadog/browser-core';
import { Observable, ValueHistory } from '@datadog/browser-core';
import type { Duration, ClocksState, RelativeTime, TimeStamp, ValueHistory } from '@datadog/browser-core';
import { Observable } from '@datadog/browser-core';
import type { FrustrationType } from '../../rawRumEvent.types';

@@ -4,0 +4,0 @@ import { ActionType } from '../../rawRumEvent.types';

@@ -19,3 +19,3 @@ "use strict";

function trackClickActions(lifeCycle, domMutationObservable, configuration) {
var history = new browser_core_1.ValueHistory(exports.ACTION_CONTEXT_TIME_OUT_DELAY);
var history = (0, browser_core_1.createValueHistory)({ expireDelay: exports.ACTION_CONTEXT_TIME_OUT_DELAY });
var stopObservable = new browser_core_1.Observable();

@@ -22,0 +22,0 @@ var currentClickChain;

@@ -65,3 +65,3 @@ "use strict";

},
browser_sdk_version: (0, browser_core_1.canUseEventBridge)() ? "5.23.0" : undefined,
browser_sdk_version: (0, browser_core_1.canUseEventBridge)() ? "5.23.3" : undefined,
},

@@ -68,0 +68,0 @@ application: {

@@ -107,3 +107,3 @@ import type { Configuration, InitConfiguration, MatchOption } from '@datadog/browser-core';

*/
plugins?: RumPlugin[] | undefined;
betaPlugins?: RumPlugin[] | undefined;
}

@@ -110,0 +110,0 @@ export type HybridInitConfiguration = Omit<RumInitConfiguration, 'applicationId' | 'clientToken'>;

@@ -15,11 +15,6 @@ "use strict";

}
if (initConfiguration.sessionReplaySampleRate !== undefined &&
!(0, browser_core_1.isPercentage)(initConfiguration.sessionReplaySampleRate)) {
browser_core_1.display.error('Session Replay Sample Rate should be a number between 0 and 100');
if (!(0, browser_core_1.isSampleRate)(initConfiguration.sessionReplaySampleRate, 'Session Replay') ||
!(0, browser_core_1.isSampleRate)(initConfiguration.traceSampleRate, 'Trace')) {
return;
}
if (initConfiguration.traceSampleRate !== undefined && !(0, browser_core_1.isPercentage)(initConfiguration.traceSampleRate)) {
browser_core_1.display.error('Trace Sample Rate should be a number between 0 and 100');
return;
}
if (initConfiguration.excludedActivityUrls !== undefined && !Array.isArray(initConfiguration.excludedActivityUrls)) {

@@ -61,3 +56,3 @@ browser_core_1.display.error('Excluded Activity Urls should be an array');

: browser_core_1.TraceContextInjection.ALL,
plugins: ((0, browser_core_1.isExperimentalFeatureEnabled)(browser_core_1.ExperimentalFeature.PLUGINS) && initConfiguration.plugins) || [],
plugins: initConfiguration.betaPlugins || [],
}, baseConfiguration);

@@ -69,27 +64,27 @@ }

function validateAndBuildTracingOptions(initConfiguration) {
if (initConfiguration.allowedTracingUrls !== undefined) {
if (!Array.isArray(initConfiguration.allowedTracingUrls)) {
browser_core_1.display.error('Allowed Tracing URLs should be an array');
return;
if (initConfiguration.allowedTracingUrls === undefined) {
return [];
}
if (!Array.isArray(initConfiguration.allowedTracingUrls)) {
browser_core_1.display.error('Allowed Tracing URLs should be an array');
return;
}
if (initConfiguration.allowedTracingUrls.length !== 0 && initConfiguration.service === undefined) {
browser_core_1.display.error('Service needs to be configured when tracing is enabled');
return;
}
// Convert from (MatchOption | TracingOption) to TracingOption, remove unknown properties
var tracingOptions = [];
initConfiguration.allowedTracingUrls.forEach(function (option) {
if ((0, browser_core_1.isMatchOption)(option)) {
tracingOptions.push({ match: option, propagatorTypes: exports.DEFAULT_PROPAGATOR_TYPES });
}
if (initConfiguration.allowedTracingUrls.length !== 0 && initConfiguration.service === undefined) {
browser_core_1.display.error('Service needs to be configured when tracing is enabled');
return;
else if ((0, tracer_1.isTracingOption)(option)) {
tracingOptions.push(option);
}
// Convert from (MatchOption | TracingOption) to TracingOption, remove unknown properties
var tracingOptions_1 = [];
initConfiguration.allowedTracingUrls.forEach(function (option) {
if ((0, browser_core_1.isMatchOption)(option)) {
tracingOptions_1.push({ match: option, propagatorTypes: exports.DEFAULT_PROPAGATOR_TYPES });
}
else if ((0, tracer_1.isTracingOption)(option)) {
tracingOptions_1.push(option);
}
else {
browser_core_1.display.warn('Allowed Tracing Urls parameters should be a string, RegExp, function, or an object. Ignoring parameter', option);
}
});
return tracingOptions_1;
}
return [];
else {
browser_core_1.display.warn('Allowed Tracing Urls parameters should be a string, RegExp, function, or an object. Ignoring parameter', option);
}
});
return tracingOptions;
}

@@ -134,5 +129,5 @@ /**

track_long_task: configuration.trackLongTasks,
plugins: (_a = configuration.plugins) === null || _a === void 0 ? void 0 : _a.map(function (plugin) { var _a; return (0, browser_core_1.assign)({ name: plugin.name }, (_a = plugin.getConfigurationTelemetry) === null || _a === void 0 ? void 0 : _a.call(plugin)); }),
plugins: (_a = configuration.betaPlugins) === null || _a === void 0 ? void 0 : _a.map(function (plugin) { var _a; return (0, browser_core_1.assign)({ name: plugin.name }, (_a = plugin.getConfigurationTelemetry) === null || _a === void 0 ? void 0 : _a.call(plugin)); }),
}, baseSerializedConfiguration);
}
//# sourceMappingURL=configuration.js.map

@@ -17,3 +17,5 @@ "use strict";

function startFeatureFlagContexts(lifeCycle, customerDataTracker) {
var featureFlagContexts = new browser_core_1.ValueHistory(exports.FEATURE_FLAG_CONTEXT_TIME_OUT_DELAY);
var featureFlagContexts = (0, browser_core_1.createValueHistory)({
expireDelay: exports.FEATURE_FLAG_CONTEXT_TIME_OUT_DELAY,
});
lifeCycle.subscribe(2 /* LifeCycleEventType.BEFORE_VIEW_CREATED */, function (_a) {

@@ -20,0 +22,0 @@ var startClocks = _a.startClocks;

@@ -13,13 +13,16 @@ "use strict";

if (maxPageStateEntriesSelectable === void 0) { maxPageStateEntriesSelectable = exports.MAX_PAGE_STATE_ENTRIES_SELECTABLE; }
var pageStateEntryHistory = new browser_core_1.ValueHistory(exports.PAGE_STATE_CONTEXT_TIME_OUT_DELAY, exports.MAX_PAGE_STATE_ENTRIES);
var pageStateEntryHistory = (0, browser_core_1.createValueHistory)({
expireDelay: exports.PAGE_STATE_CONTEXT_TIME_OUT_DELAY,
maxEntries: exports.MAX_PAGE_STATE_ENTRIES,
});
var currentPageState;
addPageState(getPageState(), (0, browser_core_1.relativeNow)());
var stopEventListeners = (0, browser_core_1.addEventListeners)(configuration, window, [
browser_core_1.DOM_EVENT.PAGE_SHOW,
browser_core_1.DOM_EVENT.FOCUS,
browser_core_1.DOM_EVENT.BLUR,
browser_core_1.DOM_EVENT.VISIBILITY_CHANGE,
browser_core_1.DOM_EVENT.RESUME,
browser_core_1.DOM_EVENT.FREEZE,
browser_core_1.DOM_EVENT.PAGE_HIDE,
"pageshow" /* DOM_EVENT.PAGE_SHOW */,
"focus" /* DOM_EVENT.FOCUS */,
"blur" /* DOM_EVENT.BLUR */,
"visibilitychange" /* DOM_EVENT.VISIBILITY_CHANGE */,
"resume" /* DOM_EVENT.RESUME */,
"freeze" /* DOM_EVENT.FREEZE */,
"pagehide" /* DOM_EVENT.PAGE_HIDE */,
], function (event) {

@@ -73,6 +76,6 @@ addPageState(computePageState(event), event.timeStamp);

function computePageState(event) {
if (event.type === browser_core_1.DOM_EVENT.FREEZE) {
if (event.type === "freeze" /* DOM_EVENT.FREEZE */) {
return "frozen" /* PageState.FROZEN */;
}
else if (event.type === browser_core_1.DOM_EVENT.PAGE_HIDE) {
else if (event.type === "pagehide" /* DOM_EVENT.PAGE_HIDE */) {
return event.persisted ? "frozen" /* PageState.FROZEN */ : "terminated" /* PageState.TERMINATED */;

@@ -79,0 +82,0 @@ }

@@ -13,3 +13,3 @@ "use strict";

function startUrlContexts(lifeCycle, locationChangeObservable, location) {
var urlContextHistory = new browser_core_1.ValueHistory(exports.URL_CONTEXT_TIME_OUT_DELAY);
var urlContextHistory = (0, browser_core_1.createValueHistory)({ expireDelay: exports.URL_CONTEXT_TIME_OUT_DELAY });
var previousViewUrl;

@@ -16,0 +16,0 @@ lifeCycle.subscribe(2 /* LifeCycleEventType.BEFORE_VIEW_CREATED */, function (_a) {

@@ -8,3 +8,3 @@ "use strict";

function startViewContexts(lifeCycle) {
var viewContextHistory = new browser_core_1.ValueHistory(exports.VIEW_CONTEXT_TIME_OUT_DELAY);
var viewContextHistory = (0, browser_core_1.createValueHistory)({ expireDelay: exports.VIEW_CONTEXT_TIME_OUT_DELAY });
lifeCycle.subscribe(2 /* LifeCycleEventType.BEFORE_VIEW_CREATED */, function (view) {

@@ -11,0 +11,0 @@ viewContextHistory.add(buildViewContext(view), view.startClocks.relative);

import type { RumConfiguration } from '../configuration';
import type { LifeCycle } from '../lifeCycle';
import type { PageStateHistory } from '../contexts/pageStateHistory';
export declare function startResourceCollection(lifeCycle: LifeCycle, configuration: RumConfiguration, pageStateHistory: PageStateHistory): {
import { retrieveInitialDocumentResourceTiming } from './retrieveInitialDocumentResourceTiming';
export declare function startResourceCollection(lifeCycle: LifeCycle, configuration: RumConfiguration, pageStateHistory: PageStateHistory, retrieveInitialDocumentResourceTimingImpl?: typeof retrieveInitialDocumentResourceTiming): {
stop: () => void;
};

@@ -10,3 +10,4 @@ "use strict";

var retrieveInitialDocumentResourceTiming_1 = require("./retrieveInitialDocumentResourceTiming");
function startResourceCollection(lifeCycle, configuration, pageStateHistory) {
function startResourceCollection(lifeCycle, configuration, pageStateHistory, retrieveInitialDocumentResourceTimingImpl) {
if (retrieveInitialDocumentResourceTimingImpl === void 0) { retrieveInitialDocumentResourceTimingImpl = retrieveInitialDocumentResourceTiming_1.retrieveInitialDocumentResourceTiming; }
lifeCycle.subscribe(8 /* LifeCycleEventType.REQUEST_COMPLETED */, function (request) {

@@ -32,3 +33,3 @@ var rawEvent = processRequest(request, configuration, pageStateHistory);

});
(0, retrieveInitialDocumentResourceTiming_1.retrieveInitialDocumentResourceTiming)(configuration, function (timing) {
retrieveInitialDocumentResourceTimingImpl(configuration, function (timing) {
var rawEvent = processResourceEntry(timing, configuration);

@@ -144,3 +145,3 @@ if (rawEvent) {

trace_id: entry.traceId,
span_id: new tracer_1.TraceIdentifier().toDecimalString(),
span_id: (0, tracer_1.createTraceIdentifier)().toDecimalString(),
rule_psr: getRulePsr(configuration),

@@ -147,0 +148,0 @@ },

@@ -1,2 +0,2 @@

import type { RelativeTime, ServerDuration } from '@datadog/browser-core';
import type { ServerDuration } from '@datadog/browser-core';
import { ResourceType } from '@datadog/browser-core';

@@ -35,5 +35,1 @@ import type { RumPerformanceResourceTiming } from '../../browser/performanceObservable';

export declare function sanitizeDataUrl(url: string): string;
export type RelativePerformanceTiming = {
-readonly [key in keyof Omit<PerformanceTiming, 'toJSON'>]: RelativeTime;
};
export declare function computeRelativePerformanceTiming(): RelativePerformanceTiming;

@@ -13,3 +13,2 @@ "use strict";

exports.sanitizeDataUrl = sanitizeDataUrl;
exports.computeRelativePerformanceTiming = computeRelativePerformanceTiming;
var browser_core_1 = require("@datadog/browser-core");

@@ -165,14 +164,2 @@ exports.FAKE_INITIAL_DOCUMENT = 'initial_document';

}
function computeRelativePerformanceTiming() {
var result = {};
var timing = performance.timing;
for (var key in timing) {
if ((0, browser_core_1.isNumber)(timing[key])) {
var numberKey = key;
var timingElement = timing[numberKey];
result[numberKey] = timingElement === 0 ? 0 : (0, browser_core_1.getRelativeTime)(timingElement);
}
}
return result;
}
//# sourceMappingURL=resourceUtils.js.map

@@ -7,2 +7,3 @@ "use strict";

var getDocumentTraceId_1 = require("../tracing/getDocumentTraceId");
var performanceUtils_1 = require("../../browser/performanceUtils");
var resourceUtils_1 = require("./resourceUtils");

@@ -24,3 +25,3 @@ function retrieveInitialDocumentResourceTiming(configuration, callback) {

else {
var relativePerformanceTiming = (0, resourceUtils_1.computeRelativePerformanceTiming)();
var relativePerformanceTiming = (0, performanceUtils_1.computeRelativePerformanceTiming)();
timing = (0, browser_core_1.assign)(relativePerformanceTiming, {

@@ -27,0 +28,0 @@ decodedBodySize: 0,

@@ -31,15 +31,7 @@ import type { RumConfiguration } from '../configuration';

export declare function isTracingSupported(): boolean;
export declare class TraceIdentifier {
private buffer;
constructor();
toString(radix: number): string;
/**
* Format used everywhere except the trace intake
*/
toDecimalString(): string;
/**
* Format used by OTel headers
*/
toPaddedHexadecimalString(): string;
private readInt32;
export declare function getCrypto(): Crypto;
export interface TraceIdentifier {
toDecimalString: () => string;
toPaddedHexadecimalString: () => string;
}
export declare function createTraceIdentifier(): TraceIdentifier;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TraceIdentifier = void 0;
exports.isTracingOption = isTracingOption;

@@ -8,2 +7,4 @@ exports.clearTracingIfNeeded = clearTracingIfNeeded;

exports.isTracingSupported = isTracingSupported;
exports.getCrypto = getCrypto;
exports.createTraceIdentifier = createTraceIdentifier;
var browser_core_1 = require("@datadog/browser-core");

@@ -98,4 +99,4 @@ function isTracingOption(item) {

}
context.traceId = new TraceIdentifier();
context.spanId = new TraceIdentifier();
context.traceId = createTraceIdentifier();
context.spanId = createTraceIdentifier();
inject(makeTracingHeaders(context.traceId, context.spanId, context.traceSampled, tracingOption.propagatorTypes));

@@ -152,12 +153,12 @@ }

}
/* eslint-disable no-bitwise */
var TraceIdentifier = /** @class */ (function () {
function TraceIdentifier() {
this.buffer = new Uint8Array(8);
getCrypto().getRandomValues(this.buffer);
this.buffer[0] = this.buffer[0] & 0x7f; // force 63-bit
function createTraceIdentifier() {
var buffer = new Uint8Array(8);
getCrypto().getRandomValues(buffer);
buffer[0] = buffer[0] & 0x7f; // force 63-bit
function readInt32(offset) {
return buffer[offset] * 16777216 + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3];
}
TraceIdentifier.prototype.toString = function (radix) {
var high = this.readInt32(0);
var low = this.readInt32(4);
function toString(radix) {
var high = readInt32(0);
var low = readInt32(4);
var str = '';

@@ -171,26 +172,22 @@ do {

return str;
};
}
/**
* Format used everywhere except the trace intake
*/
TraceIdentifier.prototype.toDecimalString = function () {
return this.toString(10);
};
function toDecimalString() {
return toString(10);
}
/**
* Format used by OTel headers
*/
TraceIdentifier.prototype.toPaddedHexadecimalString = function () {
var traceId = this.toString(16);
function toPaddedHexadecimalString() {
var traceId = toString(16);
return Array(17 - traceId.length).join('0') + traceId;
}
return {
toDecimalString: toDecimalString,
toPaddedHexadecimalString: toPaddedHexadecimalString,
};
TraceIdentifier.prototype.readInt32 = function (offset) {
return (this.buffer[offset] * 16777216 +
(this.buffer[offset + 1] << 16) +
(this.buffer[offset + 2] << 8) +
this.buffer[offset + 3]);
};
return TraceIdentifier;
}());
exports.TraceIdentifier = TraceIdentifier;
}
/* eslint-enable no-bitwise */
//# sourceMappingURL=tracer.js.map

@@ -75,3 +75,5 @@ "use strict";

stop: function () {
locationChangeSubscription === null || locationChangeSubscription === void 0 ? void 0 : locationChangeSubscription.unsubscribe();
if (locationChangeSubscription) {
locationChangeSubscription.unsubscribe();
}
currentView.end();

@@ -78,0 +80,0 @@ activeViews.forEach(function (view) { return view.stop(); });

@@ -14,4 +14,4 @@ "use strict";

timeStamp = Infinity;
(stopListeners = (0, browser_core_1.addEventListeners)(configuration, eventTarget, [browser_core_1.DOM_EVENT.PAGE_HIDE, browser_core_1.DOM_EVENT.VISIBILITY_CHANGE], function (event) {
if (event.type === browser_core_1.DOM_EVENT.PAGE_HIDE || document.visibilityState === 'hidden') {
(stopListeners = (0, browser_core_1.addEventListeners)(configuration, eventTarget, ["pagehide" /* DOM_EVENT.PAGE_HIDE */, "visibilitychange" /* DOM_EVENT.VISIBILITY_CHANGE */], function (event) {
if (event.type === "pagehide" /* DOM_EVENT.PAGE_HIDE */ || document.visibilityState === 'hidden') {
timeStamp = event.timeStamp;

@@ -18,0 +18,0 @@ stopListeners();

@@ -11,3 +11,3 @@ "use strict";

var initialViewMetrics = {};
var stopNavigationTracking = (0, trackNavigationTimings_1.trackNavigationTimings)(lifeCycle, function (navigationTimings) {
var stopNavigationTracking = (0, trackNavigationTimings_1.trackNavigationTimings)(configuration, function (navigationTimings) {
setLoadEvent(navigationTimings.loadEvent);

@@ -14,0 +14,0 @@ initialViewMetrics.navigationTimings = navigationTimings;

@@ -22,3 +22,3 @@ "use strict";

var firstInteractionTimestamp = Infinity;
var stopEventListener = (0, browser_core_1.addEventListeners)(configuration, eventTarget, [browser_core_1.DOM_EVENT.POINTER_DOWN, browser_core_1.DOM_EVENT.KEY_DOWN], function (event) {
var stopEventListener = (0, browser_core_1.addEventListeners)(configuration, eventTarget, ["pointerdown" /* DOM_EVENT.POINTER_DOWN */, "keydown" /* DOM_EVENT.KEY_DOWN */], function (event) {
firstInteractionTimestamp = event.timeStamp;

@@ -25,0 +25,0 @@ }, { capture: true, once: true }).stop;

import type { Duration } from '@datadog/browser-core';
import type { LifeCycle } from '../../lifeCycle';
import { noop } from '@datadog/browser-core';
import type { RumConfiguration } from '../../configuration';
export interface NavigationTimings {

@@ -10,4 +11,4 @@ domComplete: Duration;

}
export declare function trackNavigationTimings(lifeCycle: LifeCycle, callback: (timings: NavigationTimings) => void): {
stop: () => void;
export declare function trackNavigationTimings(configuration: RumConfiguration, callback: (timings: NavigationTimings) => void): {
stop: typeof noop;
};

@@ -5,24 +5,45 @@ "use strict";

var browser_core_1 = require("@datadog/browser-core");
var performanceUtils_1 = require("../../../browser/performanceUtils");
var performanceObservable_1 = require("../../../browser/performanceObservable");
function trackNavigationTimings(lifeCycle, callback) {
var stop = lifeCycle.subscribe(0 /* LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED */, function (entries) {
for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
var entry = entries_1[_i];
if (entry.entryType === performanceObservable_1.RumPerformanceEntryType.NAVIGATION) {
callback({
domComplete: entry.domComplete,
domContentLoaded: entry.domContentLoadedEventEnd,
domInteractive: entry.domInteractive,
loadEvent: entry.loadEventEnd,
// In some cases the value reported is negative or is larger
// than the current page time. Ignore these cases:
// https://github.com/GoogleChrome/web-vitals/issues/137
// https://github.com/GoogleChrome/web-vitals/issues/162
firstByte: entry.responseStart >= 0 && entry.responseStart <= (0, browser_core_1.relativeNow)() ? entry.responseStart : undefined,
});
}
function trackNavigationTimings(configuration, callback) {
var processEntry = function (entry) {
if (!isIncompleteNavigation(entry)) {
callback(processNavigationEntry(entry));
}
}).unsubscribe;
};
var stop = browser_core_1.noop;
if ((0, performanceObservable_1.supportPerformanceTimingEvent)(performanceObservable_1.RumPerformanceEntryType.NAVIGATION)) {
;
(stop = (0, performanceObservable_1.createPerformanceObservable)(configuration, {
type: performanceObservable_1.RumPerformanceEntryType.NAVIGATION,
buffered: true,
}).subscribe(function (entries) { return (0, browser_core_1.forEach)(entries, processEntry); }).unsubscribe);
}
else {
retrieveNavigationTiming(configuration, processEntry);
}
return { stop: stop };
}
function processNavigationEntry(entry) {
return {
domComplete: entry.domComplete,
domContentLoaded: entry.domContentLoadedEventEnd,
domInteractive: entry.domInteractive,
loadEvent: entry.loadEventEnd,
// In some cases the value reported is negative or is larger
// than the current page time. Ignore these cases:
// https://github.com/GoogleChrome/web-vitals/issues/137
// https://github.com/GoogleChrome/web-vitals/issues/162
firstByte: entry.responseStart >= 0 && entry.responseStart <= (0, browser_core_1.relativeNow)() ? entry.responseStart : undefined,
};
}
function isIncompleteNavigation(entry) {
return entry.loadEventEnd <= 0;
}
function retrieveNavigationTiming(configuration, callback) {
(0, browser_core_1.runOnReadyState)(configuration, 'complete', function () {
// Send it a bit after the actual load event, so the "loadEventEnd" timing is accurate
(0, browser_core_1.setTimeout)(function () { return callback((0, performanceUtils_1.computeRelativePerformanceTiming)()); });
});
}
//# sourceMappingURL=trackNavigationTimings.js.map

@@ -68,3 +68,3 @@ "use strict";

resizeObserver_1.observe(observerTarget_1);
var eventListener_1 = (0, browser_core_1.addEventListener)(configuration, window, browser_core_1.DOM_EVENT.SCROLL, throttledNotify_1.throttled, {
var eventListener_1 = (0, browser_core_1.addEventListener)(configuration, window, "scroll" /* DOM_EVENT.SCROLL */, throttledNotify_1.throttled, {
passive: true,

@@ -71,0 +71,0 @@ });

@@ -7,3 +7,3 @@ export { RumPublicApi, makeRumPublicApi, RecorderApi, StartRecordingOptions } from './boot/rumPublicApi';

export { startRum } from './boot/startRum';
export { LifeCycle, LifeCycleEventType } from './domain/lifeCycle';
export { LifeCycle, LifeCycleEventType, RawRumEventCollectedData } from './domain/lifeCycle';
export { ViewCreatedEvent } from './domain/view/trackViews';

@@ -10,0 +10,0 @@ export { ViewContexts, ViewContext, startViewContexts } from './domain/contexts/viewContexts';

@@ -1,2 +0,2 @@

import { BoundedBuffer, display, canUseEventBridge, displayAlreadyInitializedError, willSyntheticsInjectRum, noop, timeStampNow, clocksNow, assign, getEventBridge, ExperimentalFeature, isExperimentalFeatureEnabled, initFeatureFlags, addTelemetryConfiguration, initFetchObservable, } from '@datadog/browser-core';
import { createBoundedBuffer, display, canUseEventBridge, displayAlreadyInitializedError, willSyntheticsInjectRum, noop, timeStampNow, clocksNow, assign, getEventBridge, ExperimentalFeature, isExperimentalFeatureEnabled, initFeatureFlags, addTelemetryConfiguration, initFetchObservable, } from '@datadog/browser-core';
import { validateAndBuildRumConfiguration, } from '../domain/configuration';

@@ -8,3 +8,3 @@ import { createVitalInstance } from '../domain/vital/vitalCollection';

var ignoreInitIfSyntheticsWillInjectRum = _a.ignoreInitIfSyntheticsWillInjectRum, startDeflateWorker = _a.startDeflateWorker;
var bufferApiCalls = new BoundedBuffer();
var bufferApiCalls = createBoundedBuffer();
var firstStartViewCall;

@@ -97,5 +97,3 @@ var deflateWorker;

}
if (isExperimentalFeatureEnabled(ExperimentalFeature.PLUGINS)) {
callPluginsMethod(initConfiguration.plugins, 'onInit', { initConfiguration: initConfiguration, publicApi: publicApi });
}
callPluginsMethod(initConfiguration.betaPlugins, 'onInit', { initConfiguration: initConfiguration, publicApi: publicApi });
if (initConfiguration.remoteConfigurationId &&

@@ -102,0 +100,0 @@ isExperimentalFeatureEnabled(ExperimentalFeature.REMOTE_CONFIGURATION)) {

@@ -29,4 +29,4 @@ import { addTelemetryUsage, isExperimentalFeatureEnabled, ExperimentalFeature, assign, createContextManager, deepClone, makePublicApi, monitor, clocksNow, callMonitored, createHandlingStack, checkUser, sanitizeUser, sanitize, createIdentityEncoder, createCustomerDataTrackerManager, storeContextManager, displayAlreadyInitializedError, createTrackingConsentState, timeStampToClocks, noop, } from '@datadog/browser-core';

name: sanitize(name),
context: sanitize(options === null || options === void 0 ? void 0 : options.context),
details: sanitize(options === null || options === void 0 ? void 0 : options.details),
context: sanitize(options && options.context),
details: sanitize(options && options.details),
});

@@ -41,4 +41,4 @@ });

duration: options.duration,
context: sanitize(options === null || options === void 0 ? void 0 : options.context),
details: sanitize(options === null || options === void 0 ? void 0 : options.details),
context: sanitize(options && options.context),
details: sanitize(options && options.details),
});

@@ -153,3 +153,3 @@ });

recorderApi.start(options);
addTelemetryUsage({ feature: 'start-session-replay-recording', force: options === null || options === void 0 ? void 0 : options.force });
addTelemetryUsage({ feature: 'start-session-replay-recording', force: options && options.force });
}),

@@ -156,0 +156,0 @@ stopSessionReplayRecording: monitor(function () { return recorderApi.stop(); }),

@@ -1,2 +0,2 @@

import { setInterval, clearInterval, Observable, addEventListener, ONE_SECOND, findCommaSeparatedValue, DOM_EVENT, find, } from '@datadog/browser-core';
import { setInterval, clearInterval, Observable, addEventListener, ONE_SECOND, findCommaSeparatedValue, find, } from '@datadog/browser-core';
export function createCookieObservable(configuration, cookieName) {

@@ -12,3 +12,3 @@ var detectCookieChangeStrategy = window.cookieStore

return function (cookieName, callback) {
var listener = addEventListener(configuration, window.cookieStore, DOM_EVENT.CHANGE, function (event) {
var listener = addEventListener(configuration, window.cookieStore, "change" /* DOM_EVENT.CHANGE */, function (event) {
// Based on our experimentation, we're assuming that entries for the same cookie cannot be in both the 'changed' and 'deleted' arrays.

@@ -15,0 +15,0 @@ // However, due to ambiguity in the specification, we asked for clarification: https://github.com/WICG/cookie-store/issues/226

@@ -1,2 +0,2 @@

import { addEventListener, DOM_EVENT, instrumentMethod, Observable, shallowClone } from '@datadog/browser-core';
import { addEventListener, instrumentMethod, Observable, shallowClone } from '@datadog/browser-core';
export function createLocationChangeObservable(configuration, location) {

@@ -33,3 +33,3 @@ var currentLocation = shallowClone(location);

}).stop;
var removeListener = addEventListener(configuration, window, DOM_EVENT.POP_STATE, onHistoryChange).stop;
var removeListener = addEventListener(configuration, window, "popstate" /* DOM_EVENT.POP_STATE */, onHistoryChange).stop;
return {

@@ -44,4 +44,4 @@ stop: function () {

function trackHash(configuration, onHashChange) {
return addEventListener(configuration, window, DOM_EVENT.HASH_CHANGE, onHashChange);
return addEventListener(configuration, window, "hashchange" /* DOM_EVENT.HASH_CHANGE */, onHashChange);
}
//# sourceMappingURL=locationChangeObservable.js.map

@@ -1,3 +0,2 @@

import { dateNow, assign, addEventListeners, DOM_EVENT, monitor, setTimeout, relativeNow, runOnReadyState, addEventListener, objectHasValue, } from '@datadog/browser-core';
import { computeRelativePerformanceTiming } from '../domain/resource/resourceUtils';
import { dateNow, addEventListeners, monitor, setTimeout, relativeNow, addEventListener, objectHasValue, } from '@datadog/browser-core';
import { RumPerformanceEntryType, supportPerformanceTimingEvent } from './performanceObservable';

@@ -19,7 +18,3 @@ function supportPerformanceObject() {

});
var mainEntries = [
RumPerformanceEntryType.NAVIGATION,
RumPerformanceEntryType.LONG_TASK,
RumPerformanceEntryType.PAINT,
];
var mainEntries = [RumPerformanceEntryType.LONG_TASK, RumPerformanceEntryType.PAINT];
var experimentalEntries = [

@@ -53,4 +48,15 @@ RumPerformanceEntryType.LARGEST_CONTENTFUL_PAINT,

var mainObserver_1 = new PerformanceObserver(handlePerformanceEntryList_1);
mainObserver_1.observe({ entryTypes: mainEntries });
cleanupTasks.push(function () { return mainObserver_1.disconnect(); });
try {
mainObserver_1.observe({ entryTypes: mainEntries });
cleanupTasks.push(function () { return mainObserver_1.disconnect(); });
}
catch (_a) {
// Old versions of Safari are throwing "entryTypes contained only unsupported types"
// errors when observing only unsupported entry types.
//
// We could use `supportPerformanceTimingEvent` to make sure we don't invoke
// `observer.observe` with an unsupported entry type, but Safari 11 and 12 don't support
// `Performance.supportedEntryTypes`, so doing so would lose support for these versions
// even if they do support the entry type.
}
if (supportPerformanceObject() && 'addEventListener' in performance) {

@@ -64,7 +70,2 @@ // https://bugzilla.mozilla.org/show_bug.cgi?id=1559377

}
if (!supportPerformanceTimingEvent(RumPerformanceEntryType.NAVIGATION)) {
retrieveNavigationTiming(configuration, function (timing) {
handleRumPerformanceEntries(lifeCycle, [timing]);
});
}
if (!supportPerformanceTimingEvent(RumPerformanceEntryType.FIRST_INPUT)) {

@@ -82,13 +83,2 @@ var stopFirstInputTiming = retrieveFirstInputTiming(configuration, function (timing) {

}
function retrieveNavigationTiming(configuration, callback) {
function sendFakeTiming() {
callback(assign(computeRelativePerformanceTiming(), {
entryType: RumPerformanceEntryType.NAVIGATION,
}));
}
runOnReadyState(configuration, 'complete', function () {
// Send it a bit after the actual load event, so the "loadEventEnd" timing is accurate
setTimeout(sendFakeTiming);
});
}
/**

@@ -101,3 +91,3 @@ * first-input timing entry polyfill based on

var timingSent = false;
var removeEventListeners = addEventListeners(configuration, window, [DOM_EVENT.CLICK, DOM_EVENT.MOUSE_DOWN, DOM_EVENT.KEY_DOWN, DOM_EVENT.TOUCH_START, DOM_EVENT.POINTER_DOWN], function (evt) {
var removeEventListeners = addEventListeners(configuration, window, ["click" /* DOM_EVENT.CLICK */, "mousedown" /* DOM_EVENT.MOUSE_DOWN */, "keydown" /* DOM_EVENT.KEY_DOWN */, "touchstart" /* DOM_EVENT.TOUCH_START */, "pointerdown" /* DOM_EVENT.POINTER_DOWN */], function (evt) {
// Only count cancelable events, which should trigger behavior important to the user.

@@ -118,3 +108,3 @@ if (!evt.cancelable) {

};
if (evt.type === DOM_EVENT.POINTER_DOWN) {
if (evt.type === "pointerdown" /* DOM_EVENT.POINTER_DOWN */) {
sendTimingIfPointerIsNotCancelled(configuration, timing);

@@ -134,4 +124,4 @@ }

function sendTimingIfPointerIsNotCancelled(configuration, timing) {
addEventListeners(configuration, window, [DOM_EVENT.POINTER_UP, DOM_EVENT.POINTER_CANCEL], function (event) {
if (event.type === DOM_EVENT.POINTER_UP) {
addEventListeners(configuration, window, ["pointerup" /* DOM_EVENT.POINTER_UP */, "pointercancel" /* DOM_EVENT.POINTER_CANCEL */], function (event) {
if (event.type === "pointerup" /* DOM_EVENT.POINTER_UP */) {
sendTiming(timing);

@@ -161,10 +151,6 @@ }

});
var rumAllowedPerformanceEntries = rumPerformanceEntries.filter(function (entry) { return !isIncompleteNavigation(entry); });
if (rumAllowedPerformanceEntries.length) {
lifeCycle.notify(0 /* LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED */, rumAllowedPerformanceEntries);
if (rumPerformanceEntries.length) {
lifeCycle.notify(0 /* LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED */, rumPerformanceEntries);
}
}
function isIncompleteNavigation(entry) {
return entry.entryType === RumPerformanceEntryType.NAVIGATION && entry.loadEventEnd <= 0;
}
//# sourceMappingURL=performanceCollection.js.map

@@ -19,50 +19,60 @@ import { addEventListener, Observable, setTimeout, clearTimeout, monitor, includes } from '@datadog/browser-core';

return new Observable(function (observable) {
var observer;
if (!window.PerformanceObserver) {
return;
}
var handlePerformanceEntries = function (entries) {
var rumPerformanceEntries = filterRumPerformanceEntries(configuration, entries);
if (rumPerformanceEntries.length > 0) {
observable.notify(rumPerformanceEntries);
}
};
var timeoutId;
if (window.PerformanceObserver) {
var isObserverInitializing_1 = true;
var handlePerformanceEntries_1 = function (entries) {
var rumPerformanceEntries = filterRumPerformanceEntries(configuration, entries);
if (rumPerformanceEntries.length > 0) {
observable.notify(rumPerformanceEntries);
var isObserverInitializing = true;
var observer = new PerformanceObserver(monitor(function (entries) {
// In Safari the performance observer callback is synchronous.
// Because the buffered performance entry list can be quite large we delay the computation to prevent the SDK from blocking the main thread on init
if (isObserverInitializing) {
timeoutId = setTimeout(function () { return handlePerformanceEntries(entries.getEntries()); });
}
else {
handlePerformanceEntries(entries.getEntries());
}
}));
try {
observer.observe(options);
}
catch (_a) {
// Some old browser versions (<= chrome 74 ) don't support the PerformanceObserver type and buffered options
// In these cases, fallback to getEntriesByType and PerformanceObserver with entryTypes
// TODO: remove this fallback in the next major version
var fallbackSupportedEntryTypes = [
RumPerformanceEntryType.RESOURCE,
RumPerformanceEntryType.NAVIGATION,
RumPerformanceEntryType.LONG_TASK,
RumPerformanceEntryType.PAINT,
];
if (includes(fallbackSupportedEntryTypes, options.type)) {
if (options.buffered) {
timeoutId = setTimeout(function () { return handlePerformanceEntries(performance.getEntriesByType(options.type)); });
}
};
observer = new PerformanceObserver(monitor(function (entries) {
// In Safari the performance observer callback is synchronous.
// Because the buffered performance entry list can be quite large we delay the computation to prevent the SDK from blocking the main thread on init
if (isObserverInitializing_1) {
timeoutId = setTimeout(function () { return handlePerformanceEntries_1(entries.getEntries()); });
try {
observer.observe({ entryTypes: [options.type] });
}
else {
handlePerformanceEntries_1(entries.getEntries());
catch (_b) {
// Old versions of Safari are throwing "entryTypes contained only unsupported types"
// errors when observing only unsupported entry types.
//
// We could use `supportPerformanceTimingEvent` to make sure we don't invoke
// `observer.observe` with an unsupported entry type, but Safari 11 and 12 don't support
// `Performance.supportedEntryTypes`, so doing so would lose support for these versions
// even if they do support the entry type.
return;
}
}));
try {
observer.observe(options);
}
catch (_a) {
// Some old browser versions (<= chrome 74 ) don't support the PerformanceObserver type and buffered options
// In these cases, fallback to getEntriesByType and PerformanceObserver with entryTypes
// TODO: remove this fallback in the next major version
var fallbackSupportedEntryTypes = [
RumPerformanceEntryType.RESOURCE,
RumPerformanceEntryType.NAVIGATION,
RumPerformanceEntryType.LONG_TASK,
RumPerformanceEntryType.PAINT,
];
if (includes(fallbackSupportedEntryTypes, options.type)) {
if (options.buffered) {
timeoutId = setTimeout(function () { return handlePerformanceEntries_1(performance.getEntriesByType(options.type)); });
}
observer.observe({ entryTypes: [options.type] });
}
}
isObserverInitializing_1 = false;
}
isObserverInitializing = false;
manageResourceTimingBufferFull(configuration);
return function () {
observer === null || observer === void 0 ? void 0 : observer.disconnect();
if (timeoutId) {
clearTimeout(timeoutId);
}
observer.disconnect();
clearTimeout(timeoutId);
};

@@ -92,7 +102,7 @@ });

function filterRumPerformanceEntries(configuration, entries) {
return entries.filter(function (entry) { return isAllowedResource(configuration, entry); });
return entries.filter(function (entry) { return !isForbiddenResource(configuration, entry); });
}
function isAllowedResource(configuration, entry) {
return entry.entryType === RumPerformanceEntryType.RESOURCE && isAllowedRequestUrl(configuration, entry.name);
function isForbiddenResource(configuration, entry) {
return entry.entryType === RumPerformanceEntryType.RESOURCE && !isAllowedRequestUrl(configuration, entry.name);
}
//# sourceMappingURL=performanceObservable.js.map

@@ -55,7 +55,6 @@ // https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/selector/escapeSelector.js

export function getClassList(element) {
var _a;
if (element.classList) {
return element.classList;
}
var classes = (_a = element.getAttribute('class')) === null || _a === void 0 ? void 0 : _a.trim();
var classes = (element.getAttribute('class') || '').trim();
return classes ? classes.split(/\s+/) : [];

@@ -65,2 +64,3 @@ }

var PLACEHOLDER = 1;
// eslint-disable-next-line no-restricted-syntax
var WeakSet = /** @class */ (function () {

@@ -67,0 +67,0 @@ function WeakSet(initialValues) {

@@ -1,2 +0,2 @@

import { Observable, throttle, addEventListener, DOM_EVENT } from '@datadog/browser-core';
import { Observable, throttle, addEventListener } from '@datadog/browser-core';
var viewportObservable;

@@ -14,3 +14,3 @@ export function initViewportObservable(configuration) {

}, 200).throttled;
return addEventListener(configuration, window, DOM_EVENT.RESIZE, updateDimension, { capture: true, passive: true })
return addEventListener(configuration, window, "resize" /* DOM_EVENT.RESIZE */, updateDimension, { capture: true, passive: true })
.stop;

@@ -17,0 +17,0 @@ });

@@ -1,2 +0,2 @@

import { addEventListener, DOM_EVENT } from '@datadog/browser-core';
import { addEventListener } from '@datadog/browser-core';
export function listenActionEvents(configuration, _a) {

@@ -12,3 +12,3 @@ var onPointerDown = _a.onPointerDown, onPointerUp = _a.onPointerUp;

var listeners = [
addEventListener(configuration, window, DOM_EVENT.POINTER_DOWN, function (event) {
addEventListener(configuration, window, "pointerdown" /* DOM_EVENT.POINTER_DOWN */, function (event) {
if (isValidPointerEvent(event)) {

@@ -24,3 +24,3 @@ selectionEmptyAtPointerDown = isSelectionEmpty();

}, { capture: true }),
addEventListener(configuration, window, DOM_EVENT.SELECTION_CHANGE, function () {
addEventListener(configuration, window, "selectionchange" /* DOM_EVENT.SELECTION_CHANGE */, function () {
if (!selectionEmptyAtPointerDown || !isSelectionEmpty()) {

@@ -30,6 +30,6 @@ userActivity.selection = true;

}, { capture: true }),
addEventListener(configuration, window, DOM_EVENT.SCROLL, function () {
addEventListener(configuration, window, "scroll" /* DOM_EVENT.SCROLL */, function () {
userActivity.scroll = true;
}, { capture: true, passive: true }),
addEventListener(configuration, window, DOM_EVENT.POINTER_UP, function (event) {
addEventListener(configuration, window, "pointerup" /* DOM_EVENT.POINTER_UP */, function (event) {
if (isValidPointerEvent(event) && clickContext) {

@@ -42,3 +42,3 @@ // Use a scoped variable to make sure the value is not changed by other clicks

}, { capture: true }),
addEventListener(configuration, window, DOM_EVENT.INPUT, function () {
addEventListener(configuration, window, "input" /* DOM_EVENT.INPUT */, function () {
userActivity.input = true;

@@ -45,0 +45,0 @@ }, { capture: true }),

@@ -1,3 +0,3 @@

import type { Duration, ClocksState, RelativeTime, TimeStamp } from '@datadog/browser-core';
import { Observable, ValueHistory } from '@datadog/browser-core';
import type { Duration, ClocksState, RelativeTime, TimeStamp, ValueHistory } from '@datadog/browser-core';
import { Observable } from '@datadog/browser-core';
import type { FrustrationType } from '../../rawRumEvent.types';

@@ -4,0 +4,0 @@ import { ActionType } from '../../rawRumEvent.types';

@@ -1,2 +0,2 @@

import { includes, timeStampNow, Observable, assign, getRelativeTime, ONE_MINUTE, ValueHistory, generateUUID, clocksNow, ONE_SECOND, elapsed, } from '@datadog/browser-core';
import { includes, timeStampNow, Observable, assign, getRelativeTime, ONE_MINUTE, generateUUID, clocksNow, ONE_SECOND, elapsed, createValueHistory, } from '@datadog/browser-core';
import { trackEventCounts } from '../trackEventCounts';

@@ -14,3 +14,3 @@ import { PAGE_ACTIVITY_VALIDATION_DELAY, waitPageActivityEnd } from '../waitPageActivityEnd';

export function trackClickActions(lifeCycle, domMutationObservable, configuration) {
var history = new ValueHistory(ACTION_CONTEXT_TIME_OUT_DELAY);
var history = createValueHistory({ expireDelay: ACTION_CONTEXT_TIME_OUT_DELAY });
var stopObservable = new Observable();

@@ -17,0 +17,0 @@ var currentClickChain;

@@ -62,3 +62,3 @@ import { combine, isEmptyObject, timeStampNow, currentDrift, display, createEventRateLimiter, canUseEventBridge, assign, round, isExperimentalFeatureEnabled, ExperimentalFeature, getConnectivity, } from '@datadog/browser-core';

},
browser_sdk_version: canUseEventBridge() ? "5.23.0" : undefined,
browser_sdk_version: canUseEventBridge() ? "5.23.3" : undefined,
},

@@ -65,0 +65,0 @@ application: {

@@ -107,3 +107,3 @@ import type { Configuration, InitConfiguration, MatchOption } from '@datadog/browser-core';

*/
plugins?: RumPlugin[] | undefined;
betaPlugins?: RumPlugin[] | undefined;
}

@@ -110,0 +110,0 @@ export type HybridInitConfiguration = Omit<RumInitConfiguration, 'applicationId' | 'clientToken'>;

@@ -1,2 +0,2 @@

import { getType, arrayFrom, isMatchOption, serializeConfiguration, assign, DefaultPrivacyLevel, TraceContextInjection, display, isPercentage, objectHasValue, validateAndBuildConfiguration, isExperimentalFeatureEnabled, ExperimentalFeature, } from '@datadog/browser-core';
import { getType, arrayFrom, isMatchOption, serializeConfiguration, assign, DefaultPrivacyLevel, TraceContextInjection, display, objectHasValue, validateAndBuildConfiguration, isSampleRate, } from '@datadog/browser-core';
import { isTracingOption } from '../tracing/tracer';

@@ -10,11 +10,6 @@ export var DEFAULT_PROPAGATOR_TYPES = ['tracecontext', 'datadog'];

}
if (initConfiguration.sessionReplaySampleRate !== undefined &&
!isPercentage(initConfiguration.sessionReplaySampleRate)) {
display.error('Session Replay Sample Rate should be a number between 0 and 100');
if (!isSampleRate(initConfiguration.sessionReplaySampleRate, 'Session Replay') ||
!isSampleRate(initConfiguration.traceSampleRate, 'Trace')) {
return;
}
if (initConfiguration.traceSampleRate !== undefined && !isPercentage(initConfiguration.traceSampleRate)) {
display.error('Trace Sample Rate should be a number between 0 and 100');
return;
}
if (initConfiguration.excludedActivityUrls !== undefined && !Array.isArray(initConfiguration.excludedActivityUrls)) {

@@ -56,3 +51,3 @@ display.error('Excluded Activity Urls should be an array');

: TraceContextInjection.ALL,
plugins: (isExperimentalFeatureEnabled(ExperimentalFeature.PLUGINS) && initConfiguration.plugins) || [],
plugins: initConfiguration.betaPlugins || [],
}, baseConfiguration);

@@ -64,27 +59,27 @@ }

function validateAndBuildTracingOptions(initConfiguration) {
if (initConfiguration.allowedTracingUrls !== undefined) {
if (!Array.isArray(initConfiguration.allowedTracingUrls)) {
display.error('Allowed Tracing URLs should be an array');
return;
if (initConfiguration.allowedTracingUrls === undefined) {
return [];
}
if (!Array.isArray(initConfiguration.allowedTracingUrls)) {
display.error('Allowed Tracing URLs should be an array');
return;
}
if (initConfiguration.allowedTracingUrls.length !== 0 && initConfiguration.service === undefined) {
display.error('Service needs to be configured when tracing is enabled');
return;
}
// Convert from (MatchOption | TracingOption) to TracingOption, remove unknown properties
var tracingOptions = [];
initConfiguration.allowedTracingUrls.forEach(function (option) {
if (isMatchOption(option)) {
tracingOptions.push({ match: option, propagatorTypes: DEFAULT_PROPAGATOR_TYPES });
}
if (initConfiguration.allowedTracingUrls.length !== 0 && initConfiguration.service === undefined) {
display.error('Service needs to be configured when tracing is enabled');
return;
else if (isTracingOption(option)) {
tracingOptions.push(option);
}
// Convert from (MatchOption | TracingOption) to TracingOption, remove unknown properties
var tracingOptions_1 = [];
initConfiguration.allowedTracingUrls.forEach(function (option) {
if (isMatchOption(option)) {
tracingOptions_1.push({ match: option, propagatorTypes: DEFAULT_PROPAGATOR_TYPES });
}
else if (isTracingOption(option)) {
tracingOptions_1.push(option);
}
else {
display.warn('Allowed Tracing Urls parameters should be a string, RegExp, function, or an object. Ignoring parameter', option);
}
});
return tracingOptions_1;
}
return [];
else {
display.warn('Allowed Tracing Urls parameters should be a string, RegExp, function, or an object. Ignoring parameter', option);
}
});
return tracingOptions;
}

@@ -129,5 +124,5 @@ /**

track_long_task: configuration.trackLongTasks,
plugins: (_a = configuration.plugins) === null || _a === void 0 ? void 0 : _a.map(function (plugin) { var _a; return assign({ name: plugin.name }, (_a = plugin.getConfigurationTelemetry) === null || _a === void 0 ? void 0 : _a.call(plugin)); }),
plugins: (_a = configuration.betaPlugins) === null || _a === void 0 ? void 0 : _a.map(function (plugin) { var _a; return assign({ name: plugin.name }, (_a = plugin.getConfigurationTelemetry) === null || _a === void 0 ? void 0 : _a.call(plugin)); }),
}, baseSerializedConfiguration);
}
//# sourceMappingURL=configuration.js.map

@@ -1,2 +0,2 @@

import { SESSION_TIME_OUT_DELAY, ValueHistory } from '@datadog/browser-core';
import { SESSION_TIME_OUT_DELAY, createValueHistory } from '@datadog/browser-core';
export var FEATURE_FLAG_CONTEXT_TIME_OUT_DELAY = SESSION_TIME_OUT_DELAY;

@@ -13,3 +13,5 @@ export var BYTES_COMPUTATION_THROTTLING_DELAY = 200;

export function startFeatureFlagContexts(lifeCycle, customerDataTracker) {
var featureFlagContexts = new ValueHistory(FEATURE_FLAG_CONTEXT_TIME_OUT_DELAY);
var featureFlagContexts = createValueHistory({
expireDelay: FEATURE_FLAG_CONTEXT_TIME_OUT_DELAY,
});
lifeCycle.subscribe(2 /* LifeCycleEventType.BEFORE_VIEW_CREATED */, function (_a) {

@@ -16,0 +18,0 @@ var startClocks = _a.startClocks;

@@ -1,2 +0,2 @@

import { elapsed, ValueHistory, SESSION_TIME_OUT_DELAY, toServerDuration, addEventListeners, relativeNow, DOM_EVENT, } from '@datadog/browser-core';
import { elapsed, createValueHistory, SESSION_TIME_OUT_DELAY, toServerDuration, addEventListeners, relativeNow, } from '@datadog/browser-core';
// Arbitrary value to cap number of element for memory consumption in the browser

@@ -9,13 +9,16 @@ export var MAX_PAGE_STATE_ENTRIES = 4000;

if (maxPageStateEntriesSelectable === void 0) { maxPageStateEntriesSelectable = MAX_PAGE_STATE_ENTRIES_SELECTABLE; }
var pageStateEntryHistory = new ValueHistory(PAGE_STATE_CONTEXT_TIME_OUT_DELAY, MAX_PAGE_STATE_ENTRIES);
var pageStateEntryHistory = createValueHistory({
expireDelay: PAGE_STATE_CONTEXT_TIME_OUT_DELAY,
maxEntries: MAX_PAGE_STATE_ENTRIES,
});
var currentPageState;
addPageState(getPageState(), relativeNow());
var stopEventListeners = addEventListeners(configuration, window, [
DOM_EVENT.PAGE_SHOW,
DOM_EVENT.FOCUS,
DOM_EVENT.BLUR,
DOM_EVENT.VISIBILITY_CHANGE,
DOM_EVENT.RESUME,
DOM_EVENT.FREEZE,
DOM_EVENT.PAGE_HIDE,
"pageshow" /* DOM_EVENT.PAGE_SHOW */,
"focus" /* DOM_EVENT.FOCUS */,
"blur" /* DOM_EVENT.BLUR */,
"visibilitychange" /* DOM_EVENT.VISIBILITY_CHANGE */,
"resume" /* DOM_EVENT.RESUME */,
"freeze" /* DOM_EVENT.FREEZE */,
"pagehide" /* DOM_EVENT.PAGE_HIDE */,
], function (event) {

@@ -69,6 +72,6 @@ addPageState(computePageState(event), event.timeStamp);

function computePageState(event) {
if (event.type === DOM_EVENT.FREEZE) {
if (event.type === "freeze" /* DOM_EVENT.FREEZE */) {
return "frozen" /* PageState.FROZEN */;
}
else if (event.type === DOM_EVENT.PAGE_HIDE) {
else if (event.type === "pagehide" /* DOM_EVENT.PAGE_HIDE */) {
return event.persisted ? "frozen" /* PageState.FROZEN */ : "terminated" /* PageState.TERMINATED */;

@@ -75,0 +78,0 @@ }

@@ -1,2 +0,2 @@

import { SESSION_TIME_OUT_DELAY, relativeNow, ValueHistory } from '@datadog/browser-core';
import { SESSION_TIME_OUT_DELAY, relativeNow, createValueHistory } from '@datadog/browser-core';
/**

@@ -9,3 +9,3 @@ * We want to attach to an event:

export function startUrlContexts(lifeCycle, locationChangeObservable, location) {
var urlContextHistory = new ValueHistory(URL_CONTEXT_TIME_OUT_DELAY);
var urlContextHistory = createValueHistory({ expireDelay: URL_CONTEXT_TIME_OUT_DELAY });
var previousViewUrl;

@@ -12,0 +12,0 @@ lifeCycle.subscribe(2 /* LifeCycleEventType.BEFORE_VIEW_CREATED */, function (_a) {

@@ -1,5 +0,5 @@

import { SESSION_TIME_OUT_DELAY, ValueHistory } from '@datadog/browser-core';
import { SESSION_TIME_OUT_DELAY, createValueHistory } from '@datadog/browser-core';
export var VIEW_CONTEXT_TIME_OUT_DELAY = SESSION_TIME_OUT_DELAY;
export function startViewContexts(lifeCycle) {
var viewContextHistory = new ValueHistory(VIEW_CONTEXT_TIME_OUT_DELAY);
var viewContextHistory = createValueHistory({ expireDelay: VIEW_CONTEXT_TIME_OUT_DELAY });
lifeCycle.subscribe(2 /* LifeCycleEventType.BEFORE_VIEW_CREATED */, function (view) {

@@ -6,0 +6,0 @@ viewContextHistory.add(buildViewContext(view), view.startClocks.relative);

import type { RumConfiguration } from '../configuration';
import type { LifeCycle } from '../lifeCycle';
import type { PageStateHistory } from '../contexts/pageStateHistory';
export declare function startResourceCollection(lifeCycle: LifeCycle, configuration: RumConfiguration, pageStateHistory: PageStateHistory): {
import { retrieveInitialDocumentResourceTiming } from './retrieveInitialDocumentResourceTiming';
export declare function startResourceCollection(lifeCycle: LifeCycle, configuration: RumConfiguration, pageStateHistory: PageStateHistory, retrieveInitialDocumentResourceTimingImpl?: typeof retrieveInitialDocumentResourceTiming): {
stop: () => void;
};
import { combine, generateUUID, toServerDuration, relativeToClocks, assign, isNumber, } from '@datadog/browser-core';
import { RumPerformanceEntryType, createPerformanceObservable, } from '../../browser/performanceObservable';
import { TraceIdentifier } from '../tracing/tracer';
import { createTraceIdentifier } from '../tracing/tracer';
import { matchRequestTiming } from './matchRequestTiming';
import { computePerformanceResourceDetails, computePerformanceResourceDuration, computeResourceKind, computeSize, isRequestKind, isLongDataUrl, sanitizeDataUrl, } from './resourceUtils';
import { retrieveInitialDocumentResourceTiming } from './retrieveInitialDocumentResourceTiming';
export function startResourceCollection(lifeCycle, configuration, pageStateHistory) {
export function startResourceCollection(lifeCycle, configuration, pageStateHistory, retrieveInitialDocumentResourceTimingImpl) {
if (retrieveInitialDocumentResourceTimingImpl === void 0) { retrieveInitialDocumentResourceTimingImpl = retrieveInitialDocumentResourceTiming; }
lifeCycle.subscribe(8 /* LifeCycleEventType.REQUEST_COMPLETED */, function (request) {

@@ -28,3 +29,3 @@ var rawEvent = processRequest(request, configuration, pageStateHistory);

});
retrieveInitialDocumentResourceTiming(configuration, function (timing) {
retrieveInitialDocumentResourceTimingImpl(configuration, function (timing) {
var rawEvent = processResourceEntry(timing, configuration);

@@ -140,3 +141,3 @@ if (rawEvent) {

trace_id: entry.traceId,
span_id: new TraceIdentifier().toDecimalString(),
span_id: createTraceIdentifier().toDecimalString(),
rule_psr: getRulePsr(configuration),

@@ -143,0 +144,0 @@ },

@@ -1,2 +0,2 @@

import type { RelativeTime, ServerDuration } from '@datadog/browser-core';
import type { ServerDuration } from '@datadog/browser-core';
import { ResourceType } from '@datadog/browser-core';

@@ -35,5 +35,1 @@ import type { RumPerformanceResourceTiming } from '../../browser/performanceObservable';

export declare function sanitizeDataUrl(url: string): string;
export type RelativePerformanceTiming = {
-readonly [key in keyof Omit<PerformanceTiming, 'toJSON'>]: RelativeTime;
};
export declare function computeRelativePerformanceTiming(): RelativePerformanceTiming;

@@ -1,2 +0,2 @@

import { addTelemetryDebug, elapsed, ExperimentalFeature, getPathName, getRelativeTime, includes, isExperimentalFeatureEnabled, isNumber, isValidUrl, toServerDuration, } from '@datadog/browser-core';
import { addTelemetryDebug, elapsed, ExperimentalFeature, getPathName, includes, isExperimentalFeatureEnabled, isValidUrl, toServerDuration, } from '@datadog/browser-core';
export var FAKE_INITIAL_DOCUMENT = 'initial_document';

@@ -151,14 +151,2 @@ var RESOURCE_TYPES = [

}
export function computeRelativePerformanceTiming() {
var result = {};
var timing = performance.timing;
for (var key in timing) {
if (isNumber(timing[key])) {
var numberKey = key;
var timingElement = timing[numberKey];
result[numberKey] = timingElement === 0 ? 0 : getRelativeTime(timingElement);
}
}
return result;
}
//# sourceMappingURL=resourceUtils.js.map
import { assign, runOnReadyState } from '@datadog/browser-core';
import { supportPerformanceTimingEvent, RumPerformanceEntryType } from '../../browser/performanceObservable';
import { getDocumentTraceId } from '../tracing/getDocumentTraceId';
import { FAKE_INITIAL_DOCUMENT, computeRelativePerformanceTiming } from './resourceUtils';
import { computeRelativePerformanceTiming } from '../../browser/performanceUtils';
import { FAKE_INITIAL_DOCUMENT } from './resourceUtils';
export function retrieveInitialDocumentResourceTiming(configuration, callback) {

@@ -6,0 +7,0 @@ runOnReadyState(configuration, 'interactive', function () {

@@ -31,15 +31,7 @@ import type { RumConfiguration } from '../configuration';

export declare function isTracingSupported(): boolean;
export declare class TraceIdentifier {
private buffer;
constructor();
toString(radix: number): string;
/**
* Format used everywhere except the trace intake
*/
toDecimalString(): string;
/**
* Format used by OTel headers
*/
toPaddedHexadecimalString(): string;
private readInt32;
export declare function getCrypto(): Crypto;
export interface TraceIdentifier {
toDecimalString: () => string;
toPaddedHexadecimalString: () => string;
}
export declare function createTraceIdentifier(): TraceIdentifier;

@@ -90,4 +90,4 @@ import { objectEntries, shallowClone, performDraw, isNumber, assign, find, getType, isMatchOption, matchList, TraceContextInjection, } from '@datadog/browser-core';

}
context.traceId = new TraceIdentifier();
context.spanId = new TraceIdentifier();
context.traceId = createTraceIdentifier();
context.spanId = createTraceIdentifier();
inject(makeTracingHeaders(context.traceId, context.spanId, context.traceSampled, tracingOption.propagatorTypes));

@@ -98,3 +98,3 @@ }

}
function getCrypto() {
export function getCrypto() {
return window.crypto || window.msCrypto;

@@ -145,12 +145,12 @@ }

}
/* eslint-disable no-bitwise */
var TraceIdentifier = /** @class */ (function () {
function TraceIdentifier() {
this.buffer = new Uint8Array(8);
getCrypto().getRandomValues(this.buffer);
this.buffer[0] = this.buffer[0] & 0x7f; // force 63-bit
export function createTraceIdentifier() {
var buffer = new Uint8Array(8);
getCrypto().getRandomValues(buffer);
buffer[0] = buffer[0] & 0x7f; // force 63-bit
function readInt32(offset) {
return buffer[offset] * 16777216 + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3];
}
TraceIdentifier.prototype.toString = function (radix) {
var high = this.readInt32(0);
var low = this.readInt32(4);
function toString(radix) {
var high = readInt32(0);
var low = readInt32(4);
var str = '';

@@ -164,26 +164,22 @@ do {

return str;
};
}
/**
* Format used everywhere except the trace intake
*/
TraceIdentifier.prototype.toDecimalString = function () {
return this.toString(10);
};
function toDecimalString() {
return toString(10);
}
/**
* Format used by OTel headers
*/
TraceIdentifier.prototype.toPaddedHexadecimalString = function () {
var traceId = this.toString(16);
function toPaddedHexadecimalString() {
var traceId = toString(16);
return Array(17 - traceId.length).join('0') + traceId;
}
return {
toDecimalString: toDecimalString,
toPaddedHexadecimalString: toPaddedHexadecimalString,
};
TraceIdentifier.prototype.readInt32 = function (offset) {
return (this.buffer[offset] * 16777216 +
(this.buffer[offset + 1] << 16) +
(this.buffer[offset + 2] << 8) +
this.buffer[offset + 3]);
};
return TraceIdentifier;
}());
export { TraceIdentifier };
}
/* eslint-enable no-bitwise */
//# sourceMappingURL=tracer.js.map

@@ -71,3 +71,5 @@ import { noop, PageExitReason, shallowClone, elapsed, generateUUID, ONE_MINUTE, throttle, clocksNow, clocksOrigin, timeStampNow, display, looksLikeRelativeTime, setInterval, clearInterval, setTimeout, Observable, isExperimentalFeatureEnabled, ExperimentalFeature, } from '@datadog/browser-core';

stop: function () {
locationChangeSubscription === null || locationChangeSubscription === void 0 ? void 0 : locationChangeSubscription.unsubscribe();
if (locationChangeSubscription) {
locationChangeSubscription.unsubscribe();
}
currentView.end();

@@ -74,0 +76,0 @@ activeViews.forEach(function (view) { return view.stop(); });

@@ -1,2 +0,2 @@

import { addEventListeners, DOM_EVENT } from '@datadog/browser-core';
import { addEventListeners } from '@datadog/browser-core';
export function trackFirstHidden(configuration, eventTarget) {

@@ -11,4 +11,4 @@ if (eventTarget === void 0) { eventTarget = window; }

timeStamp = Infinity;
(stopListeners = addEventListeners(configuration, eventTarget, [DOM_EVENT.PAGE_HIDE, DOM_EVENT.VISIBILITY_CHANGE], function (event) {
if (event.type === DOM_EVENT.PAGE_HIDE || document.visibilityState === 'hidden') {
(stopListeners = addEventListeners(configuration, eventTarget, ["pagehide" /* DOM_EVENT.PAGE_HIDE */, "visibilitychange" /* DOM_EVENT.VISIBILITY_CHANGE */], function (event) {
if (event.type === "pagehide" /* DOM_EVENT.PAGE_HIDE */ || document.visibilityState === 'hidden') {
timeStamp = event.timeStamp;

@@ -15,0 +15,0 @@ stopListeners();

@@ -8,3 +8,3 @@ import { trackFirstContentfulPaint } from './trackFirstContentfulPaint';

var initialViewMetrics = {};
var stopNavigationTracking = trackNavigationTimings(lifeCycle, function (navigationTimings) {
var stopNavigationTracking = trackNavigationTimings(configuration, function (navigationTimings) {
setLoadEvent(navigationTimings.loadEvent);

@@ -11,0 +11,0 @@ initialViewMetrics.navigationTimings = navigationTimings;

@@ -1,2 +0,2 @@

import { DOM_EVENT, ONE_MINUTE, addEventListeners, findLast } from '@datadog/browser-core';
import { ONE_MINUTE, addEventListeners, findLast } from '@datadog/browser-core';
import { RumPerformanceEntryType } from '../../../browser/performanceObservable';

@@ -18,3 +18,3 @@ import { getSelectorFromElement } from '../../getSelectorFromElement';

var firstInteractionTimestamp = Infinity;
var stopEventListener = addEventListeners(configuration, eventTarget, [DOM_EVENT.POINTER_DOWN, DOM_EVENT.KEY_DOWN], function (event) {
var stopEventListener = addEventListeners(configuration, eventTarget, ["pointerdown" /* DOM_EVENT.POINTER_DOWN */, "keydown" /* DOM_EVENT.KEY_DOWN */], function (event) {
firstInteractionTimestamp = event.timeStamp;

@@ -21,0 +21,0 @@ }, { capture: true, once: true }).stop;

import type { Duration } from '@datadog/browser-core';
import type { LifeCycle } from '../../lifeCycle';
import { noop } from '@datadog/browser-core';
import type { RumConfiguration } from '../../configuration';
export interface NavigationTimings {

@@ -10,4 +11,4 @@ domComplete: Duration;

}
export declare function trackNavigationTimings(lifeCycle: LifeCycle, callback: (timings: NavigationTimings) => void): {
stop: () => void;
export declare function trackNavigationTimings(configuration: RumConfiguration, callback: (timings: NavigationTimings) => void): {
stop: typeof noop;
};

@@ -1,24 +0,45 @@

import { relativeNow } from '@datadog/browser-core';
import { RumPerformanceEntryType } from '../../../browser/performanceObservable';
export function trackNavigationTimings(lifeCycle, callback) {
var stop = lifeCycle.subscribe(0 /* LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED */, function (entries) {
for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
var entry = entries_1[_i];
if (entry.entryType === RumPerformanceEntryType.NAVIGATION) {
callback({
domComplete: entry.domComplete,
domContentLoaded: entry.domContentLoadedEventEnd,
domInteractive: entry.domInteractive,
loadEvent: entry.loadEventEnd,
// In some cases the value reported is negative or is larger
// than the current page time. Ignore these cases:
// https://github.com/GoogleChrome/web-vitals/issues/137
// https://github.com/GoogleChrome/web-vitals/issues/162
firstByte: entry.responseStart >= 0 && entry.responseStart <= relativeNow() ? entry.responseStart : undefined,
});
}
import { forEach, setTimeout, noop, relativeNow, runOnReadyState } from '@datadog/browser-core';
import { computeRelativePerformanceTiming } from '../../../browser/performanceUtils';
import { createPerformanceObservable, RumPerformanceEntryType, supportPerformanceTimingEvent, } from '../../../browser/performanceObservable';
export function trackNavigationTimings(configuration, callback) {
var processEntry = function (entry) {
if (!isIncompleteNavigation(entry)) {
callback(processNavigationEntry(entry));
}
}).unsubscribe;
};
var stop = noop;
if (supportPerformanceTimingEvent(RumPerformanceEntryType.NAVIGATION)) {
;
(stop = createPerformanceObservable(configuration, {
type: RumPerformanceEntryType.NAVIGATION,
buffered: true,
}).subscribe(function (entries) { return forEach(entries, processEntry); }).unsubscribe);
}
else {
retrieveNavigationTiming(configuration, processEntry);
}
return { stop: stop };
}
function processNavigationEntry(entry) {
return {
domComplete: entry.domComplete,
domContentLoaded: entry.domContentLoadedEventEnd,
domInteractive: entry.domInteractive,
loadEvent: entry.loadEventEnd,
// In some cases the value reported is negative or is larger
// than the current page time. Ignore these cases:
// https://github.com/GoogleChrome/web-vitals/issues/137
// https://github.com/GoogleChrome/web-vitals/issues/162
firstByte: entry.responseStart >= 0 && entry.responseStart <= relativeNow() ? entry.responseStart : undefined,
};
}
function isIncompleteNavigation(entry) {
return entry.loadEventEnd <= 0;
}
function retrieveNavigationTiming(configuration, callback) {
runOnReadyState(configuration, 'complete', function () {
// Send it a bit after the actual load event, so the "loadEventEnd" timing is accurate
setTimeout(function () { return callback(computeRelativePerformanceTiming()); });
});
}
//# sourceMappingURL=trackNavigationTimings.js.map

@@ -1,2 +0,2 @@

import { Observable, ONE_SECOND, elapsed, relativeNow, throttle, addEventListener, DOM_EVENT, monitor, } from '@datadog/browser-core';
import { Observable, ONE_SECOND, elapsed, relativeNow, throttle, addEventListener, monitor, } from '@datadog/browser-core';
import { getScrollY } from '../../../browser/scroll';

@@ -62,3 +62,3 @@ import { getViewportDimension } from '../../../browser/viewportObservable';

resizeObserver_1.observe(observerTarget_1);
var eventListener_1 = addEventListener(configuration, window, DOM_EVENT.SCROLL, throttledNotify_1.throttled, {
var eventListener_1 = addEventListener(configuration, window, "scroll" /* DOM_EVENT.SCROLL */, throttledNotify_1.throttled, {
passive: true,

@@ -65,0 +65,0 @@ });

@@ -7,3 +7,3 @@ export { RumPublicApi, makeRumPublicApi, RecorderApi, StartRecordingOptions } from './boot/rumPublicApi';

export { startRum } from './boot/startRum';
export { LifeCycle, LifeCycleEventType } from './domain/lifeCycle';
export { LifeCycle, LifeCycleEventType, RawRumEventCollectedData } from './domain/lifeCycle';
export { ViewCreatedEvent } from './domain/view/trackViews';

@@ -10,0 +10,0 @@ export { ViewContexts, ViewContext, startViewContexts } from './domain/contexts/viewContexts';

{
"name": "@datadog/browser-rum-core",
"version": "5.23.0",
"version": "5.23.3",
"license": "Apache-2.0",

@@ -15,3 +15,3 @@ "main": "cjs/index.js",

"dependencies": {
"@datadog/browser-core": "5.23.0"
"@datadog/browser-core": "5.23.3"
},

@@ -32,3 +32,3 @@ "devDependencies": {

},
"gitHead": "11c8da555ab131e2b0c1b53e9908fbde64c388c8"
"gitHead": "276d1141c77dfaafcd5fc16a8cb7baf6221cfff4"
}
import {
BoundedBuffer,
createBoundedBuffer,
display,

@@ -43,3 +43,3 @@ canUseEventBridge,

): Strategy {
const bufferApiCalls = new BoundedBuffer<StartRumResult>()
const bufferApiCalls = createBoundedBuffer<StartRumResult>()
let firstStartViewCall:

@@ -158,5 +158,3 @@ | { options: ViewOptions | undefined; callback: (startRumResult: StartRumResult) => void }

if (isExperimentalFeatureEnabled(ExperimentalFeature.PLUGINS)) {
callPluginsMethod(initConfiguration.plugins, 'onInit', { initConfiguration, publicApi })
}
callPluginsMethod(initConfiguration.betaPlugins, 'onInit', { initConfiguration, publicApi })

@@ -163,0 +161,0 @@ if (

@@ -334,4 +334,4 @@ import type {

name: sanitize(name)!,
context: sanitize(options?.context) as Context,
details: sanitize(options?.details) as string | undefined,
context: sanitize(options && options.context) as Context,
details: sanitize(options && options.details) as string | undefined,
})

@@ -359,4 +359,4 @@ }

duration: options.duration as Duration,
context: sanitize(options?.context) as Context,
details: sanitize(options?.details) as string | undefined,
context: sanitize(options && options.context) as Context,
details: sanitize(options && options.details) as string | undefined,
})

@@ -529,3 +529,3 @@ }

recorderApi.start(options)
addTelemetryUsage({ feature: 'start-session-replay-recording', force: options?.force })
addTelemetryUsage({ feature: 'start-session-replay-recording', force: options && options.force })
}),

@@ -532,0 +532,0 @@

import type { Duration, RelativeTime } from '@datadog/browser-core'
import {
dateNow,
assign,
addEventListeners,

@@ -10,3 +9,2 @@ DOM_EVENT,

relativeNow,
runOnReadyState,
addEventListener,

@@ -19,3 +17,2 @@ objectHasValue,

import { LifeCycleEventType } from '../domain/lifeCycle'
import { computeRelativePerformanceTiming } from '../domain/resource/resourceUtils'
import type {

@@ -25,3 +22,2 @@ BrowserWindow,

RumPerformanceEntry,
RumPerformanceNavigationTiming,
RumPerformanceResourceTiming,

@@ -51,7 +47,3 @@ } from './performanceObservable'

)
const mainEntries = [
RumPerformanceEntryType.NAVIGATION,
RumPerformanceEntryType.LONG_TASK,
RumPerformanceEntryType.PAINT,
]
const mainEntries = [RumPerformanceEntryType.LONG_TASK, RumPerformanceEntryType.PAINT]
const experimentalEntries = [

@@ -86,4 +78,14 @@ RumPerformanceEntryType.LARGEST_CONTENTFUL_PAINT,

const mainObserver = new PerformanceObserver(handlePerformanceEntryList)
mainObserver.observe({ entryTypes: mainEntries })
cleanupTasks.push(() => mainObserver.disconnect())
try {
mainObserver.observe({ entryTypes: mainEntries })
cleanupTasks.push(() => mainObserver.disconnect())
} catch {
// Old versions of Safari are throwing "entryTypes contained only unsupported types"
// errors when observing only unsupported entry types.
//
// We could use `supportPerformanceTimingEvent` to make sure we don't invoke
// `observer.observe` with an unsupported entry type, but Safari 11 and 12 don't support
// `Performance.supportedEntryTypes`, so doing so would lose support for these versions
// even if they do support the entry type.
}

@@ -103,7 +105,3 @@ if (supportPerformanceObject() && 'addEventListener' in performance) {

}
if (!supportPerformanceTimingEvent(RumPerformanceEntryType.NAVIGATION)) {
retrieveNavigationTiming(configuration, (timing) => {
handleRumPerformanceEntries(lifeCycle, [timing])
})
}
if (!supportPerformanceTimingEvent(RumPerformanceEntryType.FIRST_INPUT)) {

@@ -122,20 +120,2 @@ const { stop: stopFirstInputTiming } = retrieveFirstInputTiming(configuration, (timing) => {

function retrieveNavigationTiming(
configuration: RumConfiguration,
callback: (timing: RumPerformanceNavigationTiming) => void
) {
function sendFakeTiming() {
callback(
assign(computeRelativePerformanceTiming(), {
entryType: RumPerformanceEntryType.NAVIGATION as const,
})
)
}
runOnReadyState(configuration, 'complete', () => {
// Send it a bit after the actual load event, so the "loadEventEnd" timing is accurate
setTimeout(sendFakeTiming)
})
}
/**

@@ -227,11 +207,5 @@ * first-input timing entry polyfill based on

const rumAllowedPerformanceEntries = rumPerformanceEntries.filter((entry) => !isIncompleteNavigation(entry))
if (rumAllowedPerformanceEntries.length) {
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, rumAllowedPerformanceEntries)
if (rumPerformanceEntries.length) {
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, rumPerformanceEntries)
}
}
function isIncompleteNavigation(entry: RumPerformanceEntry) {
return entry.entryType === RumPerformanceEntryType.NAVIGATION && entry.loadEventEnd <= 0
}

@@ -146,48 +146,60 @@ import type { Duration, RelativeTime, TimeoutId } from '@datadog/browser-core'

return new Observable<Array<EntryTypeToReturnType[T]>>((observable) => {
let observer: PerformanceObserver | undefined
if (!window.PerformanceObserver) {
return
}
const handlePerformanceEntries = (entries: PerformanceEntryList) => {
const rumPerformanceEntries = filterRumPerformanceEntries(
configuration,
entries as Array<EntryTypeToReturnType[T]>
)
if (rumPerformanceEntries.length > 0) {
observable.notify(rumPerformanceEntries)
}
}
let timeoutId: TimeoutId | undefined
if (window.PerformanceObserver) {
let isObserverInitializing = true
const handlePerformanceEntries = (entries: PerformanceEntryList) => {
const rumPerformanceEntries = filterRumPerformanceEntries(
configuration,
entries as Array<EntryTypeToReturnType[T]>
)
if (rumPerformanceEntries.length > 0) {
observable.notify(rumPerformanceEntries)
let isObserverInitializing = true
const observer = new PerformanceObserver(
monitor((entries) => {
// In Safari the performance observer callback is synchronous.
// Because the buffered performance entry list can be quite large we delay the computation to prevent the SDK from blocking the main thread on init
if (isObserverInitializing) {
timeoutId = setTimeout(() => handlePerformanceEntries(entries.getEntries()))
} else {
handlePerformanceEntries(entries.getEntries())
}
}
observer = new PerformanceObserver(
monitor((entries) => {
// In Safari the performance observer callback is synchronous.
// Because the buffered performance entry list can be quite large we delay the computation to prevent the SDK from blocking the main thread on init
if (isObserverInitializing) {
timeoutId = setTimeout(() => handlePerformanceEntries(entries.getEntries()))
} else {
handlePerformanceEntries(entries.getEntries())
}
})
)
try {
observer.observe(options)
} catch {
// Some old browser versions (<= chrome 74 ) don't support the PerformanceObserver type and buffered options
// In these cases, fallback to getEntriesByType and PerformanceObserver with entryTypes
// TODO: remove this fallback in the next major version
const fallbackSupportedEntryTypes = [
RumPerformanceEntryType.RESOURCE,
RumPerformanceEntryType.NAVIGATION,
RumPerformanceEntryType.LONG_TASK,
RumPerformanceEntryType.PAINT,
]
if (includes(fallbackSupportedEntryTypes, options.type)) {
if (options.buffered) {
timeoutId = setTimeout(() => handlePerformanceEntries(performance.getEntriesByType(options.type)))
}
})
)
try {
observer.observe(options)
} catch {
// Some old browser versions (<= chrome 74 ) don't support the PerformanceObserver type and buffered options
// In these cases, fallback to getEntriesByType and PerformanceObserver with entryTypes
// TODO: remove this fallback in the next major version
const fallbackSupportedEntryTypes = [
RumPerformanceEntryType.RESOURCE,
RumPerformanceEntryType.NAVIGATION,
RumPerformanceEntryType.LONG_TASK,
RumPerformanceEntryType.PAINT,
]
if (includes(fallbackSupportedEntryTypes, options.type)) {
if (options.buffered) {
timeoutId = setTimeout(() => handlePerformanceEntries(performance.getEntriesByType(options.type)))
}
try {
observer.observe({ entryTypes: [options.type] })
} catch {
// Old versions of Safari are throwing "entryTypes contained only unsupported types"
// errors when observing only unsupported entry types.
//
// We could use `supportPerformanceTimingEvent` to make sure we don't invoke
// `observer.observe` with an unsupported entry type, but Safari 11 and 12 don't support
// `Performance.supportedEntryTypes`, so doing so would lose support for these versions
// even if they do support the entry type.
return
}
}
isObserverInitializing = false
}
isObserverInitializing = false

@@ -197,6 +209,4 @@ manageResourceTimingBufferFull(configuration)

return () => {
observer?.disconnect()
if (timeoutId) {
clearTimeout(timeoutId)
}
observer.disconnect()
clearTimeout(timeoutId)
}

@@ -235,7 +245,7 @@ })

) {
return entries.filter((entry) => isAllowedResource(configuration, entry))
return entries.filter((entry) => !isForbiddenResource(configuration, entry))
}
function isAllowedResource(configuration: RumConfiguration, entry: RumPerformanceEntry) {
return entry.entryType === RumPerformanceEntryType.RESOURCE && isAllowedRequestUrl(configuration, entry.name)
function isForbiddenResource(configuration: RumConfiguration, entry: RumPerformanceEntry) {
return entry.entryType === RumPerformanceEntryType.RESOURCE && !isAllowedRequestUrl(configuration, entry.name)
}

@@ -65,3 +65,3 @@ // https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/selector/escapeSelector.js

const classes = element.getAttribute('class')?.trim()
const classes = (element.getAttribute('class') || '').trim()
return classes ? classes.split(/\s+/) : []

@@ -72,2 +72,3 @@ }

const PLACEHOLDER = 1
// eslint-disable-next-line no-restricted-syntax
export class WeakSet<T extends object> {

@@ -74,0 +75,0 @@ private map = new WeakMap<T, typeof PLACEHOLDER>()

@@ -1,2 +0,2 @@

import type { Duration, ClocksState, RelativeTime, TimeStamp } from '@datadog/browser-core'
import type { Duration, ClocksState, RelativeTime, TimeStamp, ValueHistory } from '@datadog/browser-core'
import {

@@ -9,3 +9,2 @@ includes,

ONE_MINUTE,
ValueHistory,
generateUUID,

@@ -15,2 +14,3 @@ clocksNow,

elapsed,
createValueHistory,
} from '@datadog/browser-core'

@@ -72,3 +72,3 @@ import type { FrustrationType } from '../../rawRumEvent.types'

) {
const history: ClickActionIdHistory = new ValueHistory(ACTION_CONTEXT_TIME_OUT_DELAY)
const history: ClickActionIdHistory = createValueHistory({ expireDelay: ACTION_CONTEXT_TIME_OUT_DELAY })
const stopObservable = new Observable<void>()

@@ -75,0 +75,0 @@ let currentClickChain: ClickChain | undefined

@@ -229,2 +229,3 @@ import type { Context, RawError, EventRateLimiter, User } from '@datadog/browser-core'

const rateLimitReached = eventRateLimiters[event.type]?.isLimitReached()
return !rateLimitReached

@@ -231,0 +232,0 @@ }

@@ -11,7 +11,5 @@ import type { Configuration, InitConfiguration, MatchOption, RawTelemetryConfiguration } from '@datadog/browser-core'

display,
isPercentage,
objectHasValue,
validateAndBuildConfiguration,
isExperimentalFeatureEnabled,
ExperimentalFeature,
isSampleRate,
} from '@datadog/browser-core'

@@ -135,3 +133,3 @@ import type { RumEventDomainContext } from '../../domainContext.types'

*/
plugins?: RumPlugin[] | undefined
betaPlugins?: RumPlugin[] | undefined
}

@@ -174,14 +172,8 @@

if (
initConfiguration.sessionReplaySampleRate !== undefined &&
!isPercentage(initConfiguration.sessionReplaySampleRate)
!isSampleRate(initConfiguration.sessionReplaySampleRate, 'Session Replay') ||
!isSampleRate(initConfiguration.traceSampleRate, 'Trace')
) {
display.error('Session Replay Sample Rate should be a number between 0 and 100')
return
}
if (initConfiguration.traceSampleRate !== undefined && !isPercentage(initConfiguration.traceSampleRate)) {
display.error('Trace Sample Rate should be a number between 0 and 100')
return
}
if (initConfiguration.excludedActivityUrls !== undefined && !Array.isArray(initConfiguration.excludedActivityUrls)) {

@@ -227,3 +219,3 @@ display.error('Excluded Activity Urls should be an array')

: TraceContextInjection.ALL,
plugins: (isExperimentalFeatureEnabled(ExperimentalFeature.PLUGINS) && initConfiguration.plugins) || [],
plugins: initConfiguration.betaPlugins || [],
},

@@ -238,30 +230,29 @@ baseConfiguration

function validateAndBuildTracingOptions(initConfiguration: RumInitConfiguration): TracingOption[] | undefined {
if (initConfiguration.allowedTracingUrls !== undefined) {
if (!Array.isArray(initConfiguration.allowedTracingUrls)) {
display.error('Allowed Tracing URLs should be an array')
return
if (initConfiguration.allowedTracingUrls === undefined) {
return []
}
if (!Array.isArray(initConfiguration.allowedTracingUrls)) {
display.error('Allowed Tracing URLs should be an array')
return
}
if (initConfiguration.allowedTracingUrls.length !== 0 && initConfiguration.service === undefined) {
display.error('Service needs to be configured when tracing is enabled')
return
}
// Convert from (MatchOption | TracingOption) to TracingOption, remove unknown properties
const tracingOptions: TracingOption[] = []
initConfiguration.allowedTracingUrls.forEach((option) => {
if (isMatchOption(option)) {
tracingOptions.push({ match: option, propagatorTypes: DEFAULT_PROPAGATOR_TYPES })
} else if (isTracingOption(option)) {
tracingOptions.push(option)
} else {
display.warn(
'Allowed Tracing Urls parameters should be a string, RegExp, function, or an object. Ignoring parameter',
option
)
}
if (initConfiguration.allowedTracingUrls.length !== 0 && initConfiguration.service === undefined) {
display.error('Service needs to be configured when tracing is enabled')
return
}
// Convert from (MatchOption | TracingOption) to TracingOption, remove unknown properties
const tracingOptions: TracingOption[] = []
initConfiguration.allowedTracingUrls.forEach((option) => {
if (isMatchOption(option)) {
tracingOptions.push({ match: option, propagatorTypes: DEFAULT_PROPAGATOR_TYPES })
} else if (isTracingOption(option)) {
tracingOptions.push(option)
} else {
display.warn(
'Allowed Tracing Urls parameters should be a string, RegExp, function, or an object. Ignoring parameter',
option
)
}
})
})
return tracingOptions
}
return []
return tracingOptions
}

@@ -312,3 +303,3 @@

track_long_task: configuration.trackLongTasks,
plugins: configuration.plugins?.map((plugin) =>
plugins: configuration.betaPlugins?.map((plugin) =>
assign({ name: plugin.name }, plugin.getConfigurationTelemetry?.())

@@ -315,0 +306,0 @@ ),

import type { RelativeTime, ContextValue, Context, CustomerDataTracker } from '@datadog/browser-core'
import { SESSION_TIME_OUT_DELAY, ValueHistory } from '@datadog/browser-core'
import { SESSION_TIME_OUT_DELAY, createValueHistory } from '@datadog/browser-core'
import type { LifeCycle } from '../lifeCycle'

@@ -29,3 +29,5 @@ import { LifeCycleEventType } from '../lifeCycle'

): FeatureFlagContexts {
const featureFlagContexts = new ValueHistory<FeatureFlagContext>(FEATURE_FLAG_CONTEXT_TIME_OUT_DELAY)
const featureFlagContexts = createValueHistory<FeatureFlagContext>({
expireDelay: FEATURE_FLAG_CONTEXT_TIME_OUT_DELAY,
})

@@ -32,0 +34,0 @@ lifeCycle.subscribe(LifeCycleEventType.BEFORE_VIEW_CREATED, ({ startClocks }) => {

import type { Duration, RelativeTime } from '@datadog/browser-core'
import {
elapsed,
ValueHistory,
createValueHistory,
SESSION_TIME_OUT_DELAY,

@@ -43,6 +43,6 @@ toServerDuration,

): PageStateHistory {
const pageStateEntryHistory = new ValueHistory<PageStateEntry>(
PAGE_STATE_CONTEXT_TIME_OUT_DELAY,
MAX_PAGE_STATE_ENTRIES
)
const pageStateEntryHistory = createValueHistory<PageStateEntry>({
expireDelay: PAGE_STATE_CONTEXT_TIME_OUT_DELAY,
maxEntries: MAX_PAGE_STATE_ENTRIES,
})

@@ -49,0 +49,0 @@ let currentPageState: PageState

import type { RelativeTime, Observable } from '@datadog/browser-core'
import { SESSION_TIME_OUT_DELAY, relativeNow, ValueHistory } from '@datadog/browser-core'
import { SESSION_TIME_OUT_DELAY, relativeNow, createValueHistory } from '@datadog/browser-core'
import type { LocationChange } from '../../browser/locationChangeObservable'

@@ -30,3 +30,3 @@ import type { LifeCycle } from '../lifeCycle'

) {
const urlContextHistory = new ValueHistory<UrlContext>(URL_CONTEXT_TIME_OUT_DELAY)
const urlContextHistory = createValueHistory<UrlContext>({ expireDelay: URL_CONTEXT_TIME_OUT_DELAY })

@@ -33,0 +33,0 @@ let previousViewUrl: string | undefined

import type { RelativeTime, ClocksState } from '@datadog/browser-core'
import { SESSION_TIME_OUT_DELAY, ValueHistory } from '@datadog/browser-core'
import { SESSION_TIME_OUT_DELAY, createValueHistory } from '@datadog/browser-core'
import type { LifeCycle } from '../lifeCycle'

@@ -23,3 +23,3 @@ import { LifeCycleEventType } from '../lifeCycle'

export function startViewContexts(lifeCycle: LifeCycle): ViewContexts {
const viewContextHistory = new ValueHistory<ViewContext>(VIEW_CONTEXT_TIME_OUT_DELAY)
const viewContextHistory = createValueHistory<ViewContext>({ expireDelay: VIEW_CONTEXT_TIME_OUT_DELAY })

@@ -26,0 +26,0 @@ lifeCycle.subscribe(LifeCycleEventType.BEFORE_VIEW_CREATED, (view) => {

@@ -26,3 +26,3 @@ import type { ClocksState, Duration } from '@datadog/browser-core'

import { PageState } from '../contexts/pageStateHistory'
import { TraceIdentifier } from '../tracing/tracer'
import { createTraceIdentifier } from '../tracing/tracer'
import { matchRequestTiming } from './matchRequestTiming'

@@ -43,3 +43,4 @@ import {

configuration: RumConfiguration,
pageStateHistory: PageStateHistory
pageStateHistory: PageStateHistory,
retrieveInitialDocumentResourceTimingImpl = retrieveInitialDocumentResourceTiming
) {

@@ -67,3 +68,3 @@ lifeCycle.subscribe(LifeCycleEventType.REQUEST_COMPLETED, (request: RequestCompleteEvent) => {

retrieveInitialDocumentResourceTiming(configuration, (timing) => {
retrieveInitialDocumentResourceTimingImpl(configuration, (timing) => {
const rawEvent = processResourceEntry(timing, configuration)

@@ -211,3 +212,3 @@ if (rawEvent) {

trace_id: entry.traceId,
span_id: new TraceIdentifier().toDecimalString(),
span_id: createTraceIdentifier().toDecimalString(),
rule_psr: getRulePsr(configuration),

@@ -214,0 +215,0 @@ },

@@ -1,2 +0,2 @@

import type { RelativeTime, ServerDuration, TimeStamp } from '@datadog/browser-core'
import type { RelativeTime, ServerDuration } from '@datadog/browser-core'
import {

@@ -7,6 +7,4 @@ addTelemetryDebug,

getPathName,
getRelativeTime,
includes,
isExperimentalFeatureEnabled,
isNumber,
isValidUrl,

@@ -221,18 +219,1 @@ ResourceType,

}
export type RelativePerformanceTiming = {
-readonly [key in keyof Omit<PerformanceTiming, 'toJSON'>]: RelativeTime
}
export function computeRelativePerformanceTiming() {
const result: Partial<RelativePerformanceTiming> = {}
const timing = performance.timing
for (const key in timing) {
if (isNumber(timing[key as keyof PerformanceTiming])) {
const numberKey = key as keyof RelativePerformanceTiming
const timingElement = timing[numberKey] as TimeStamp
result[numberKey] = timingElement === 0 ? (0 as RelativeTime) : getRelativeTime(timingElement)
}
}
return result as RelativePerformanceTiming
}

@@ -7,3 +7,4 @@ import type { RelativeTime } from '@datadog/browser-core'

import { getDocumentTraceId } from '../tracing/getDocumentTraceId'
import { FAKE_INITIAL_DOCUMENT, computeRelativePerformanceTiming } from './resourceUtils'
import { computeRelativePerformanceTiming } from '../../browser/performanceUtils'
import { FAKE_INITIAL_DOCUMENT } from './resourceUtils'

@@ -10,0 +11,0 @@ export function retrieveInitialDocumentResourceTiming(

@@ -127,4 +127,4 @@ import {

context.traceId = new TraceIdentifier()
context.spanId = new TraceIdentifier()
context.traceId = createTraceIdentifier()
context.spanId = createTraceIdentifier()

@@ -138,3 +138,3 @@ inject(makeTracingHeaders(context.traceId, context.spanId, context.traceSampled, tracingOption.propagatorTypes))

function getCrypto() {
export function getCrypto() {
return window.crypto || (window as any).msCrypto

@@ -198,13 +198,19 @@ }

/* eslint-disable no-bitwise */
export class TraceIdentifier {
private buffer: Uint8Array = new Uint8Array(8)
export interface TraceIdentifier {
toDecimalString: () => string
toPaddedHexadecimalString: () => string
}
constructor() {
getCrypto().getRandomValues(this.buffer)
this.buffer[0] = this.buffer[0] & 0x7f // force 63-bit
export function createTraceIdentifier(): TraceIdentifier {
const buffer: Uint8Array = new Uint8Array(8)
getCrypto().getRandomValues(buffer)
buffer[0] = buffer[0] & 0x7f // force 63-bit
function readInt32(offset: number) {
return buffer[offset] * 16777216 + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]
}
toString(radix: number) {
let high = this.readInt32(0)
let low = this.readInt32(4)
function toString(radix: number) {
let high = readInt32(0)
let low = readInt32(4)
let str = ''

@@ -225,4 +231,4 @@

*/
toDecimalString() {
return this.toString(10)
function toDecimalString() {
return toString(10)
}

@@ -233,16 +239,12 @@

*/
toPaddedHexadecimalString() {
const traceId = this.toString(16)
function toPaddedHexadecimalString() {
const traceId = toString(16)
return Array(17 - traceId.length).join('0') + traceId
}
private readInt32(offset: number) {
return (
this.buffer[offset] * 16777216 +
(this.buffer[offset + 1] << 16) +
(this.buffer[offset + 2] << 8) +
this.buffer[offset + 3]
)
return {
toDecimalString,
toPaddedHexadecimalString,
}
}
/* eslint-enable no-bitwise */

@@ -162,3 +162,5 @@ import type { Duration, ClocksState, TimeStamp, Subscription, RelativeTime } from '@datadog/browser-core'

stop: () => {
locationChangeSubscription?.unsubscribe()
if (locationChangeSubscription) {
locationChangeSubscription.unsubscribe()
}
currentView.end()

@@ -165,0 +167,0 @@ activeViews.forEach((view) => view.stop())

@@ -28,3 +28,3 @@ import type { Duration } from '@datadog/browser-core'

const { stop: stopNavigationTracking } = trackNavigationTimings(lifeCycle, (navigationTimings) => {
const { stop: stopNavigationTracking } = trackNavigationTimings(configuration, (navigationTimings) => {
setLoadEvent(navigationTimings.loadEvent)

@@ -31,0 +31,0 @@ initialViewMetrics.navigationTimings = navigationTimings

import type { Duration } from '@datadog/browser-core'
import { relativeNow } from '@datadog/browser-core'
import { RumPerformanceEntryType } from '../../../browser/performanceObservable'
import type { LifeCycle } from '../../lifeCycle'
import { LifeCycleEventType } from '../../lifeCycle'
import { forEach, setTimeout, noop, relativeNow, runOnReadyState } from '@datadog/browser-core'
import type { RelativePerformanceTiming } from '../../../browser/performanceUtils'
import { computeRelativePerformanceTiming } from '../../../browser/performanceUtils'
import type { RumPerformanceNavigationTiming } from '../../../browser/performanceObservable'
import {
createPerformanceObservable,
RumPerformanceEntryType,
supportPerformanceTimingEvent,
} from '../../../browser/performanceObservable'
import type { RumConfiguration } from '../../configuration'

@@ -15,22 +21,51 @@ export interface NavigationTimings {

export function trackNavigationTimings(lifeCycle: LifeCycle, callback: (timings: NavigationTimings) => void) {
const { unsubscribe: stop } = lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, (entries) => {
for (const entry of entries) {
if (entry.entryType === RumPerformanceEntryType.NAVIGATION) {
callback({
domComplete: entry.domComplete,
domContentLoaded: entry.domContentLoadedEventEnd,
domInteractive: entry.domInteractive,
loadEvent: entry.loadEventEnd,
// In some cases the value reported is negative or is larger
// than the current page time. Ignore these cases:
// https://github.com/GoogleChrome/web-vitals/issues/137
// https://github.com/GoogleChrome/web-vitals/issues/162
firstByte: entry.responseStart >= 0 && entry.responseStart <= relativeNow() ? entry.responseStart : undefined,
})
}
export function trackNavigationTimings(
configuration: RumConfiguration,
callback: (timings: NavigationTimings) => void
) {
const processEntry = (entry: RumPerformanceNavigationTiming | RelativePerformanceTiming) => {
if (!isIncompleteNavigation(entry)) {
callback(processNavigationEntry(entry))
}
})
}
let stop = noop
if (supportPerformanceTimingEvent(RumPerformanceEntryType.NAVIGATION)) {
;({ unsubscribe: stop } = createPerformanceObservable(configuration, {
type: RumPerformanceEntryType.NAVIGATION,
buffered: true,
}).subscribe((entries) => forEach(entries, processEntry)))
} else {
retrieveNavigationTiming(configuration, processEntry)
}
return { stop }
}
function processNavigationEntry(entry: RumPerformanceNavigationTiming | RelativePerformanceTiming): NavigationTimings {
return {
domComplete: entry.domComplete,
domContentLoaded: entry.domContentLoadedEventEnd,
domInteractive: entry.domInteractive,
loadEvent: entry.loadEventEnd,
// In some cases the value reported is negative or is larger
// than the current page time. Ignore these cases:
// https://github.com/GoogleChrome/web-vitals/issues/137
// https://github.com/GoogleChrome/web-vitals/issues/162
firstByte: entry.responseStart >= 0 && entry.responseStart <= relativeNow() ? entry.responseStart : undefined,
}
}
function isIncompleteNavigation(entry: RumPerformanceNavigationTiming | RelativePerformanceTiming) {
return entry.loadEventEnd <= 0
}
function retrieveNavigationTiming(
configuration: RumConfiguration,
callback: (timing: RelativePerformanceTiming) => void
) {
runOnReadyState(configuration, 'complete', () => {
// Send it a bit after the actual load event, so the "loadEventEnd" timing is accurate
setTimeout(() => callback(computeRelativePerformanceTiming()))
})
}

@@ -25,3 +25,3 @@ export { RumPublicApi, makeRumPublicApi, RecorderApi, StartRecordingOptions } from './boot/rumPublicApi'

export { startRum } from './boot/startRum'
export { LifeCycle, LifeCycleEventType } from './domain/lifeCycle'
export { LifeCycle, LifeCycleEventType, RawRumEventCollectedData } from './domain/lifeCycle'
export { ViewCreatedEvent } from './domain/view/trackViews'

@@ -28,0 +28,0 @@ export { ViewContexts, ViewContext, startViewContexts } from './domain/contexts/viewContexts'

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc