Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
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 4.23.3 to 4.24.0

cjs/domain/rumEventsCollection/action/getSelectorFromElement.d.ts

4

cjs/boot/rumPublicApi.d.ts

@@ -1,6 +0,6 @@

import type { Context, InitConfiguration } from '@datadog/browser-core';
import type { Context, InitConfiguration, User } from '@datadog/browser-core';
import type { LifeCycle } from '../domain/lifeCycle';
import type { ViewContexts } from '../domain/contexts/viewContexts';
import type { RumSessionManager } from '../domain/rumSessionManager';
import type { User, ReplayStats } from '../rawRumEvent.types';
import type { ReplayStats } from '../rawRumEvent.types';
import type { RumConfiguration, RumInitConfiguration } from '../domain/configuration';

@@ -7,0 +7,0 @@ import type { ViewOptions } from '../domain/rumEventsCollection/view/trackViews';

@@ -128,8 +128,5 @@ "use strict";

setUser: (0, browser_core_1.monitor)(function (newUser) {
if (typeof newUser !== 'object' || !newUser) {
browser_core_1.display.error('Unsupported user:', newUser);
if ((0, browser_core_1.checkUser)(newUser)) {
userContextManager.setContext((0, browser_core_1.sanitizeUser)(newUser));
}
else {
userContextManager.setContext(sanitizeUser(newUser));
}
}),

@@ -139,3 +136,3 @@ getUser: (0, browser_core_1.monitor)(userContextManager.getContext),

var _a;
var sanitizedProperty = sanitizeUser((_a = {}, _a[key] = property, _a))[key];
var sanitizedProperty = (0, browser_core_1.sanitizeUser)((_a = {}, _a[key] = property, _a))[key];
userContextManager.setContextProperty(key, sanitizedProperty);

@@ -152,15 +149,2 @@ }),

return rumPublicApi;
function sanitizeUser(newUser) {
var shallowClonedUser = (0, browser_core_1.assign)(newUser, {});
if ('id' in shallowClonedUser) {
shallowClonedUser.id = String(shallowClonedUser.id);
}
if ('name' in shallowClonedUser) {
shallowClonedUser.name = String(shallowClonedUser.name);
}
if ('email' in shallowClonedUser) {
shallowClonedUser.email = String(shallowClonedUser.email);
}
return shallowClonedUser;
}
function canHandleSession(initConfiguration) {

@@ -167,0 +151,0 @@ if (!(0, browser_core_1.areCookiesAuthorized)((0, browser_core_1.buildCookieOptions)(initConfiguration))) {

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

if (!(0, browser_core_1.canUseEventBridge)()) {
(0, startRumBatch_1.startRumBatch)(configuration, lifeCycle, telemetry.observable, reportError);
var pageExitObservable = (0, browser_core_1.createPageExitObservable)();
pageExitObservable.subscribe(function (event) {
lifeCycle.notify(9 /* PAGE_EXITED */, event);
});
(0, startRumBatch_1.startRumBatch)(configuration, lifeCycle, telemetry.observable, reportError, pageExitObservable);
}

@@ -51,0 +55,0 @@ else {

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

},
browser_sdk_version: (0, browser_core_1.canUseEventBridge)() ? "4.23.3" : undefined,
browser_sdk_version: (0, browser_core_1.canUseEventBridge)() ? "4.24.0" : undefined,
},

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

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

import type { Context, RawError, RelativeTime, Subscription } from '@datadog/browser-core';
import type { Context, PageExitEvent, RawError, RelativeTime, Subscription } from '@datadog/browser-core';
import type { RumPerformanceEntry } from '../browser/performanceCollection';

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

SESSION_RENEWED = 8,
BEFORE_UNLOAD = 9,
PAGE_EXITED = 9,
RAW_RUM_EVENT_COLLECTED = 10,

@@ -34,2 +34,3 @@ RUM_EVENT_COLLECTED = 11,

notify(eventType: LifeCycleEventType.VIEW_ENDED, data: ViewEndedEvent): void;
notify(eventType: LifeCycleEventType.PAGE_EXITED, data: PageExitEvent): void;
notify(eventType: LifeCycleEventType.RAW_ERROR_COLLECTED, data: {

@@ -40,3 +41,3 @@ error: RawError;

}): void;
notify(eventType: LifeCycleEventType.SESSION_EXPIRED | LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.BEFORE_UNLOAD): void;
notify(eventType: LifeCycleEventType.SESSION_EXPIRED | LifeCycleEventType.SESSION_RENEWED): void;
notify(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, data: RawRumEventCollectedData): void;

@@ -51,2 +52,3 @@ notify(eventType: LifeCycleEventType.RUM_EVENT_COLLECTED, data: RumEvent & Context): void;

subscribe(eventType: LifeCycleEventType.VIEW_ENDED, callback: (data: ViewEndedEvent) => void): Subscription;
subscribe(eventType: LifeCycleEventType.PAGE_EXITED, callback: (data: PageExitEvent) => void): Subscription;
subscribe(eventType: LifeCycleEventType.RAW_ERROR_COLLECTED, callback: (data: {

@@ -57,3 +59,3 @@ error: RawError;

}) => void): Subscription;
subscribe(eventType: LifeCycleEventType.SESSION_EXPIRED | LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.BEFORE_UNLOAD, callback: () => void): Subscription;
subscribe(eventType: LifeCycleEventType.SESSION_EXPIRED | LifeCycleEventType.SESSION_RENEWED, callback: () => void): Subscription;
subscribe(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, callback: (data: RawRumEventCollectedData) => void): Subscription;

@@ -60,0 +62,0 @@ subscribe(eventType: LifeCycleEventType.RUM_EVENT_COLLECTED, callback: (data: RumEvent & Context) => void): Subscription;

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

var getActionNameFromElement_1 = require("./getActionNameFromElement");
var getSelectorsFromElement_1 = require("./getSelectorsFromElement");
var getSelectorFromElement_1 = require("./getSelectorFromElement");
var listenActionEvents_1 = require("./listenActionEvents");

@@ -23,3 +23,2 @@ var computeFrustration_1 = require("./computeFrustration");

});
lifeCycle.subscribe(9 /* BEFORE_UNLOAD */, stopClickChain);
lifeCycle.subscribe(4 /* VIEW_ENDED */, stopClickChain);

@@ -118,6 +117,7 @@ var stopActionEventsListener = (0, listenActionEvents_1.listenActionEvents)({

var rect = event.target.getBoundingClientRect();
target = (0, browser_core_1.assign)({
target = {
width: Math.round(rect.width),
height: Math.round(rect.height),
}, (0, getSelectorsFromElement_1.getSelectorsFromElement)(event.target, actionNameAttribute));
selector: (0, getSelectorFromElement_1.getSelectorFromElement)(event.target, actionNameAttribute),
};
position = {

@@ -124,0 +124,0 @@ // Use clientX and Y because for SVG element offsetX and Y are relatives to the <svg> element

@@ -40,5 +40,7 @@ "use strict";

// End the current view on page unload
lifeCycle.subscribe(9 /* BEFORE_UNLOAD */, function () {
currentView.end();
currentView.triggerUpdate();
lifeCycle.subscribe(9 /* PAGE_EXITED */, function (pageExitEvent) {
if (pageExitEvent.reason === "before_unload" /* UNLOADING */) {
currentView.end();
currentView.triggerUpdate();
}
});

@@ -45,0 +47,0 @@ // Session keep alive

@@ -14,2 +14,2 @@ export { RumPublicApi, makeRumPublicApi, RecorderApi, StartRum } from './boot/rumPublicApi';

export { DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE } from './domain/rumEventsCollection/action/getActionNameFromElement';
export { STABLE_ATTRIBUTES } from './domain/rumEventsCollection/action/getSelectorsFromElement';
export { STABLE_ATTRIBUTES } from './domain/rumEventsCollection/action/getSelectorFromElement';

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

Object.defineProperty(exports, "DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE", { enumerable: true, get: function () { return getActionNameFromElement_1.DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE; } });
var getSelectorsFromElement_1 = require("./domain/rumEventsCollection/action/getSelectorsFromElement");
Object.defineProperty(exports, "STABLE_ATTRIBUTES", { enumerable: true, get: function () { return getSelectorsFromElement_1.STABLE_ATTRIBUTES; } });
var getSelectorFromElement_1 = require("./domain/rumEventsCollection/action/getSelectorFromElement");
Object.defineProperty(exports, "STABLE_ATTRIBUTES", { enumerable: true, get: function () { return getSelectorFromElement_1.STABLE_ATTRIBUTES; } });
//# sourceMappingURL=index.js.map

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

import type { Context, Duration, ErrorSource, ErrorHandling, ResourceType, ServerDuration, TimeStamp, RawErrorCause } from '@datadog/browser-core';
import type { Context, Duration, ErrorSource, ErrorHandling, ResourceType, ServerDuration, TimeStamp, RawErrorCause, User } from '@datadog/browser-core';
import type { RumSessionPlan } from './domain/rumSessionManager';

@@ -212,8 +212,2 @@ export declare const enum RumEventType {

}
export interface User {
id?: string | undefined;
email?: string | undefined;
name?: string | undefined;
[key: string]: unknown;
}
export interface CommonContext {

@@ -220,0 +214,0 @@ user: User;

@@ -1,4 +0,4 @@

import type { Context, TelemetryEvent, Observable, RawError } from '@datadog/browser-core';
import type { Context, TelemetryEvent, Observable, RawError, PageExitEvent } from '@datadog/browser-core';
import type { RumConfiguration } from '../domain/configuration';
import type { LifeCycle } from '../domain/lifeCycle';
export declare function startRumBatch(configuration: RumConfiguration, lifeCycle: LifeCycle, telemetryEventObservable: Observable<TelemetryEvent & Context>, reportError: (error: RawError) => void): void;
export declare function startRumBatch(configuration: RumConfiguration, lifeCycle: LifeCycle, telemetryEventObservable: Observable<TelemetryEvent & Context>, reportError: (error: RawError) => void, pageExitObservable: Observable<PageExitEvent>): void;

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

var browser_core_1 = require("@datadog/browser-core");
function startRumBatch(configuration, lifeCycle, telemetryEventObservable, reportError) {
var batch = makeRumBatch(configuration, lifeCycle, reportError);
function startRumBatch(configuration, lifeCycle, telemetryEventObservable, reportError, pageExitObservable) {
var batch = makeRumBatch(configuration, reportError, pageExitObservable);
lifeCycle.subscribe(11 /* RUM_EVENT_COLLECTED */, function (serverRumEvent) {

@@ -19,6 +19,4 @@ if (serverRumEvent.type === "view" /* VIEW */) {

exports.startRumBatch = startRumBatch;
function makeRumBatch(configuration, lifeCycle, reportError) {
var primaryBatch = createRumBatch(configuration.rumEndpointBuilder, function () {
return lifeCycle.notify(9 /* BEFORE_UNLOAD */);
});
function makeRumBatch(configuration, reportError, pageExitObservable) {
var primaryBatch = createRumBatch(configuration.rumEndpointBuilder);
var replicaBatch;

@@ -29,4 +27,4 @@ var replica = configuration.replica;

}
function createRumBatch(endpointBuilder, unloadCallback) {
return new browser_core_1.Batch((0, browser_core_1.createHttpRequest)(endpointBuilder, configuration.batchBytesLimit, reportError), configuration.batchMessagesLimit, configuration.batchBytesLimit, configuration.messageBytesLimit, configuration.flushTimeout, unloadCallback);
function createRumBatch(endpointBuilder) {
return new browser_core_1.Batch((0, browser_core_1.createHttpRequest)(endpointBuilder, configuration.batchBytesLimit, reportError), configuration.batchMessagesLimit, configuration.batchBytesLimit, configuration.messageBytesLimit, configuration.flushTimeout, pageExitObservable);
}

@@ -33,0 +31,0 @@ function withReplicaApplicationId(message) {

@@ -1,6 +0,6 @@

import type { Context, InitConfiguration } from '@datadog/browser-core';
import type { Context, InitConfiguration, User } from '@datadog/browser-core';
import type { LifeCycle } from '../domain/lifeCycle';
import type { ViewContexts } from '../domain/contexts/viewContexts';
import type { RumSessionManager } from '../domain/rumSessionManager';
import type { User, ReplayStats } from '../rawRumEvent.types';
import type { ReplayStats } from '../rawRumEvent.types';
import type { RumConfiguration, RumInitConfiguration } from '../domain/configuration';

@@ -7,0 +7,0 @@ import type { ViewOptions } from '../domain/rumEventsCollection/view/trackViews';

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

import { willSyntheticsInjectRum, assign, BoundedBuffer, buildCookieOptions, createContextManager, deepClone, makePublicApi, monitor, clocksNow, timeStampNow, display, callMonitored, createHandlingStack, canUseEventBridge, areCookiesAuthorized, } from '@datadog/browser-core';
import { willSyntheticsInjectRum, assign, BoundedBuffer, buildCookieOptions, createContextManager, deepClone, makePublicApi, monitor, clocksNow, timeStampNow, display, callMonitored, createHandlingStack, canUseEventBridge, areCookiesAuthorized, checkUser, sanitizeUser, } from '@datadog/browser-core';
import { validateAndBuildRumConfiguration } from '../domain/configuration';

@@ -125,6 +125,3 @@ export function makeRumPublicApi(startRumImpl, recorderApi, _a) {

setUser: monitor(function (newUser) {
if (typeof newUser !== 'object' || !newUser) {
display.error('Unsupported user:', newUser);
}
else {
if (checkUser(newUser)) {
userContextManager.setContext(sanitizeUser(newUser));

@@ -148,15 +145,2 @@ }

return rumPublicApi;
function sanitizeUser(newUser) {
var shallowClonedUser = assign(newUser, {});
if ('id' in shallowClonedUser) {
shallowClonedUser.id = String(shallowClonedUser.id);
}
if ('name' in shallowClonedUser) {
shallowClonedUser.name = String(shallowClonedUser.name);
}
if ('email' in shallowClonedUser) {
shallowClonedUser.email = String(shallowClonedUser.email);
}
return shallowClonedUser;
}
function canHandleSession(initConfiguration) {

@@ -163,0 +147,0 @@ if (!areCookiesAuthorized(buildCookieOptions(initConfiguration))) {

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

import { addTelemetryConfiguration, startTelemetry, canUseEventBridge, getEventBridge, } from '@datadog/browser-core';
import { createPageExitObservable, addTelemetryConfiguration, startTelemetry, canUseEventBridge, getEventBridge, } from '@datadog/browser-core';
import { createDOMMutationObservable } from '../browser/domMutationObservable';

@@ -45,3 +45,7 @@ import { startPerformanceCollection } from '../browser/performanceCollection';

if (!canUseEventBridge()) {
startRumBatch(configuration, lifeCycle, telemetry.observable, reportError);
var pageExitObservable = createPageExitObservable();
pageExitObservable.subscribe(function (event) {
lifeCycle.notify(9 /* PAGE_EXITED */, event);
});
startRumBatch(configuration, lifeCycle, telemetry.observable, reportError, pageExitObservable);
}

@@ -48,0 +52,0 @@ else {

@@ -45,3 +45,3 @@ import { combine, isEmptyObject, limitModification, timeStampNow, currentDrift, display, createEventRateLimiter, canUseEventBridge, } from '@datadog/browser-core';

},
browser_sdk_version: canUseEventBridge() ? "4.23.3" : undefined,
browser_sdk_version: canUseEventBridge() ? "4.24.0" : undefined,
},

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

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

import type { Context, RawError, RelativeTime, Subscription } from '@datadog/browser-core';
import type { Context, PageExitEvent, RawError, RelativeTime, Subscription } from '@datadog/browser-core';
import type { RumPerformanceEntry } from '../browser/performanceCollection';

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

SESSION_RENEWED = 8,
BEFORE_UNLOAD = 9,
PAGE_EXITED = 9,
RAW_RUM_EVENT_COLLECTED = 10,

@@ -34,2 +34,3 @@ RUM_EVENT_COLLECTED = 11,

notify(eventType: LifeCycleEventType.VIEW_ENDED, data: ViewEndedEvent): void;
notify(eventType: LifeCycleEventType.PAGE_EXITED, data: PageExitEvent): void;
notify(eventType: LifeCycleEventType.RAW_ERROR_COLLECTED, data: {

@@ -40,3 +41,3 @@ error: RawError;

}): void;
notify(eventType: LifeCycleEventType.SESSION_EXPIRED | LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.BEFORE_UNLOAD): void;
notify(eventType: LifeCycleEventType.SESSION_EXPIRED | LifeCycleEventType.SESSION_RENEWED): void;
notify(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, data: RawRumEventCollectedData): void;

@@ -51,2 +52,3 @@ notify(eventType: LifeCycleEventType.RUM_EVENT_COLLECTED, data: RumEvent & Context): void;

subscribe(eventType: LifeCycleEventType.VIEW_ENDED, callback: (data: ViewEndedEvent) => void): Subscription;
subscribe(eventType: LifeCycleEventType.PAGE_EXITED, callback: (data: PageExitEvent) => void): Subscription;
subscribe(eventType: LifeCycleEventType.RAW_ERROR_COLLECTED, callback: (data: {

@@ -57,3 +59,3 @@ error: RawError;

}) => void): Subscription;
subscribe(eventType: LifeCycleEventType.SESSION_EXPIRED | LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.BEFORE_UNLOAD, callback: () => void): Subscription;
subscribe(eventType: LifeCycleEventType.SESSION_EXPIRED | LifeCycleEventType.SESSION_RENEWED, callback: () => void): Subscription;
subscribe(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, callback: (data: RawRumEventCollectedData) => void): Subscription;

@@ -60,0 +62,0 @@ subscribe(eventType: LifeCycleEventType.RUM_EVENT_COLLECTED, callback: (data: RumEvent & Context) => void): Subscription;

@@ -6,3 +6,3 @@ import { timeStampNow, isExperimentalFeatureEnabled, Observable, assign, getRelativeTime, ONE_MINUTE, ContextHistory, generateUUID, clocksNow, ONE_SECOND, elapsed, } from '@datadog/browser-core';

import { getActionNameFromElement } from './getActionNameFromElement';
import { getSelectorsFromElement } from './getSelectorsFromElement';
import { getSelectorFromElement } from './getSelectorFromElement';
import { listenActionEvents } from './listenActionEvents';

@@ -20,3 +20,2 @@ import { computeFrustration } from './computeFrustration';

});
lifeCycle.subscribe(9 /* BEFORE_UNLOAD */, stopClickChain);
lifeCycle.subscribe(4 /* VIEW_ENDED */, stopClickChain);

@@ -114,6 +113,7 @@ var stopActionEventsListener = listenActionEvents({

var rect = event.target.getBoundingClientRect();
target = assign({
target = {
width: Math.round(rect.width),
height: Math.round(rect.height),
}, getSelectorsFromElement(event.target, actionNameAttribute));
selector: getSelectorFromElement(event.target, actionNameAttribute),
};
position = {

@@ -120,0 +120,0 @@ // Use clientX and Y because for SVG element offsetX and Y are relatives to the <svg> element

@@ -37,5 +37,7 @@ import { shallowClone, assign, elapsed, generateUUID, monitor, ONE_MINUTE, throttle, clocksNow, clocksOrigin, timeStampNow, display, looksLikeRelativeTime, } from '@datadog/browser-core';

// End the current view on page unload
lifeCycle.subscribe(9 /* BEFORE_UNLOAD */, function () {
currentView.end();
currentView.triggerUpdate();
lifeCycle.subscribe(9 /* PAGE_EXITED */, function (pageExitEvent) {
if (pageExitEvent.reason === "before_unload" /* UNLOADING */) {
currentView.end();
currentView.triggerUpdate();
}
});

@@ -42,0 +44,0 @@ // Session keep alive

@@ -14,2 +14,2 @@ export { RumPublicApi, makeRumPublicApi, RecorderApi, StartRum } from './boot/rumPublicApi';

export { DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE } from './domain/rumEventsCollection/action/getActionNameFromElement';
export { STABLE_ATTRIBUTES } from './domain/rumEventsCollection/action/getSelectorsFromElement';
export { STABLE_ATTRIBUTES } from './domain/rumEventsCollection/action/getSelectorFromElement';

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

export { DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE } from './domain/rumEventsCollection/action/getActionNameFromElement';
export { STABLE_ATTRIBUTES } from './domain/rumEventsCollection/action/getSelectorsFromElement';
export { STABLE_ATTRIBUTES } from './domain/rumEventsCollection/action/getSelectorFromElement';
//# sourceMappingURL=index.js.map

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

import type { Context, Duration, ErrorSource, ErrorHandling, ResourceType, ServerDuration, TimeStamp, RawErrorCause } from '@datadog/browser-core';
import type { Context, Duration, ErrorSource, ErrorHandling, ResourceType, ServerDuration, TimeStamp, RawErrorCause, User } from '@datadog/browser-core';
import type { RumSessionPlan } from './domain/rumSessionManager';

@@ -212,8 +212,2 @@ export declare const enum RumEventType {

}
export interface User {
id?: string | undefined;
email?: string | undefined;
name?: string | undefined;
[key: string]: unknown;
}
export interface CommonContext {

@@ -220,0 +214,0 @@ user: User;

@@ -1,4 +0,4 @@

import type { Context, TelemetryEvent, Observable, RawError } from '@datadog/browser-core';
import type { Context, TelemetryEvent, Observable, RawError, PageExitEvent } from '@datadog/browser-core';
import type { RumConfiguration } from '../domain/configuration';
import type { LifeCycle } from '../domain/lifeCycle';
export declare function startRumBatch(configuration: RumConfiguration, lifeCycle: LifeCycle, telemetryEventObservable: Observable<TelemetryEvent & Context>, reportError: (error: RawError) => void): void;
export declare function startRumBatch(configuration: RumConfiguration, lifeCycle: LifeCycle, telemetryEventObservable: Observable<TelemetryEvent & Context>, reportError: (error: RawError) => void, pageExitObservable: Observable<PageExitEvent>): void;
import { Batch, combine, createHttpRequest, isTelemetryReplicationAllowed } from '@datadog/browser-core';
export function startRumBatch(configuration, lifeCycle, telemetryEventObservable, reportError) {
var batch = makeRumBatch(configuration, lifeCycle, reportError);
export function startRumBatch(configuration, lifeCycle, telemetryEventObservable, reportError, pageExitObservable) {
var batch = makeRumBatch(configuration, reportError, pageExitObservable);
lifeCycle.subscribe(11 /* RUM_EVENT_COLLECTED */, function (serverRumEvent) {

@@ -14,6 +14,4 @@ if (serverRumEvent.type === "view" /* VIEW */) {

}
function makeRumBatch(configuration, lifeCycle, reportError) {
var primaryBatch = createRumBatch(configuration.rumEndpointBuilder, function () {
return lifeCycle.notify(9 /* BEFORE_UNLOAD */);
});
function makeRumBatch(configuration, reportError, pageExitObservable) {
var primaryBatch = createRumBatch(configuration.rumEndpointBuilder);
var replicaBatch;

@@ -24,4 +22,4 @@ var replica = configuration.replica;

}
function createRumBatch(endpointBuilder, unloadCallback) {
return new Batch(createHttpRequest(endpointBuilder, configuration.batchBytesLimit, reportError), configuration.batchMessagesLimit, configuration.batchBytesLimit, configuration.messageBytesLimit, configuration.flushTimeout, unloadCallback);
function createRumBatch(endpointBuilder) {
return new Batch(createHttpRequest(endpointBuilder, configuration.batchBytesLimit, reportError), configuration.batchMessagesLimit, configuration.batchBytesLimit, configuration.messageBytesLimit, configuration.flushTimeout, pageExitObservable);
}

@@ -28,0 +26,0 @@ function withReplicaApplicationId(message) {

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

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

"dependencies": {
"@datadog/browser-core": "4.23.3"
"@datadog/browser-core": "4.24.0"
},

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

},
"gitHead": "34d32df19bb97046feb67fc585376e3b06295702"
"gitHead": "5d165e9050d3cb2554d5a402af6959c13ad3d26b"
}

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

import type { Context, InitConfiguration, TimeStamp, RelativeTime } from '@datadog/browser-core'
import type { Context, InitConfiguration, TimeStamp, RelativeTime, User } from '@datadog/browser-core'
import {

@@ -18,2 +18,4 @@ willSyntheticsInjectRum,

areCookiesAuthorized,
checkUser,
sanitizeUser,
} from '@datadog/browser-core'

@@ -23,3 +25,3 @@ import type { LifeCycle } from '../domain/lifeCycle'

import type { RumSessionManager } from '../domain/rumSessionManager'
import type { User, ReplayStats } from '../rawRumEvent.types'
import type { ReplayStats } from '../rawRumEvent.types'
import { ActionType } from '../rawRumEvent.types'

@@ -227,5 +229,3 @@ import type { RumConfiguration, RumInitConfiguration } from '../domain/configuration'

setUser: monitor((newUser: User) => {
if (typeof newUser !== 'object' || !newUser) {
display.error('Unsupported user:', newUser)
} else {
if (checkUser(newUser)) {
userContextManager.setContext(sanitizeUser(newUser as Context))

@@ -255,16 +255,2 @@ }

function sanitizeUser(newUser: Context) {
const shallowClonedUser = assign(newUser, {})
if ('id' in shallowClonedUser) {
shallowClonedUser.id = String(shallowClonedUser.id)
}
if ('name' in shallowClonedUser) {
shallowClonedUser.name = String(shallowClonedUser.name)
}
if ('email' in shallowClonedUser) {
shallowClonedUser.email = String(shallowClonedUser.email)
}
return shallowClonedUser
}
function canHandleSession(initConfiguration: RumInitConfiguration): boolean {

@@ -271,0 +257,0 @@ if (!areCookiesAuthorized(buildCookieOptions(initConfiguration))) {

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

import type { RelativeTime, Observable, RawError } from '@datadog/browser-core'
import { noop, relativeNow, isIE } from '@datadog/browser-core'
import type { RelativeTime, Observable, RawError, Duration } from '@datadog/browser-core'
import {
stopSessionManager,
toServerDuration,
ONE_SECOND,
findLast,
noop,
relativeNow,
isIE,
} from '@datadog/browser-core'
import { createNewEvent, interceptRequests } from '../../../core/test/specHelper'
import type { RumSessionManagerMock } from '../../test/mockRumSessionManager'

@@ -12,8 +21,9 @@ import { createRumSessionManagerMock } from '../../test/mockRumSessionManager'

import { startViewCollection } from '../domain/rumEventsCollection/view/viewCollection'
import type { RumEvent } from '../rumEvent.types'
import type { RumEvent, RumViewEvent } from '../rumEvent.types'
import type { LocationChange } from '../browser/locationChangeObservable'
import { startLongTaskCollection } from '../domain/rumEventsCollection/longTask/longTaskCollection'
import type { RumSessionManager } from '..'
import type { RumConfiguration } from '../domain/configuration'
import { startRumEventCollection } from './startRum'
import type { RumConfiguration, RumInitConfiguration } from '../domain/configuration'
import { RumEventType } from '../rawRumEvent.types'
import { startRum, startRumEventCollection } from './startRum'

@@ -28,3 +38,3 @@ function collectServerEvents(lifeCycle: LifeCycle) {

function startRum(
function startRumStub(
lifeCycle: LifeCycle,

@@ -82,3 +92,3 @@ configuration: RumConfiguration,

serverRumEvents = collectServerEvents(lifeCycle)
return startRum(
return startRumStub(
lifeCycle,

@@ -136,3 +146,3 @@ configuration,

serverRumEvents = collectServerEvents(lifeCycle)
return startRum(
return startRumStub(
lifeCycle,

@@ -208,3 +218,3 @@ configuration,

serverRumEvents = collectServerEvents(lifeCycle)
return startRum(
return startRumStub(
lifeCycle,

@@ -287,1 +297,42 @@ configuration,

})
describe('view events', () => {
let setupBuilder: TestSetupBuilder
let interceptor: ReturnType<typeof interceptRequests>
beforeEach(() => {
setupBuilder = setup().beforeBuild(({ configuration }) => {
startRum({} as RumInitConfiguration, configuration, () => ({ context: {}, user: {} }), noopRecorderApi)
})
interceptor = interceptRequests()
})
afterEach(() => {
stopSessionManager()
setupBuilder.cleanup()
interceptor.restore()
})
it('sends a view update on page unload', () => {
// Note: this test is intentionally very high level to make sure the view update is correctly
// made right before flushing the Batch.
// Arbitrary duration to simulate a non-zero view duration
const VIEW_DURATION = ONE_SECOND as Duration
const { clock } = setupBuilder.withFakeClock().build()
clock.tick(VIEW_DURATION)
window.dispatchEvent(createNewEvent('beforeunload'))
const lastRumEvents = interceptor.requests[interceptor.requests.length - 1].body
.split('\n')
.map((line) => JSON.parse(line) as RumEvent)
const lastRumViewEvent = findLast(
lastRumEvents,
(serverRumEvent): serverRumEvent is RumViewEvent => serverRumEvent.type === RumEventType.VIEW
)!
expect(lastRumViewEvent.view.time_spent).toBe(toServerDuration(VIEW_DURATION))
})
})
import type { Observable, TelemetryEvent, RawError } from '@datadog/browser-core'
import {
createPageExitObservable,
TelemetryService,

@@ -64,3 +65,7 @@ addTelemetryConfiguration,

if (!canUseEventBridge()) {
startRumBatch(configuration, lifeCycle, telemetry.observable, reportError)
const pageExitObservable = createPageExitObservable()
pageExitObservable.subscribe((event) => {
lifeCycle.notify(LifeCycleEventType.PAGE_EXITED, event)
})
startRumBatch(configuration, lifeCycle, telemetry.observable, reportError, pageExitObservable)
} else {

@@ -67,0 +72,0 @@ startRumEventBridge(lifeCycle)

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

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

@@ -20,3 +20,2 @@ combine,

RumContext,
User,
} from '../rawRumEvent.types'

@@ -23,0 +22,0 @@ import { RumEventType } from '../rawRumEvent.types'

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

import type { Context, RawError, RelativeTime, Subscription } from '@datadog/browser-core'
import type { Context, PageExitEvent, RawError, RelativeTime, Subscription } from '@datadog/browser-core'
import type { RumPerformanceEntry } from '../browser/performanceCollection'

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

SESSION_RENEWED,
BEFORE_UNLOAD,
PAGE_EXITED,
RAW_RUM_EVENT_COLLECTED,

@@ -49,2 +49,3 @@ RUM_EVENT_COLLECTED,

notify(eventType: LifeCycleEventType.VIEW_ENDED, data: ViewEndedEvent): void
notify(eventType: LifeCycleEventType.PAGE_EXITED, data: PageExitEvent): void
notify(

@@ -54,8 +55,3 @@ eventType: LifeCycleEventType.RAW_ERROR_COLLECTED,

): void
notify(
eventType:
| LifeCycleEventType.SESSION_EXPIRED
| LifeCycleEventType.SESSION_RENEWED
| LifeCycleEventType.BEFORE_UNLOAD
): void
notify(eventType: LifeCycleEventType.SESSION_EXPIRED | LifeCycleEventType.SESSION_RENEWED): void
notify(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, data: RawRumEventCollectedData): void

@@ -83,2 +79,3 @@ notify(eventType: LifeCycleEventType.RUM_EVENT_COLLECTED, data: RumEvent & Context): void

subscribe(eventType: LifeCycleEventType.VIEW_ENDED, callback: (data: ViewEndedEvent) => void): Subscription
subscribe(eventType: LifeCycleEventType.PAGE_EXITED, callback: (data: PageExitEvent) => void): Subscription
subscribe(

@@ -89,6 +86,3 @@ eventType: LifeCycleEventType.RAW_ERROR_COLLECTED,

subscribe(
eventType:
| LifeCycleEventType.SESSION_EXPIRED
| LifeCycleEventType.SESSION_RENEWED
| LifeCycleEventType.BEFORE_UNLOAD,
eventType: LifeCycleEventType.SESSION_EXPIRED | LifeCycleEventType.SESSION_RENEWED,
callback: () => void

@@ -95,0 +89,0 @@ ): Subscription

@@ -135,5 +135,2 @@ import type { Context, Observable, Duration } from '@datadog/browser-core'

selector: '#button',
selector_combined: '#button',
selector_stopping_when_unique: '#button',
selector_all_together: '#button',
width: 100,

@@ -140,0 +137,0 @@ height: 100,

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

import { getActionNameFromElement } from './getActionNameFromElement'
import { getSelectorsFromElement } from './getSelectorsFromElement'
import { getSelectorFromElement } from './getSelectorFromElement'
import type { MouseEventOnElement, GetUserActivity } from './listenActionEvents'

@@ -79,3 +79,2 @@ import { listenActionEvents } from './listenActionEvents'

lifeCycle.subscribe(LifeCycleEventType.BEFORE_UNLOAD, stopClickChain)
lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, stopClickChain)

@@ -217,9 +216,7 @@

const rect = event.target.getBoundingClientRect()
target = assign(
{
width: Math.round(rect.width),
height: Math.round(rect.height),
},
getSelectorsFromElement(event.target, actionNameAttribute)
)
target = {
width: Math.round(rect.width),
height: Math.round(rect.height),
selector: getSelectorFromElement(event.target, actionNameAttribute),
}
position = {

@@ -226,0 +223,0 @@ // Use clientX and Y because for SVG element offsetX and Y are relatives to the <svg> element

import type { Context, Duration, RelativeTime } from '@datadog/browser-core'
import { timeStampNow, display, relativeToClocks, relativeNow, resetExperimentalFeatures } from '@datadog/browser-core'
import {
PageExitReason,
timeStampNow,
display,
relativeToClocks,
relativeNow,
resetExperimentalFeatures,
} from '@datadog/browser-core'
import type { TestSetupBuilder, ViewTest } from '../../../../test/specHelper'

@@ -699,3 +706,3 @@ import { setup, setupViewTest } from '../../../../test/specHelper'

lifeCycle.notify(LifeCycleEventType.BEFORE_UNLOAD)
lifeCycle.notify(LifeCycleEventType.PAGE_EXITED, { reason: PageExitReason.UNLOADING })

@@ -702,0 +709,0 @@ expect(getViewUpdate(getViewUpdateCount() - 1).eventCounts.actionCount).toBe(1)

import type { Duration, ClocksState, TimeStamp, Observable, Subscription, RelativeTime } from '@datadog/browser-core'
import {
PageExitReason,
shallowClone,

@@ -129,5 +130,7 @@ assign,

// End the current view on page unload
lifeCycle.subscribe(LifeCycleEventType.BEFORE_UNLOAD, () => {
currentView.end()
currentView.triggerUpdate()
lifeCycle.subscribe(LifeCycleEventType.PAGE_EXITED, (pageExitEvent) => {
if (pageExitEvent.reason === PageExitReason.UNLOADING) {
currentView.end()
currentView.triggerUpdate()
}
})

@@ -134,0 +137,0 @@

@@ -38,2 +38,2 @@ export { RumPublicApi, makeRumPublicApi, RecorderApi, StartRum } from './boot/rumPublicApi'

export { DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE } from './domain/rumEventsCollection/action/getActionNameFromElement'
export { STABLE_ATTRIBUTES } from './domain/rumEventsCollection/action/getSelectorsFromElement'
export { STABLE_ATTRIBUTES } from './domain/rumEventsCollection/action/getSelectorFromElement'

@@ -10,2 +10,3 @@ import type {

RawErrorCause,
User,
} from '@datadog/browser-core'

@@ -244,9 +245,2 @@ import type { RumSessionPlan } from './domain/rumSessionManager'

export interface User {
id?: string | undefined
email?: string | undefined
name?: string | undefined
[key: string]: unknown
}
export interface CommonContext {

@@ -253,0 +247,0 @@ user: User

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

import type { Context, EndpointBuilder, TelemetryEvent, Observable, RawError } from '@datadog/browser-core'
import type {
Context,
EndpointBuilder,
TelemetryEvent,
Observable,
RawError,
PageExitEvent,
} from '@datadog/browser-core'
import { Batch, combine, createHttpRequest, isTelemetryReplicationAllowed } from '@datadog/browser-core'

@@ -13,5 +20,6 @@ import type { RumConfiguration } from '../domain/configuration'

telemetryEventObservable: Observable<TelemetryEvent & Context>,
reportError: (error: RawError) => void
reportError: (error: RawError) => void,
pageExitObservable: Observable<PageExitEvent>
) {
const batch = makeRumBatch(configuration, lifeCycle, reportError)
const batch = makeRumBatch(configuration, reportError, pageExitObservable)

@@ -36,8 +44,6 @@ lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, (serverRumEvent: RumEvent & Context) => {

configuration: RumConfiguration,
lifeCycle: LifeCycle,
reportError: (error: RawError) => void
reportError: (error: RawError) => void,
pageExitObservable: Observable<PageExitEvent>
): RumBatch {
const primaryBatch = createRumBatch(configuration.rumEndpointBuilder, () =>
lifeCycle.notify(LifeCycleEventType.BEFORE_UNLOAD)
)
const primaryBatch = createRumBatch(configuration.rumEndpointBuilder)

@@ -50,3 +56,3 @@ let replicaBatch: Batch | undefined

function createRumBatch(endpointBuilder: EndpointBuilder, unloadCallback?: () => void) {
function createRumBatch(endpointBuilder: EndpointBuilder) {
return new Batch(

@@ -58,3 +64,3 @@ createHttpRequest(endpointBuilder, configuration.batchBytesLimit, reportError),

configuration.flushTimeout,
unloadCallback
pageExitObservable
)

@@ -61,0 +67,0 @@ }

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