@pratham.raval/browser-core 6.22.3 → 6.22.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/cjs/boot/displayAlreadyInitializedError.d.ts +1 -1
- package/cjs/boot/init.d.ts +1 -1
- package/cjs/browser/cookie.d.ts +10 -0
- package/cjs/browser/cookie.js +13 -0
- package/cjs/browser/cookie.js.map +1 -1
- package/cjs/domain/configuration/configuration.js +4 -4
- package/cjs/domain/configuration/configuration.js.map +1 -1
- package/cjs/domain/configuration/endpointBuilder.js +16 -24
- package/cjs/domain/configuration/endpointBuilder.js.map +1 -1
- package/cjs/domain/configuration/transportConfiguration.js +5 -15
- package/cjs/domain/configuration/transportConfiguration.js.map +1 -1
- package/cjs/domain/intakeSites.d.ts +1 -7
- package/cjs/domain/intakeSites.js +2 -8
- package/cjs/domain/intakeSites.js.map +1 -1
- package/cjs/domain/session/oldCookiesMigration.d.ts +1 -1
- package/cjs/domain/session/oldCookiesMigration.js +1 -1
- package/cjs/domain/session/sessionManager.d.ts +1 -0
- package/cjs/domain/session/sessionManager.js +24 -6
- package/cjs/domain/session/sessionManager.js.map +1 -1
- package/cjs/domain/session/sessionState.js +2 -8
- package/cjs/domain/session/sessionState.js.map +1 -1
- package/cjs/domain/session/sessionStore.d.ts +1 -1
- package/cjs/domain/session/sessionStore.js +5 -1
- package/cjs/domain/session/sessionStore.js.map +1 -1
- package/cjs/domain/session/storeStrategies/sessionInCookie.d.ts +5 -1
- package/cjs/domain/session/storeStrategies/sessionInCookie.js +52 -3
- package/cjs/domain/session/storeStrategies/sessionInCookie.js.map +1 -1
- package/cjs/domain/session/storeStrategies/sessionInLocalStorage.d.ts +2 -0
- package/cjs/domain/session/storeStrategies/sessionInLocalStorage.js +1 -0
- package/cjs/domain/session/storeStrategies/sessionInLocalStorage.js.map +1 -1
- package/cjs/domain/session/storeStrategies/sessionStoreStrategy.d.ts +1 -1
- package/cjs/domain/session/storeStrategies/sessionStoreStrategy.js +1 -1
- package/cjs/domain/synthetics/syntheticsWorkerValues.d.ts +6 -6
- package/cjs/domain/synthetics/syntheticsWorkerValues.js +6 -6
- package/cjs/domain/synthetics/syntheticsWorkerValues.js.map +1 -1
- package/cjs/domain/tags.js +6 -5
- package/cjs/domain/tags.js.map +1 -1
- package/cjs/domain/telemetry/telemetry.js +4 -5
- package/cjs/domain/telemetry/telemetry.js.map +1 -1
- package/cjs/domain/telemetry/telemetryEvent.types.d.ts +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +3 -2
- package/cjs/index.js.map +1 -1
- package/cjs/tools/display.js +1 -1
- package/cjs/tools/display.js.map +1 -1
- package/cjs/tools/experimentalFeatures.d.ts +2 -1
- package/cjs/tools/experimentalFeatures.js +1 -0
- package/cjs/tools/experimentalFeatures.js.map +1 -1
- package/cjs/tools/utils/browserDetection.d.ts +2 -0
- package/cjs/tools/utils/browserDetection.js +20 -0
- package/cjs/tools/utils/browserDetection.js.map +1 -1
- package/cjs/tools/utils/stringUtils.d.ts +15 -0
- package/cjs/tools/utils/stringUtils.js +36 -0
- package/cjs/tools/utils/stringUtils.js.map +1 -1
- package/cjs/transport/httpRequest.d.ts +1 -0
- package/cjs/transport/httpRequest.js +26 -4
- package/cjs/transport/httpRequest.js.map +1 -1
- package/cjs/transport/index.d.ts +1 -1
- package/cjs/transport/index.js +2 -1
- package/cjs/transport/index.js.map +1 -1
- package/esm/boot/displayAlreadyInitializedError.d.ts +1 -1
- package/esm/boot/init.d.ts +1 -1
- package/esm/browser/cookie.d.ts +10 -0
- package/esm/browser/cookie.js +13 -1
- package/esm/browser/cookie.js.map +1 -1
- package/esm/domain/configuration/configuration.js +5 -5
- package/esm/domain/configuration/configuration.js.map +1 -1
- package/esm/domain/configuration/endpointBuilder.js +16 -24
- package/esm/domain/configuration/endpointBuilder.js.map +1 -1
- package/esm/domain/configuration/transportConfiguration.js +6 -16
- package/esm/domain/configuration/transportConfiguration.js.map +1 -1
- package/esm/domain/intakeSites.d.ts +1 -7
- package/esm/domain/intakeSites.js +1 -7
- package/esm/domain/intakeSites.js.map +1 -1
- package/esm/domain/session/oldCookiesMigration.d.ts +1 -1
- package/esm/domain/session/oldCookiesMigration.js +1 -1
- package/esm/domain/session/sessionManager.d.ts +1 -0
- package/esm/domain/session/sessionManager.js +25 -7
- package/esm/domain/session/sessionManager.js.map +1 -1
- package/esm/domain/session/sessionState.js +2 -8
- package/esm/domain/session/sessionState.js.map +1 -1
- package/esm/domain/session/sessionStore.d.ts +1 -1
- package/esm/domain/session/sessionStore.js +5 -1
- package/esm/domain/session/sessionStore.js.map +1 -1
- package/esm/domain/session/storeStrategies/sessionInCookie.d.ts +5 -1
- package/esm/domain/session/storeStrategies/sessionInCookie.js +53 -4
- package/esm/domain/session/storeStrategies/sessionInCookie.js.map +1 -1
- package/esm/domain/session/storeStrategies/sessionInLocalStorage.d.ts +2 -0
- package/esm/domain/session/storeStrategies/sessionInLocalStorage.js +1 -1
- package/esm/domain/session/storeStrategies/sessionInLocalStorage.js.map +1 -1
- package/esm/domain/session/storeStrategies/sessionStoreStrategy.d.ts +1 -1
- package/esm/domain/session/storeStrategies/sessionStoreStrategy.js +1 -1
- package/esm/domain/synthetics/syntheticsWorkerValues.d.ts +6 -6
- package/esm/domain/synthetics/syntheticsWorkerValues.js +6 -6
- package/esm/domain/synthetics/syntheticsWorkerValues.js.map +1 -1
- package/esm/domain/tags.js +6 -5
- package/esm/domain/tags.js.map +1 -1
- package/esm/domain/telemetry/telemetry.js +4 -5
- package/esm/domain/telemetry/telemetry.js.map +1 -1
- package/esm/domain/telemetry/telemetryEvent.types.d.ts +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/tools/display.js +1 -1
- package/esm/tools/display.js.map +1 -1
- package/esm/tools/experimentalFeatures.d.ts +2 -1
- package/esm/tools/experimentalFeatures.js +1 -0
- package/esm/tools/experimentalFeatures.js.map +1 -1
- package/esm/tools/utils/browserDetection.d.ts +2 -0
- package/esm/tools/utils/browserDetection.js +18 -0
- package/esm/tools/utils/browserDetection.js.map +1 -1
- package/esm/tools/utils/stringUtils.d.ts +15 -0
- package/esm/tools/utils/stringUtils.js +35 -0
- package/esm/tools/utils/stringUtils.js.map +1 -1
- package/esm/transport/httpRequest.d.ts +1 -0
- package/esm/transport/httpRequest.js +25 -4
- package/esm/transport/httpRequest.js.map +1 -1
- package/esm/transport/index.d.ts +1 -1
- package/esm/transport/index.js +1 -1
- package/esm/transport/index.js.map +1 -1
- package/package.json +4 -6
- package/src/boot/displayAlreadyInitializedError.ts +1 -1
- package/src/boot/init.ts +1 -1
- package/src/browser/cookie.ts +19 -1
- package/src/domain/configuration/configuration.ts +4 -4
- package/src/domain/configuration/endpointBuilder.ts +17 -27
- package/src/domain/configuration/transportConfiguration.ts +6 -18
- package/src/domain/intakeSites.ts +2 -17
- package/src/domain/session/oldCookiesMigration.ts +1 -1
- package/src/domain/session/sessionManager.ts +28 -7
- package/src/domain/session/sessionState.ts +2 -7
- package/src/domain/session/sessionStore.ts +6 -2
- package/src/domain/session/storeStrategies/sessionInCookie.ts +66 -4
- package/src/domain/session/storeStrategies/sessionInLocalStorage.ts +1 -1
- package/src/domain/session/storeStrategies/sessionStoreStrategy.ts +1 -1
- package/src/domain/synthetics/syntheticsWorkerValues.ts +9 -9
- package/src/domain/tags.ts +6 -6
- package/src/domain/telemetry/telemetry.ts +5 -5
- package/src/domain/telemetry/telemetryEvent.types.ts +1 -1
- package/src/index.ts +1 -0
- package/src/tools/display.ts +1 -1
- package/src/tools/experimentalFeatures.ts +1 -0
- package/src/tools/utils/browserDetection.ts +26 -0
- package/src/tools/utils/stringUtils.ts +34 -0
- package/src/transport/httpRequest.ts +31 -5
- package/src/transport/index.ts +1 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { getInitCookie } from '../../browser/cookie'
|
|
2
2
|
import { globalObject, isWorkerEnvironment } from '../../tools/globalObject'
|
|
3
3
|
|
|
4
|
-
export const SYNTHETICS_TEST_ID_COOKIE_NAME = '
|
|
5
|
-
export const SYNTHETICS_RESULT_ID_COOKIE_NAME = '
|
|
6
|
-
export const SYNTHETICS_INJECTS_RUM_COOKIE_NAME = '
|
|
4
|
+
export const SYNTHETICS_TEST_ID_COOKIE_NAME = 'motadata-synthetics-public-id'
|
|
5
|
+
export const SYNTHETICS_RESULT_ID_COOKIE_NAME = 'motadata-synthetics-result-id'
|
|
6
|
+
export const SYNTHETICS_INJECTS_RUM_COOKIE_NAME = 'motadata-synthetics-injects-rum'
|
|
7
7
|
|
|
8
8
|
export interface BrowserWindow extends Window {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
_MOTADATA_SYNTHETICS_PUBLIC_ID?: unknown
|
|
10
|
+
_MOTADATA_SYNTHETICS_RESULT_ID?: unknown
|
|
11
|
+
_MOTADATA_SYNTHETICS_INJECTS_RUM?: unknown
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function willSyntheticsInjectRum(): boolean {
|
|
@@ -18,18 +18,18 @@ export function willSyntheticsInjectRum(): boolean {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
return Boolean(
|
|
21
|
-
(globalObject as BrowserWindow).
|
|
21
|
+
(globalObject as BrowserWindow)._MOTADATA_SYNTHETICS_INJECTS_RUM || getInitCookie(SYNTHETICS_INJECTS_RUM_COOKIE_NAME)
|
|
22
22
|
)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export function getSyntheticsTestId(): string | undefined {
|
|
26
|
-
const value = (window as BrowserWindow).
|
|
26
|
+
const value = (window as BrowserWindow)._MOTADATA_SYNTHETICS_PUBLIC_ID || getInitCookie(SYNTHETICS_TEST_ID_COOKIE_NAME)
|
|
27
27
|
return typeof value === 'string' ? value : undefined
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export function getSyntheticsResultId(): string | undefined {
|
|
31
31
|
const value =
|
|
32
|
-
(window as BrowserWindow).
|
|
32
|
+
(window as BrowserWindow)._MOTADATA_SYNTHETICS_RESULT_ID || getInitCookie(SYNTHETICS_RESULT_ID_COOKIE_NAME)
|
|
33
33
|
return typeof value === 'string' ? value : undefined
|
|
34
34
|
}
|
|
35
35
|
|
package/src/domain/tags.ts
CHANGED
|
@@ -36,15 +36,15 @@ export function buildTag(key: string, rawValue?: string) {
|
|
|
36
36
|
// warning.
|
|
37
37
|
const tag = rawValue ? `${key}:${rawValue}` : key
|
|
38
38
|
|
|
39
|
-
if (tag.length > TAG_SIZE_LIMIT || hasForbiddenCharacters(tag)) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
39
|
+
// if (tag.length > TAG_SIZE_LIMIT || hasForbiddenCharacters(tag)) {
|
|
40
|
+
// display.warn(
|
|
41
|
+
// `Tag ${tag} doesn't meet tag requirements and will be sanitized. ${MORE_DETAILS} ${DOCS_ORIGIN}/getting_started/tagging/#defining-tags`
|
|
42
|
+
// )
|
|
43
|
+
// }
|
|
44
44
|
|
|
45
45
|
// Let the backend do most of the sanitization, but still make sure multiple tags can't be crafted
|
|
46
46
|
// by forging a value containing commas.
|
|
47
|
-
return
|
|
47
|
+
return tag
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export function sanitizeTag(tag: string) {
|
|
@@ -5,7 +5,7 @@ import { toStackTraceString } from '../../tools/stackTrace/handlingStack'
|
|
|
5
5
|
import { getExperimentalFeatures } from '../../tools/experimentalFeatures'
|
|
6
6
|
import type { Configuration } from '../configuration'
|
|
7
7
|
import { buildTags } from '../tags'
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
import { BufferedObservable, Observable } from '../../tools/observable'
|
|
10
10
|
import { clocksNow } from '../../tools/utils/timeUtils'
|
|
11
11
|
import { displayIfDebugEnabled, startMonitorErrorCollection } from '../../tools/monitor'
|
|
@@ -74,7 +74,7 @@ export const enum TelemetryMetrics {
|
|
|
74
74
|
|
|
75
75
|
const METRIC_SAMPLE_RATE = 1
|
|
76
76
|
|
|
77
|
-
const TELEMETRY_EXCLUDED_SITES: string[] = [
|
|
77
|
+
const TELEMETRY_EXCLUDED_SITES: string[] = []
|
|
78
78
|
|
|
79
79
|
let telemetryObservable: BufferedObservable<{ rawEvent: RawTelemetryEvent; metricName?: string }> | undefined
|
|
80
80
|
|
|
@@ -188,7 +188,7 @@ export function startTelemetryCollection(
|
|
|
188
188
|
service: telemetryService,
|
|
189
189
|
version: __BUILD_ENV__SDK_VERSION__,
|
|
190
190
|
source: 'browser' as const,
|
|
191
|
-
|
|
191
|
+
_md: {
|
|
192
192
|
format_version: 2 as const,
|
|
193
193
|
},
|
|
194
194
|
telemetry: combine(rawEvent, {
|
|
@@ -196,7 +196,7 @@ export function startTelemetryCollection(
|
|
|
196
196
|
connectivity: getConnectivity(),
|
|
197
197
|
sdk_setup: __BUILD_ENV__SDK_SETUP__,
|
|
198
198
|
}) as TelemetryEvent['telemetry'],
|
|
199
|
-
|
|
199
|
+
mdtags: buildTags(configuration).join(','),
|
|
200
200
|
experimental_features: Array.from(getExperimentalFeatures()),
|
|
201
201
|
}
|
|
202
202
|
|
|
@@ -262,7 +262,7 @@ export function resetTelemetry() {
|
|
|
262
262
|
* but keep replicating staging events for reliability
|
|
263
263
|
*/
|
|
264
264
|
function isTelemetryReplicationAllowed(configuration: Configuration) {
|
|
265
|
-
return
|
|
265
|
+
return false // No telemetry replication for custom sites
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
export function addTelemetryDebug(message: string, context?: Context) {
|
package/src/index.ts
CHANGED
package/src/tools/display.ts
CHANGED
|
@@ -41,7 +41,7 @@ Object.keys(ConsoleApiName).forEach((name) => {
|
|
|
41
41
|
originalConsoleMethods[name as ConsoleApiName] = globalConsole[name as ConsoleApiName]
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
const PREFIX = '
|
|
44
|
+
const PREFIX = 'Motadata Browser SDK:'
|
|
45
45
|
|
|
46
46
|
export const display: Display = {
|
|
47
47
|
debug: originalConsoleMethods.debug.bind(globalConsole, PREFIX),
|
|
@@ -18,6 +18,7 @@ export enum ExperimentalFeature {
|
|
|
18
18
|
USE_TREE_WALKER_FOR_ACTION_NAME = 'use_tree_walker_for_action_name',
|
|
19
19
|
FEATURE_OPERATION_VITAL = 'feature_operation_vital',
|
|
20
20
|
SHORT_SESSION_INVESTIGATION = 'short_session_investigation',
|
|
21
|
+
ENCODE_COOKIE_OPTIONS = 'encode_cookie_options',
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
const enabledExperimentalFeatures: Set<ExperimentalFeature> = new Set()
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies, local-rules/disallow-side-effects, local-rules/enforce-prod-deps-imports
|
|
2
|
+
import { UAParser } from 'ua-parser-js';
|
|
3
|
+
|
|
1
4
|
// Exported only for tests
|
|
2
5
|
export const enum Browser {
|
|
3
6
|
CHROMIUM,
|
|
@@ -37,3 +40,26 @@ export function detectBrowser(browserWindow: Window = window) {
|
|
|
37
40
|
|
|
38
41
|
return Browser.OTHER
|
|
39
42
|
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get detailed browser name for X-Browser-Name header
|
|
46
|
+
* Uses ua-parser-js for accurate browser detection
|
|
47
|
+
*/
|
|
48
|
+
let detailedBrowserNameCache: string | undefined
|
|
49
|
+
|
|
50
|
+
export function getDetailedBrowserName(browserWindow: Window = window): string {
|
|
51
|
+
return (
|
|
52
|
+
detailedBrowserNameCache ??
|
|
53
|
+
(detailedBrowserNameCache = detectDetailedBrowserName(browserWindow))
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function detectDetailedBrowserName(browserWindow: Window = window): string {
|
|
58
|
+
const ua = browserWindow.navigator.userAgent
|
|
59
|
+
const parser = new UAParser(ua)
|
|
60
|
+
const result = parser.getResult()
|
|
61
|
+
|
|
62
|
+
// Return the browser name from ua-parser-js
|
|
63
|
+
// If browser name is undefined or empty, return 'Unknown Browser'
|
|
64
|
+
return result.browser.name || 'Unknown Browser'
|
|
65
|
+
}
|
|
@@ -11,6 +11,10 @@ export function generateUUID(placeholder?: string): string {
|
|
|
11
11
|
|
|
12
12
|
const COMMA_SEPARATED_KEY_VALUE = /([\w-]+)\s*=\s*([^;]+)/g
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Returns the value of the key with the given name
|
|
16
|
+
* If there are multiple values with the same key, returns the first one
|
|
17
|
+
*/
|
|
14
18
|
export function findCommaSeparatedValue(rawString: string, name: string): string | undefined {
|
|
15
19
|
COMMA_SEPARATED_KEY_VALUE.lastIndex = 0
|
|
16
20
|
while (true) {
|
|
@@ -25,6 +29,36 @@ export function findCommaSeparatedValue(rawString: string, name: string): string
|
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Returns a map of all the values with the given key
|
|
34
|
+
* If there are multiple values with the same key, returns all the values
|
|
35
|
+
*/
|
|
36
|
+
export function findAllCommaSeparatedValues(rawString: string): Map<string, string[]> {
|
|
37
|
+
const result = new Map<string, string[]>()
|
|
38
|
+
COMMA_SEPARATED_KEY_VALUE.lastIndex = 0
|
|
39
|
+
while (true) {
|
|
40
|
+
const match = COMMA_SEPARATED_KEY_VALUE.exec(rawString)
|
|
41
|
+
if (match) {
|
|
42
|
+
const key = match[1]
|
|
43
|
+
const value = match[2]
|
|
44
|
+
if (result.has(key)) {
|
|
45
|
+
result.get(key)!.push(value)
|
|
46
|
+
} else {
|
|
47
|
+
result.set(key, [value])
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
break
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return result
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns a map of the values with the given key
|
|
58
|
+
* ⚠️ If there are multiple values with the same key, returns the LAST one
|
|
59
|
+
*
|
|
60
|
+
* @deprecated use `findAllCommaSeparatedValues()` instead
|
|
61
|
+
*/
|
|
28
62
|
export function findCommaSeparatedValues(rawString: string): Map<string, string> {
|
|
29
63
|
const result = new Map<string, string>()
|
|
30
64
|
COMMA_SEPARATED_KEY_VALUE.lastIndex = 0
|
|
@@ -3,6 +3,7 @@ import type { Context } from '../tools/serialisation/context'
|
|
|
3
3
|
import { monitor, monitorError } from '../tools/monitor'
|
|
4
4
|
import type { RawError } from '../domain/error/error.types'
|
|
5
5
|
import { Observable } from '../tools/observable'
|
|
6
|
+
import { getDetailedBrowserName } from '../tools/utils/browserDetection'
|
|
6
7
|
import { newRetryState, sendWithRetryStrategy } from './sendWithRetryStrategy'
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -62,6 +63,12 @@ export interface RetryInfo {
|
|
|
62
63
|
lastFailureStatus: number
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
let currentSite: string | undefined
|
|
67
|
+
|
|
68
|
+
export function setCurrentSite(site: string | undefined) {
|
|
69
|
+
currentSite = site
|
|
70
|
+
}
|
|
71
|
+
|
|
65
72
|
export function createHttpRequest<Body extends Payload = Payload>(
|
|
66
73
|
endpointBuilders: EndpointBuilder[],
|
|
67
74
|
bytesLimit: number,
|
|
@@ -133,10 +140,16 @@ export function fetchKeepAliveStrategy(
|
|
|
133
140
|
|
|
134
141
|
if (canUseKeepAlive) {
|
|
135
142
|
const fetchUrl = endpointBuilder.build('fetch-keepalive', payload)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
.
|
|
143
|
+
const headers = buildRequestHeaders(fetchUrl)
|
|
144
|
+
|
|
145
|
+
fetch(fetchUrl, { method: 'POST', body: payload.data, keepalive: true, mode: 'cors', headers })
|
|
146
|
+
.then(monitor((response: Response) => {
|
|
147
|
+
onResponse?.({ status: response.status, type: response.type })
|
|
148
|
+
}))
|
|
149
|
+
.catch(monitor((error) => {
|
|
150
|
+
fetchStrategy(endpointBuilder, payload, onResponse)
|
|
151
|
+
onResponse?.({ status: 0 })
|
|
152
|
+
}))
|
|
140
153
|
} else {
|
|
141
154
|
fetchStrategy(endpointBuilder, payload, onResponse)
|
|
142
155
|
}
|
|
@@ -148,8 +161,9 @@ export function fetchStrategy(
|
|
|
148
161
|
onResponse?: (r: HttpResponse) => void
|
|
149
162
|
) {
|
|
150
163
|
const fetchUrl = endpointBuilder.build('fetch', payload)
|
|
164
|
+
const headers = buildRequestHeaders(fetchUrl)
|
|
151
165
|
|
|
152
|
-
fetch(fetchUrl, { method: 'POST', body: payload.data, mode: 'cors' })
|
|
166
|
+
fetch(fetchUrl, { method: 'POST', body: payload.data, mode: 'cors', headers })
|
|
153
167
|
.then(monitor((response: Response) => onResponse?.({ status: response.status, type: response.type })))
|
|
154
168
|
.catch(monitor(() => onResponse?.({ status: 0 })))
|
|
155
169
|
}
|
|
@@ -162,3 +176,15 @@ function isKeepAliveSupported() {
|
|
|
162
176
|
return false
|
|
163
177
|
}
|
|
164
178
|
}
|
|
179
|
+
|
|
180
|
+
function buildRequestHeaders(url?: string): HeadersInit {
|
|
181
|
+
const headers: HeadersInit = {}
|
|
182
|
+
|
|
183
|
+
// dynamically match your RUM SDK endpoint host
|
|
184
|
+
// "site" comes from init() call, so this automatically adjusts
|
|
185
|
+
if (currentSite && url ) {
|
|
186
|
+
headers['X-Browser-Name'] = getDetailedBrowserName()
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return headers
|
|
190
|
+
}
|
package/src/transport/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { BandwidthStats, HttpRequest, HttpRequestEvent, Payload, RetryInfo } from './httpRequest'
|
|
2
|
-
export { createHttpRequest } from './httpRequest'
|
|
2
|
+
export { createHttpRequest, setCurrentSite } from './httpRequest'
|
|
3
3
|
export type { BrowserWindowWithEventBridge, DatadogEventBridge } from './eventBridge'
|
|
4
4
|
export { canUseEventBridge, bridgeSupports, getEventBridge, BridgeCapability } from './eventBridge'
|
|
5
5
|
export { createBatch } from './batch'
|