@datadog/browser-core
Advanced tools
Comparing version 4.49.0 to 4.50.0
@@ -9,3 +9,3 @@ "use strict"; | ||
var publicApi = (0, polyfills_1.assign)({ | ||
version: "4.49.0", | ||
version: "4.50.0", | ||
// This API method is intentionally not monitored, since the only thing executed is the | ||
@@ -12,0 +12,0 @@ // user-provided 'callback'. All SDK usages executed in the callback should be monitored, and |
@@ -1,2 +0,2 @@ | ||
import type { RetryInfo, FlushReason } from '../../transport'; | ||
import type { Payload } from '../../transport'; | ||
import type { InitConfiguration } from './configuration'; | ||
@@ -11,5 +11,5 @@ export declare const ENDPOINTS: { | ||
export declare function createEndpointBuilder(initConfiguration: InitConfiguration, endpointType: EndpointType, configurationTags: string[]): { | ||
build(api: 'xhr' | 'fetch' | 'beacon', flushReason?: FlushReason, retry?: RetryInfo): string; | ||
build(api: 'xhr' | 'fetch' | 'beacon', payload: Payload): string; | ||
urlPrefix: string; | ||
endpointType: "logs" | "rum" | "sessionReplay"; | ||
}; |
@@ -22,4 +22,4 @@ "use strict"; | ||
return { | ||
build: function (api, flushReason, retry) { | ||
var parameters = buildEndpointParameters(initConfiguration, endpointType, configurationTags, api, flushReason, retry); | ||
build: function (api, payload) { | ||
var parameters = buildEndpointParameters(initConfiguration, endpointType, configurationTags, api, payload); | ||
return buildUrlWithParameters(parameters); | ||
@@ -68,5 +68,6 @@ }, | ||
*/ | ||
function buildEndpointParameters(_a, endpointType, configurationTags, api, flushReason, retry) { | ||
function buildEndpointParameters(_a, endpointType, configurationTags, api, _b) { | ||
var clientToken = _a.clientToken, internalAnalyticsSubdomain = _a.internalAnalyticsSubdomain; | ||
var tags = ["sdk_version:".concat("4.49.0"), "api:".concat(api)].concat(configurationTags); | ||
var retry = _b.retry, flushReason = _b.flushReason, encoding = _b.encoding; | ||
var tags = ["sdk_version:".concat("4.50.0"), "api:".concat(api)].concat(configurationTags); | ||
if (flushReason && (0, experimentalFeatures_1.isExperimentalFeatureEnabled)(experimentalFeatures_1.ExperimentalFeature.COLLECT_FLUSH_REASON)) { | ||
@@ -82,6 +83,9 @@ tags.push("flush_reason:".concat(flushReason)); | ||
"dd-api-key=".concat(clientToken), | ||
"dd-evp-origin-version=".concat(encodeURIComponent("4.49.0")), | ||
"dd-evp-origin-version=".concat(encodeURIComponent("4.50.0")), | ||
'dd-evp-origin=browser', | ||
"dd-request-id=".concat((0, stringUtils_1.generateUUID)()), | ||
]; | ||
if (encoding) { | ||
parameters.push("dd-evp-encoding=".concat(encoding)); | ||
} | ||
if (endpointType === 'rum') { | ||
@@ -88,0 +92,0 @@ parameters.push("batch_time=".concat((0, timeUtils_1.timeStampNow)())); |
import type { ClocksState } from '../../tools/utils/timeUtils'; | ||
export interface ErrorWithCause extends Error { | ||
cause?: Error; | ||
cause?: unknown; | ||
} | ||
@@ -5,0 +5,0 @@ export type RawErrorCause = { |
@@ -10,7 +10,2 @@ import type { SessionStoreStrategy } from './storeStrategies/sessionStoreStrategy'; | ||
export declare function processSessionStoreOperations(operations: Operations, sessionStoreStrategy: SessionStoreStrategy, numberOfRetries?: number): void; | ||
/** | ||
* Lock strategy allows mitigating issues due to concurrent access to cookie. | ||
* This issue concerns only chromium browsers and enabling this on firefox increases cookie write failures. | ||
*/ | ||
export declare const isLockEnabled: () => boolean; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isLockEnabled = exports.processSessionStoreOperations = exports.LOCK_MAX_TRIES = exports.LOCK_RETRY_DELAY = void 0; | ||
exports.processSessionStoreOperations = exports.LOCK_MAX_TRIES = exports.LOCK_RETRY_DELAY = void 0; | ||
var timer_1 = require("../../tools/timer"); | ||
var stringUtils_1 = require("../../tools/utils/stringUtils"); | ||
var browserDetection_1 = require("../../tools/utils/browserDetection"); | ||
var sessionState_1 = require("./sessionState"); | ||
@@ -15,4 +14,3 @@ exports.LOCK_RETRY_DELAY = 10; | ||
if (numberOfRetries === void 0) { numberOfRetries = 0; } | ||
var retrieveSession = sessionStoreStrategy.retrieveSession, persistSession = sessionStoreStrategy.persistSession, clearSession = sessionStoreStrategy.clearSession; | ||
var lockEnabled = (0, exports.isLockEnabled)(); | ||
var isLockEnabled = sessionStoreStrategy.isLockEnabled, retrieveSession = sessionStoreStrategy.retrieveSession, persistSession = sessionStoreStrategy.persistSession, clearSession = sessionStoreStrategy.clearSession; | ||
if (!ongoingOperations) { | ||
@@ -25,3 +23,3 @@ ongoingOperations = operations; | ||
} | ||
if (lockEnabled && numberOfRetries >= exports.LOCK_MAX_TRIES) { | ||
if (isLockEnabled && numberOfRetries >= exports.LOCK_MAX_TRIES) { | ||
next(sessionStoreStrategy); | ||
@@ -32,3 +30,3 @@ return; | ||
var currentSession = retrieveSession(); | ||
if (lockEnabled) { | ||
if (isLockEnabled) { | ||
// if someone has lock, retry later | ||
@@ -51,3 +49,3 @@ if (currentSession.lock) { | ||
var processedSession = operations.process(currentSession); | ||
if (lockEnabled) { | ||
if (isLockEnabled) { | ||
// if lock corrupted after process, retry later | ||
@@ -69,3 +67,3 @@ currentSession = retrieveSession(); | ||
} | ||
if (lockEnabled) { | ||
if (isLockEnabled) { | ||
// correctly handle lock around expiration would require to handle this case properly at several levels | ||
@@ -91,8 +89,2 @@ // since we don't have evidence of lock issues around expiration, let's just not do the corruption check for it | ||
exports.processSessionStoreOperations = processSessionStoreOperations; | ||
/** | ||
* Lock strategy allows mitigating issues due to concurrent access to cookie. | ||
* This issue concerns only chromium browsers and enabling this on firefox increases cookie write failures. | ||
*/ | ||
var isLockEnabled = function () { return (0, browserDetection_1.isChromium)(); }; | ||
exports.isLockEnabled = isLockEnabled; | ||
function retryLater(operations, sessionStore, currentNumberOfRetries) { | ||
@@ -99,0 +91,0 @@ (0, timer_1.setTimeout)(function () { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.buildCookieOptions = exports.initCookieStrategy = exports.selectCookieStrategy = void 0; | ||
var browserDetection_1 = require("../../../tools/utils/browserDetection"); | ||
var cookie_1 = require("../../../browser/cookie"); | ||
@@ -16,2 +17,7 @@ var oldCookiesMigration_1 = require("../oldCookiesMigration"); | ||
var cookieStore = { | ||
/** | ||
* Lock strategy allows mitigating issues due to concurrent access to cookie. | ||
* This issue concerns only chromium browsers and enabling this on firefox increases cookie write failures. | ||
*/ | ||
isLockEnabled: (0, browserDetection_1.isChromium)(), | ||
persistSession: persistSessionCookie(cookieOptions), | ||
@@ -18,0 +24,0 @@ retrieveSession: retrieveSessionCookie, |
@@ -24,2 +24,3 @@ "use strict"; | ||
return { | ||
isLockEnabled: false, | ||
persistSession: persistInLocalStorage, | ||
@@ -26,0 +27,0 @@ retrieveSession: retrieveSessionFromLocalStorage, |
@@ -11,2 +11,3 @@ import type { CookieOptions } from '../../../browser/cookie'; | ||
export interface SessionStoreStrategy { | ||
isLockEnabled: boolean; | ||
persistSession: (session: SessionState) => void; | ||
@@ -13,0 +14,0 @@ retrieveSession: () => SessionState; |
@@ -54,3 +54,3 @@ "use strict"; | ||
service: telemetryService, | ||
version: "4.49.0", | ||
version: "4.50.0", | ||
source: 'browser', | ||
@@ -57,0 +57,0 @@ _dd: { |
@@ -40,7 +40,8 @@ "use strict"; | ||
exports.globalConsole = console; | ||
exports.display.debug = exports.globalConsole.debug.bind(exports.globalConsole); | ||
exports.display.log = exports.globalConsole.log.bind(exports.globalConsole); | ||
exports.display.info = exports.globalConsole.info.bind(exports.globalConsole); | ||
exports.display.warn = exports.globalConsole.warn.bind(exports.globalConsole); | ||
exports.display.error = exports.globalConsole.error.bind(exports.globalConsole); | ||
var PREFIX = 'Datadog Browser SDK:'; | ||
exports.display.debug = exports.globalConsole.debug.bind(exports.globalConsole, PREFIX); | ||
exports.display.log = exports.globalConsole.log.bind(exports.globalConsole, PREFIX); | ||
exports.display.info = exports.globalConsole.info.bind(exports.globalConsole, PREFIX); | ||
exports.display.warn = exports.globalConsole.warn.bind(exports.globalConsole, PREFIX); | ||
exports.display.error = exports.globalConsole.error.bind(exports.globalConsole, PREFIX); | ||
//# sourceMappingURL=display.js.map |
@@ -19,2 +19,3 @@ /** | ||
INTERACTION_TO_NEXT_PAINT = "interaction_to_next_paint", | ||
WEB_VITALS_ATTRIBUTION = "web_vitals_attribution", | ||
DISABLE_REPLAY_INLINE_CSS = "disable_replay_inline_css" | ||
@@ -21,0 +22,0 @@ } |
@@ -26,2 +26,3 @@ "use strict"; | ||
ExperimentalFeature["INTERACTION_TO_NEXT_PAINT"] = "interaction_to_next_paint"; | ||
ExperimentalFeature["WEB_VITALS_ATTRIBUTION"] = "web_vitals_attribution"; | ||
ExperimentalFeature["DISABLE_REPLAY_INLINE_CSS"] = "disable_replay_inline_css"; | ||
@@ -28,0 +29,0 @@ })(ExperimentalFeature || (exports.ExperimentalFeature = ExperimentalFeature = {})); |
@@ -23,2 +23,3 @@ import type { EndpointBuilder, Configuration } from '../domain/configuration'; | ||
flushReason?: FlushReason; | ||
encoding?: 'deflate'; | ||
} | ||
@@ -37,3 +38,3 @@ export interface RetryInfo { | ||
}; | ||
export declare function fetchKeepAliveStrategy(configuration: Configuration, endpointBuilder: EndpointBuilder, bytesLimit: number, { data, bytesCount, flushReason, retry }: Payload, onResponse?: (r: HttpResponse) => void): void; | ||
export declare function fetchKeepAliveStrategy(configuration: Configuration, endpointBuilder: EndpointBuilder, bytesLimit: number, payload: Payload, onResponse?: (r: HttpResponse) => void): void; | ||
export declare function sendXHR(configuration: Configuration, url: string, data: Payload['data'], onResponse?: (r: HttpResponse) => void): void; |
@@ -27,9 +27,8 @@ "use strict"; | ||
exports.createHttpRequest = createHttpRequest; | ||
function sendBeaconStrategy(configuration, endpointBuilder, bytesLimit, _a) { | ||
var data = _a.data, bytesCount = _a.bytesCount, flushReason = _a.flushReason; | ||
var canUseBeacon = !!navigator.sendBeacon && bytesCount < bytesLimit; | ||
function sendBeaconStrategy(configuration, endpointBuilder, bytesLimit, payload) { | ||
var canUseBeacon = !!navigator.sendBeacon && payload.bytesCount < bytesLimit; | ||
if (canUseBeacon) { | ||
try { | ||
var beaconUrl = endpointBuilder.build('beacon', flushReason); | ||
var isQueued = navigator.sendBeacon(beaconUrl, data); | ||
var beaconUrl = endpointBuilder.build('beacon', payload); | ||
var isQueued = navigator.sendBeacon(beaconUrl, payload.data); | ||
if (isQueued) { | ||
@@ -43,4 +42,4 @@ return; | ||
} | ||
var xhrUrl = endpointBuilder.build('xhr', flushReason); | ||
sendXHR(configuration, xhrUrl, data); | ||
var xhrUrl = endpointBuilder.build('xhr', payload); | ||
sendXHR(configuration, xhrUrl, payload.data); | ||
} | ||
@@ -54,16 +53,15 @@ var hasReportedBeaconError = false; | ||
} | ||
function fetchKeepAliveStrategy(configuration, endpointBuilder, bytesLimit, _a, onResponse) { | ||
var data = _a.data, bytesCount = _a.bytesCount, flushReason = _a.flushReason, retry = _a.retry; | ||
var canUseKeepAlive = isKeepAliveSupported() && bytesCount < bytesLimit; | ||
function fetchKeepAliveStrategy(configuration, endpointBuilder, bytesLimit, payload, onResponse) { | ||
var canUseKeepAlive = isKeepAliveSupported() && payload.bytesCount < bytesLimit; | ||
if (canUseKeepAlive) { | ||
var fetchUrl = endpointBuilder.build('fetch', flushReason, retry); | ||
fetch(fetchUrl, { method: 'POST', body: data, keepalive: true, mode: 'cors' }).then((0, monitor_1.monitor)(function (response) { return onResponse === null || onResponse === void 0 ? void 0 : onResponse({ status: response.status, type: response.type }); }), (0, monitor_1.monitor)(function () { | ||
var xhrUrl = endpointBuilder.build('xhr', flushReason, retry); | ||
var fetchUrl = endpointBuilder.build('fetch', payload); | ||
fetch(fetchUrl, { method: 'POST', body: payload.data, keepalive: true, mode: 'cors' }).then((0, monitor_1.monitor)(function (response) { return onResponse === null || onResponse === void 0 ? void 0 : onResponse({ status: response.status, type: response.type }); }), (0, monitor_1.monitor)(function () { | ||
var xhrUrl = endpointBuilder.build('xhr', payload); | ||
// failed to queue the request | ||
sendXHR(configuration, xhrUrl, data, onResponse); | ||
sendXHR(configuration, xhrUrl, payload.data, onResponse); | ||
})); | ||
} | ||
else { | ||
var xhrUrl = endpointBuilder.build('xhr', flushReason, retry); | ||
sendXHR(configuration, xhrUrl, data, onResponse); | ||
var xhrUrl = endpointBuilder.build('xhr', payload); | ||
sendXHR(configuration, xhrUrl, payload.data, onResponse); | ||
} | ||
@@ -70,0 +68,0 @@ } |
@@ -6,3 +6,3 @@ import { catchUserErrors } from '../tools/catchUserErrors'; | ||
var publicApi = assign({ | ||
version: "4.49.0", | ||
version: "4.50.0", | ||
// This API method is intentionally not monitored, since the only thing executed is the | ||
@@ -9,0 +9,0 @@ // user-provided 'callback'. All SDK usages executed in the callback should be monitored, and |
@@ -1,2 +0,2 @@ | ||
import type { RetryInfo, FlushReason } from '../../transport'; | ||
import type { Payload } from '../../transport'; | ||
import type { InitConfiguration } from './configuration'; | ||
@@ -11,5 +11,5 @@ export declare const ENDPOINTS: { | ||
export declare function createEndpointBuilder(initConfiguration: InitConfiguration, endpointType: EndpointType, configurationTags: string[]): { | ||
build(api: 'xhr' | 'fetch' | 'beacon', flushReason?: FlushReason, retry?: RetryInfo): string; | ||
build(api: 'xhr' | 'fetch' | 'beacon', payload: Payload): string; | ||
urlPrefix: string; | ||
endpointType: "logs" | "rum" | "sessionReplay"; | ||
}; |
@@ -19,4 +19,4 @@ import { timeStampNow } from '../../tools/utils/timeUtils'; | ||
return { | ||
build: function (api, flushReason, retry) { | ||
var parameters = buildEndpointParameters(initConfiguration, endpointType, configurationTags, api, flushReason, retry); | ||
build: function (api, payload) { | ||
var parameters = buildEndpointParameters(initConfiguration, endpointType, configurationTags, api, payload); | ||
return buildUrlWithParameters(parameters); | ||
@@ -64,5 +64,6 @@ }, | ||
*/ | ||
function buildEndpointParameters(_a, endpointType, configurationTags, api, flushReason, retry) { | ||
function buildEndpointParameters(_a, endpointType, configurationTags, api, _b) { | ||
var clientToken = _a.clientToken, internalAnalyticsSubdomain = _a.internalAnalyticsSubdomain; | ||
var tags = ["sdk_version:".concat("4.49.0"), "api:".concat(api)].concat(configurationTags); | ||
var retry = _b.retry, flushReason = _b.flushReason, encoding = _b.encoding; | ||
var tags = ["sdk_version:".concat("4.50.0"), "api:".concat(api)].concat(configurationTags); | ||
if (flushReason && isExperimentalFeatureEnabled(ExperimentalFeature.COLLECT_FLUSH_REASON)) { | ||
@@ -78,6 +79,9 @@ tags.push("flush_reason:".concat(flushReason)); | ||
"dd-api-key=".concat(clientToken), | ||
"dd-evp-origin-version=".concat(encodeURIComponent("4.49.0")), | ||
"dd-evp-origin-version=".concat(encodeURIComponent("4.50.0")), | ||
'dd-evp-origin=browser', | ||
"dd-request-id=".concat(generateUUID()), | ||
]; | ||
if (encoding) { | ||
parameters.push("dd-evp-encoding=".concat(encoding)); | ||
} | ||
if (endpointType === 'rum') { | ||
@@ -84,0 +88,0 @@ parameters.push("batch_time=".concat(timeStampNow())); |
import type { ClocksState } from '../../tools/utils/timeUtils'; | ||
export interface ErrorWithCause extends Error { | ||
cause?: Error; | ||
cause?: unknown; | ||
} | ||
@@ -5,0 +5,0 @@ export type RawErrorCause = { |
@@ -10,7 +10,2 @@ import type { SessionStoreStrategy } from './storeStrategies/sessionStoreStrategy'; | ||
export declare function processSessionStoreOperations(operations: Operations, sessionStoreStrategy: SessionStoreStrategy, numberOfRetries?: number): void; | ||
/** | ||
* Lock strategy allows mitigating issues due to concurrent access to cookie. | ||
* This issue concerns only chromium browsers and enabling this on firefox increases cookie write failures. | ||
*/ | ||
export declare const isLockEnabled: () => boolean; | ||
export {}; |
import { setTimeout } from '../../tools/timer'; | ||
import { generateUUID } from '../../tools/utils/stringUtils'; | ||
import { isChromium } from '../../tools/utils/browserDetection'; | ||
import { expandSessionState, isSessionInExpiredState } from './sessionState'; | ||
@@ -12,4 +11,3 @@ export var LOCK_RETRY_DELAY = 10; | ||
if (numberOfRetries === void 0) { numberOfRetries = 0; } | ||
var retrieveSession = sessionStoreStrategy.retrieveSession, persistSession = sessionStoreStrategy.persistSession, clearSession = sessionStoreStrategy.clearSession; | ||
var lockEnabled = isLockEnabled(); | ||
var isLockEnabled = sessionStoreStrategy.isLockEnabled, retrieveSession = sessionStoreStrategy.retrieveSession, persistSession = sessionStoreStrategy.persistSession, clearSession = sessionStoreStrategy.clearSession; | ||
if (!ongoingOperations) { | ||
@@ -22,3 +20,3 @@ ongoingOperations = operations; | ||
} | ||
if (lockEnabled && numberOfRetries >= LOCK_MAX_TRIES) { | ||
if (isLockEnabled && numberOfRetries >= LOCK_MAX_TRIES) { | ||
next(sessionStoreStrategy); | ||
@@ -29,3 +27,3 @@ return; | ||
var currentSession = retrieveSession(); | ||
if (lockEnabled) { | ||
if (isLockEnabled) { | ||
// if someone has lock, retry later | ||
@@ -48,3 +46,3 @@ if (currentSession.lock) { | ||
var processedSession = operations.process(currentSession); | ||
if (lockEnabled) { | ||
if (isLockEnabled) { | ||
// if lock corrupted after process, retry later | ||
@@ -66,3 +64,3 @@ currentSession = retrieveSession(); | ||
} | ||
if (lockEnabled) { | ||
if (isLockEnabled) { | ||
// correctly handle lock around expiration would require to handle this case properly at several levels | ||
@@ -87,7 +85,2 @@ // since we don't have evidence of lock issues around expiration, let's just not do the corruption check for it | ||
} | ||
/** | ||
* Lock strategy allows mitigating issues due to concurrent access to cookie. | ||
* This issue concerns only chromium browsers and enabling this on firefox increases cookie write failures. | ||
*/ | ||
export var isLockEnabled = function () { return isChromium(); }; | ||
function retryLater(operations, sessionStore, currentNumberOfRetries) { | ||
@@ -94,0 +87,0 @@ setTimeout(function () { |
@@ -0,1 +1,2 @@ | ||
import { isChromium } from '../../../tools/utils/browserDetection'; | ||
import { getCurrentSite, areCookiesAuthorized, deleteCookie, getCookie, setCookie } from '../../../browser/cookie'; | ||
@@ -12,2 +13,7 @@ import { tryOldCookiesMigration } from '../oldCookiesMigration'; | ||
var cookieStore = { | ||
/** | ||
* Lock strategy allows mitigating issues due to concurrent access to cookie. | ||
* This issue concerns only chromium browsers and enabling this on firefox increases cookie write failures. | ||
*/ | ||
isLockEnabled: isChromium(), | ||
persistSession: persistSessionCookie(cookieOptions), | ||
@@ -14,0 +20,0 @@ retrieveSession: retrieveSessionCookie, |
@@ -20,2 +20,3 @@ import { generateUUID } from '../../../tools/utils/stringUtils'; | ||
return { | ||
isLockEnabled: false, | ||
persistSession: persistInLocalStorage, | ||
@@ -22,0 +23,0 @@ retrieveSession: retrieveSessionFromLocalStorage, |
@@ -11,2 +11,3 @@ import type { CookieOptions } from '../../../browser/cookie'; | ||
export interface SessionStoreStrategy { | ||
isLockEnabled: boolean; | ||
persistSession: (session: SessionState) => void; | ||
@@ -13,0 +14,0 @@ retrieveSession: () => SessionState; |
@@ -51,3 +51,3 @@ import { ConsoleApiName } from '../../tools/display'; | ||
service: telemetryService, | ||
version: "4.49.0", | ||
version: "4.50.0", | ||
source: 'browser', | ||
@@ -54,0 +54,0 @@ _dd: { |
@@ -36,7 +36,8 @@ /* eslint-disable local-rules/disallow-side-effects */ | ||
export var globalConsole = console; | ||
display.debug = globalConsole.debug.bind(globalConsole); | ||
display.log = globalConsole.log.bind(globalConsole); | ||
display.info = globalConsole.info.bind(globalConsole); | ||
display.warn = globalConsole.warn.bind(globalConsole); | ||
display.error = globalConsole.error.bind(globalConsole); | ||
var PREFIX = 'Datadog Browser SDK:'; | ||
display.debug = globalConsole.debug.bind(globalConsole, PREFIX); | ||
display.log = globalConsole.log.bind(globalConsole, PREFIX); | ||
display.info = globalConsole.info.bind(globalConsole, PREFIX); | ||
display.warn = globalConsole.warn.bind(globalConsole, PREFIX); | ||
display.error = globalConsole.error.bind(globalConsole, PREFIX); | ||
//# sourceMappingURL=display.js.map |
@@ -19,2 +19,3 @@ /** | ||
INTERACTION_TO_NEXT_PAINT = "interaction_to_next_paint", | ||
WEB_VITALS_ATTRIBUTION = "web_vitals_attribution", | ||
DISABLE_REPLAY_INLINE_CSS = "disable_replay_inline_css" | ||
@@ -21,0 +22,0 @@ } |
@@ -23,2 +23,3 @@ /** | ||
ExperimentalFeature["INTERACTION_TO_NEXT_PAINT"] = "interaction_to_next_paint"; | ||
ExperimentalFeature["WEB_VITALS_ATTRIBUTION"] = "web_vitals_attribution"; | ||
ExperimentalFeature["DISABLE_REPLAY_INLINE_CSS"] = "disable_replay_inline_css"; | ||
@@ -25,0 +26,0 @@ })(ExperimentalFeature || (ExperimentalFeature = {})); |
@@ -23,2 +23,3 @@ import type { EndpointBuilder, Configuration } from '../domain/configuration'; | ||
flushReason?: FlushReason; | ||
encoding?: 'deflate'; | ||
} | ||
@@ -37,3 +38,3 @@ export interface RetryInfo { | ||
}; | ||
export declare function fetchKeepAliveStrategy(configuration: Configuration, endpointBuilder: EndpointBuilder, bytesLimit: number, { data, bytesCount, flushReason, retry }: Payload, onResponse?: (r: HttpResponse) => void): void; | ||
export declare function fetchKeepAliveStrategy(configuration: Configuration, endpointBuilder: EndpointBuilder, bytesLimit: number, payload: Payload, onResponse?: (r: HttpResponse) => void): void; | ||
export declare function sendXHR(configuration: Configuration, url: string, data: Payload['data'], onResponse?: (r: HttpResponse) => void): void; |
@@ -23,9 +23,8 @@ import { addTelemetryError } from '../domain/telemetry'; | ||
} | ||
function sendBeaconStrategy(configuration, endpointBuilder, bytesLimit, _a) { | ||
var data = _a.data, bytesCount = _a.bytesCount, flushReason = _a.flushReason; | ||
var canUseBeacon = !!navigator.sendBeacon && bytesCount < bytesLimit; | ||
function sendBeaconStrategy(configuration, endpointBuilder, bytesLimit, payload) { | ||
var canUseBeacon = !!navigator.sendBeacon && payload.bytesCount < bytesLimit; | ||
if (canUseBeacon) { | ||
try { | ||
var beaconUrl = endpointBuilder.build('beacon', flushReason); | ||
var isQueued = navigator.sendBeacon(beaconUrl, data); | ||
var beaconUrl = endpointBuilder.build('beacon', payload); | ||
var isQueued = navigator.sendBeacon(beaconUrl, payload.data); | ||
if (isQueued) { | ||
@@ -39,4 +38,4 @@ return; | ||
} | ||
var xhrUrl = endpointBuilder.build('xhr', flushReason); | ||
sendXHR(configuration, xhrUrl, data); | ||
var xhrUrl = endpointBuilder.build('xhr', payload); | ||
sendXHR(configuration, xhrUrl, payload.data); | ||
} | ||
@@ -50,16 +49,15 @@ var hasReportedBeaconError = false; | ||
} | ||
export function fetchKeepAliveStrategy(configuration, endpointBuilder, bytesLimit, _a, onResponse) { | ||
var data = _a.data, bytesCount = _a.bytesCount, flushReason = _a.flushReason, retry = _a.retry; | ||
var canUseKeepAlive = isKeepAliveSupported() && bytesCount < bytesLimit; | ||
export function fetchKeepAliveStrategy(configuration, endpointBuilder, bytesLimit, payload, onResponse) { | ||
var canUseKeepAlive = isKeepAliveSupported() && payload.bytesCount < bytesLimit; | ||
if (canUseKeepAlive) { | ||
var fetchUrl = endpointBuilder.build('fetch', flushReason, retry); | ||
fetch(fetchUrl, { method: 'POST', body: data, keepalive: true, mode: 'cors' }).then(monitor(function (response) { return onResponse === null || onResponse === void 0 ? void 0 : onResponse({ status: response.status, type: response.type }); }), monitor(function () { | ||
var xhrUrl = endpointBuilder.build('xhr', flushReason, retry); | ||
var fetchUrl = endpointBuilder.build('fetch', payload); | ||
fetch(fetchUrl, { method: 'POST', body: payload.data, keepalive: true, mode: 'cors' }).then(monitor(function (response) { return onResponse === null || onResponse === void 0 ? void 0 : onResponse({ status: response.status, type: response.type }); }), monitor(function () { | ||
var xhrUrl = endpointBuilder.build('xhr', payload); | ||
// failed to queue the request | ||
sendXHR(configuration, xhrUrl, data, onResponse); | ||
sendXHR(configuration, xhrUrl, payload.data, onResponse); | ||
})); | ||
} | ||
else { | ||
var xhrUrl = endpointBuilder.build('xhr', flushReason, retry); | ||
sendXHR(configuration, xhrUrl, data, onResponse); | ||
var xhrUrl = endpointBuilder.build('xhr', payload); | ||
sendXHR(configuration, xhrUrl, payload.data, onResponse); | ||
} | ||
@@ -66,0 +64,0 @@ } |
{ | ||
"name": "@datadog/browser-core", | ||
"version": "4.49.0", | ||
"version": "4.50.0", | ||
"license": "Apache-2.0", | ||
@@ -26,3 +26,3 @@ "main": "cjs/index.js", | ||
}, | ||
"gitHead": "4aa09a00c7457f4d4f302b15bc1c1bb645072016" | ||
"gitHead": "6bb23089915b99c9dab8edbf0131b5edc09eb4b5" | ||
} |
@@ -1,2 +0,2 @@ | ||
import type { RetryInfo, FlushReason } from '../../transport' | ||
import type { Payload } from '../../transport' | ||
import { timeStampNow } from '../../tools/utils/timeUtils' | ||
@@ -36,11 +36,4 @@ import { normalizeUrl } from '../../tools/utils/urlPolyfill' | ||
return { | ||
build(api: 'xhr' | 'fetch' | 'beacon', flushReason?: FlushReason, retry?: RetryInfo) { | ||
const parameters = buildEndpointParameters( | ||
initConfiguration, | ||
endpointType, | ||
configurationTags, | ||
api, | ||
flushReason, | ||
retry | ||
) | ||
build(api: 'xhr' | 'fetch' | 'beacon', payload: Payload) { | ||
const parameters = buildEndpointParameters(initConfiguration, endpointType, configurationTags, api, payload) | ||
return buildUrlWithParameters(parameters) | ||
@@ -104,4 +97,3 @@ }, | ||
api: 'xhr' | 'fetch' | 'beacon', | ||
flushReason: FlushReason | undefined, | ||
retry: RetryInfo | undefined | ||
{ retry, flushReason, encoding }: Payload | ||
) { | ||
@@ -115,2 +107,3 @@ const tags = [`sdk_version:${__BUILD_ENV__SDK_VERSION__}`, `api:${api}`].concat(configurationTags) | ||
} | ||
const parameters = [ | ||
@@ -125,5 +118,10 @@ 'ddsource=browser', | ||
if (encoding) { | ||
parameters.push(`dd-evp-encoding=${encoding}`) | ||
} | ||
if (endpointType === 'rum') { | ||
parameters.push(`batch_time=${timeStampNow()}`) | ||
} | ||
if (internalAnalyticsSubdomain) { | ||
@@ -130,0 +128,0 @@ parameters.reverse() |
import type { ClocksState } from '../../tools/utils/timeUtils' | ||
export interface ErrorWithCause extends Error { | ||
cause?: Error | ||
cause?: unknown | ||
} | ||
@@ -6,0 +6,0 @@ |
import { setTimeout } from '../../tools/timer' | ||
import { generateUUID } from '../../tools/utils/stringUtils' | ||
import { isChromium } from '../../tools/utils/browserDetection' | ||
import type { SessionStoreStrategy } from './storeStrategies/sessionStoreStrategy' | ||
@@ -23,4 +22,3 @@ import type { SessionState } from './sessionState' | ||
) { | ||
const { retrieveSession, persistSession, clearSession } = sessionStoreStrategy | ||
const lockEnabled = isLockEnabled() | ||
const { isLockEnabled, retrieveSession, persistSession, clearSession } = sessionStoreStrategy | ||
@@ -34,3 +32,3 @@ if (!ongoingOperations) { | ||
} | ||
if (lockEnabled && numberOfRetries >= LOCK_MAX_TRIES) { | ||
if (isLockEnabled && numberOfRetries >= LOCK_MAX_TRIES) { | ||
next(sessionStoreStrategy) | ||
@@ -41,3 +39,3 @@ return | ||
let currentSession = retrieveSession() | ||
if (lockEnabled) { | ||
if (isLockEnabled) { | ||
// if someone has lock, retry later | ||
@@ -60,3 +58,3 @@ if (currentSession.lock) { | ||
let processedSession = operations.process(currentSession) | ||
if (lockEnabled) { | ||
if (isLockEnabled) { | ||
// if lock corrupted after process, retry later | ||
@@ -77,3 +75,3 @@ currentSession = retrieveSession() | ||
} | ||
if (lockEnabled) { | ||
if (isLockEnabled) { | ||
// correctly handle lock around expiration would require to handle this case properly at several levels | ||
@@ -99,8 +97,2 @@ // since we don't have evidence of lock issues around expiration, let's just not do the corruption check for it | ||
/** | ||
* Lock strategy allows mitigating issues due to concurrent access to cookie. | ||
* This issue concerns only chromium browsers and enabling this on firefox increases cookie write failures. | ||
*/ | ||
export const isLockEnabled = () => isChromium() | ||
function retryLater(operations: Operations, sessionStore: SessionStoreStrategy, currentNumberOfRetries: number) { | ||
@@ -107,0 +99,0 @@ setTimeout(() => { |
@@ -0,1 +1,2 @@ | ||
import { isChromium } from '../../../tools/utils/browserDetection' | ||
import type { CookieOptions } from '../../../browser/cookie' | ||
@@ -18,2 +19,7 @@ import { getCurrentSite, areCookiesAuthorized, deleteCookie, getCookie, setCookie } from '../../../browser/cookie' | ||
const cookieStore = { | ||
/** | ||
* Lock strategy allows mitigating issues due to concurrent access to cookie. | ||
* This issue concerns only chromium browsers and enabling this on firefox increases cookie write failures. | ||
*/ | ||
isLockEnabled: isChromium(), | ||
persistSession: persistSessionCookie(cookieOptions), | ||
@@ -20,0 +26,0 @@ retrieveSession: retrieveSessionCookie, |
@@ -24,2 +24,3 @@ import { generateUUID } from '../../../tools/utils/stringUtils' | ||
return { | ||
isLockEnabled: false, | ||
persistSession: persistInLocalStorage, | ||
@@ -26,0 +27,0 @@ retrieveSession: retrieveSessionFromLocalStorage, |
@@ -9,2 +9,3 @@ import type { CookieOptions } from '../../../browser/cookie' | ||
export interface SessionStoreStrategy { | ||
isLockEnabled: boolean | ||
persistSession: (session: SessionState) => void | ||
@@ -11,0 +12,0 @@ retrieveSession: () => SessionState |
@@ -46,7 +46,8 @@ /* eslint-disable local-rules/disallow-side-effects */ | ||
export const globalConsole = console | ||
const PREFIX = 'Datadog Browser SDK:' | ||
display.debug = globalConsole.debug.bind(globalConsole) | ||
display.log = globalConsole.log.bind(globalConsole) | ||
display.info = globalConsole.info.bind(globalConsole) | ||
display.warn = globalConsole.warn.bind(globalConsole) | ||
display.error = globalConsole.error.bind(globalConsole) | ||
display.debug = globalConsole.debug.bind(globalConsole, PREFIX) | ||
display.log = globalConsole.log.bind(globalConsole, PREFIX) | ||
display.info = globalConsole.info.bind(globalConsole, PREFIX) | ||
display.warn = globalConsole.warn.bind(globalConsole, PREFIX) | ||
display.error = globalConsole.error.bind(globalConsole, PREFIX) |
@@ -22,2 +22,3 @@ /** | ||
INTERACTION_TO_NEXT_PAINT = 'interaction_to_next_paint', | ||
WEB_VITALS_ATTRIBUTION = 'web_vitals_attribution', | ||
DISABLE_REPLAY_INLINE_CSS = 'disable_replay_inline_css', | ||
@@ -24,0 +25,0 @@ } |
@@ -31,2 +31,3 @@ import type { EndpointBuilder, Configuration } from '../domain/configuration' | ||
flushReason?: FlushReason | ||
encoding?: 'deflate' | ||
} | ||
@@ -67,9 +68,9 @@ | ||
bytesLimit: number, | ||
{ data, bytesCount, flushReason }: Payload | ||
payload: Payload | ||
) { | ||
const canUseBeacon = !!navigator.sendBeacon && bytesCount < bytesLimit | ||
const canUseBeacon = !!navigator.sendBeacon && payload.bytesCount < bytesLimit | ||
if (canUseBeacon) { | ||
try { | ||
const beaconUrl = endpointBuilder.build('beacon', flushReason) | ||
const isQueued = navigator.sendBeacon(beaconUrl, data) | ||
const beaconUrl = endpointBuilder.build('beacon', payload) | ||
const isQueued = navigator.sendBeacon(beaconUrl, payload.data) | ||
@@ -84,4 +85,4 @@ if (isQueued) { | ||
const xhrUrl = endpointBuilder.build('xhr', flushReason) | ||
sendXHR(configuration, xhrUrl, data) | ||
const xhrUrl = endpointBuilder.build('xhr', payload) | ||
sendXHR(configuration, xhrUrl, payload.data) | ||
} | ||
@@ -102,19 +103,19 @@ | ||
bytesLimit: number, | ||
{ data, bytesCount, flushReason, retry }: Payload, | ||
payload: Payload, | ||
onResponse?: (r: HttpResponse) => void | ||
) { | ||
const canUseKeepAlive = isKeepAliveSupported() && bytesCount < bytesLimit | ||
const canUseKeepAlive = isKeepAliveSupported() && payload.bytesCount < bytesLimit | ||
if (canUseKeepAlive) { | ||
const fetchUrl = endpointBuilder.build('fetch', flushReason, retry) | ||
fetch(fetchUrl, { method: 'POST', body: data, keepalive: true, mode: 'cors' }).then( | ||
const fetchUrl = endpointBuilder.build('fetch', payload) | ||
fetch(fetchUrl, { method: 'POST', body: payload.data, keepalive: true, mode: 'cors' }).then( | ||
monitor((response: Response) => onResponse?.({ status: response.status, type: response.type })), | ||
monitor(() => { | ||
const xhrUrl = endpointBuilder.build('xhr', flushReason, retry) | ||
const xhrUrl = endpointBuilder.build('xhr', payload) | ||
// failed to queue the request | ||
sendXHR(configuration, xhrUrl, data, onResponse) | ||
sendXHR(configuration, xhrUrl, payload.data, onResponse) | ||
}) | ||
) | ||
} else { | ||
const xhrUrl = endpointBuilder.build('xhr', flushReason, retry) | ||
sendXHR(configuration, xhrUrl, data, onResponse) | ||
const xhrUrl = endpointBuilder.build('xhr', payload) | ||
sendXHR(configuration, xhrUrl, payload.data, onResponse) | ||
} | ||
@@ -121,0 +122,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
980768
17277