@amplitude/session-replay-browser 1.26.2 → 1.27.0
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/lib/cjs/config/local-config.d.ts +3 -0
- package/lib/cjs/config/local-config.d.ts.map +1 -1
- package/lib/cjs/config/local-config.js +4 -1
- package/lib/cjs/config/local-config.js.map +1 -1
- package/lib/cjs/config/types.d.ts +23 -0
- package/lib/cjs/config/types.d.ts.map +1 -1
- package/lib/cjs/config/types.js.map +1 -1
- package/lib/cjs/constants.d.ts +1 -0
- package/lib/cjs/constants.d.ts.map +1 -1
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/helpers.d.ts +3 -0
- package/lib/cjs/helpers.d.ts.map +1 -1
- package/lib/cjs/plugins/index.d.ts +2 -0
- package/lib/cjs/plugins/index.d.ts.map +1 -0
- package/lib/cjs/plugins/index.js +5 -0
- package/lib/cjs/plugins/index.js.map +1 -0
- package/lib/cjs/plugins/url-tracking-plugin.d.ts +56 -0
- package/lib/cjs/plugins/url-tracking-plugin.d.ts.map +1 -0
- package/lib/cjs/plugins/url-tracking-plugin.js +187 -0
- package/lib/cjs/plugins/url-tracking-plugin.js.map +1 -0
- package/lib/cjs/session-replay.d.ts +1 -1
- package/lib/cjs/session-replay.d.ts.map +1 -1
- package/lib/cjs/session-replay.js +23 -9
- package/lib/cjs/session-replay.js.map +1 -1
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/version.js.map +1 -1
- package/lib/esm/config/local-config.d.ts +3 -0
- package/lib/esm/config/local-config.d.ts.map +1 -1
- package/lib/esm/config/local-config.js +5 -2
- package/lib/esm/config/local-config.js.map +1 -1
- package/lib/esm/config/types.d.ts +23 -0
- package/lib/esm/config/types.d.ts.map +1 -1
- package/lib/esm/config/types.js.map +1 -1
- package/lib/esm/constants.d.ts +1 -0
- package/lib/esm/constants.d.ts.map +1 -1
- package/lib/esm/constants.js +1 -0
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/helpers.d.ts +3 -0
- package/lib/esm/helpers.d.ts.map +1 -1
- package/lib/esm/plugins/index.d.ts +2 -0
- package/lib/esm/plugins/index.d.ts.map +1 -0
- package/lib/esm/plugins/index.js +2 -0
- package/lib/esm/plugins/index.js.map +1 -0
- package/lib/esm/plugins/url-tracking-plugin.d.ts +56 -0
- package/lib/esm/plugins/url-tracking-plugin.d.ts.map +1 -0
- package/lib/esm/plugins/url-tracking-plugin.js +183 -0
- package/lib/esm/plugins/url-tracking-plugin.js.map +1 -0
- package/lib/esm/session-replay.d.ts +1 -1
- package/lib/esm/session-replay.d.ts.map +1 -1
- package/lib/esm/session-replay.js +23 -9
- package/lib/esm/session-replay.js.map +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/version.js.map +1 -1
- package/lib/scripts/session-replay-browser-min.js +1 -1
- package/lib/scripts/session-replay-browser-min.js.gz +0 -0
- package/lib/scripts/session-replay-browser-min.js.map +1 -1
- package/lib/scripts/session-replay-min.js +1 -1
- package/lib/scripts/session-replay-min.js.gz +0 -0
- package/lib/scripts/session-replay-min.js.map +1 -1
- package/package.json +3 -3
|
@@ -27,6 +27,9 @@ export declare class SessionReplayLocalConfig extends Config implements ISession
|
|
|
27
27
|
script?: boolean;
|
|
28
28
|
comment?: boolean;
|
|
29
29
|
};
|
|
30
|
+
enableUrlChangePolling?: boolean;
|
|
31
|
+
urlChangePollingInterval?: number;
|
|
32
|
+
captureDocumentTitle?: boolean;
|
|
30
33
|
constructor(apiKey: string, options: SessionReplayOptions);
|
|
31
34
|
}
|
|
32
35
|
//# sourceMappingURL=local-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-config.d.ts","sourceRoot":"","sources":["../../../src/config/local-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,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M,EAAE,OAAO,EAAE,oBAAoB;CAgD1D"}
|
|
@@ -17,7 +17,7 @@ var SessionReplayLocalConfig = /** @class */ (function (_super) {
|
|
|
17
17
|
tslib_1.__extends(SessionReplayLocalConfig, _super);
|
|
18
18
|
function SessionReplayLocalConfig(apiKey, options) {
|
|
19
19
|
var _this = this;
|
|
20
|
-
var _a, _b;
|
|
20
|
+
var _a, _b, _c, _d, _e;
|
|
21
21
|
var defaultConfig = (0, exports.getDefaultConfig)();
|
|
22
22
|
_this = _super.call(this, tslib_1.__assign(tslib_1.__assign({ transportProvider: defaultConfig.transportProvider, loggerProvider: new logger_1.SafeLoggerProvider(options.loggerProvider || defaultConfig.loggerProvider) }, options), { apiKey: apiKey })) || this;
|
|
23
23
|
_this.flushMaxRetries =
|
|
@@ -34,6 +34,9 @@ var SessionReplayLocalConfig = /** @class */ (function (_super) {
|
|
|
34
34
|
_this.performanceConfig = options.performanceConfig || constants_1.DEFAULT_PERFORMANCE_CONFIG;
|
|
35
35
|
_this.storeType = (_a = options.storeType) !== null && _a !== void 0 ? _a : 'idb';
|
|
36
36
|
_this.applyBackgroundColorToBlockedElements = (_b = options.applyBackgroundColorToBlockedElements) !== null && _b !== void 0 ? _b : false;
|
|
37
|
+
_this.enableUrlChangePolling = (_c = options.enableUrlChangePolling) !== null && _c !== void 0 ? _c : false;
|
|
38
|
+
_this.urlChangePollingInterval = (_d = options.urlChangePollingInterval) !== null && _d !== void 0 ? _d : constants_1.DEFAULT_URL_CHANGE_POLLING_INTERVAL;
|
|
39
|
+
_this.captureDocumentTitle = (_e = options.captureDocumentTitle) !== null && _e !== void 0 ? _e : false;
|
|
37
40
|
if (options.privacyConfig) {
|
|
38
41
|
_this.privacyConfig = options.privacyConfig;
|
|
39
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-config.js","sourceRoot":"","sources":["../../../src/config/local-config.ts"],"names":[],"mappings":";;;;AAAA,4DAAqF;AACrF,
|
|
1
|
+
{"version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chTransport, LogLevel } from '@amplitude/analytics-core';\nimport {\n DEFAULT_PERFORMANCE_CONFIG,\n DEFAULT_SAMPLE_RATE,\n DEFAULT_SERVER_ZONE,\n DEFAULT_URL_CHANGE_POLLING_INTERVAL,\n} from '../constants';\nimport { SessionReplayOptions, StoreType } from '../typings/session-replay';\nimport {\n SessionReplayLocalConfig as ISessionReplayLocalConfig,\n InteractionConfig,\n PrivacyConfig,\n SessionReplayPerformanceConfig,\n SessionReplayVersion,\n} from './types';\nimport { SafeLoggerProvider } from '../logger';\nimport { validateUGCFilterRules } from '../helpers';\n\nexport const getDefaultConfig = () => ({\n flushMaxRetries: 2,\n logLevel: LogLevel.Warn,\n loggerProvider: new Logger(),\n transportProvider: new FetchTransport(),\n});\n\nexport class SessionReplayLocalConfig extends Config implements ISessionReplayLocalConfig {\n apiKey: string;\n sampleRate: number;\n privacyConfig?: PrivacyConfig;\n interactionConfig?: InteractionConfig;\n debugMode?: boolean;\n configServerUrl?: string;\n trackServerUrl?: string;\n shouldInlineStylesheet?: boolean;\n version?: SessionReplayVersion;\n storeType: StoreType;\n performanceConfig?: SessionReplayPerformanceConfig;\n experimental?: { useWebWorker: boolean };\n applyBackgroundColorToBlockedElements?: boolean;\n omitElementTags?: {\n script?: boolean;\n comment?: boolean;\n };\n enableUrlChangePolling?: boolean;\n urlChangePollingInterval?: number;\n captureDocumentTitle?: boolean;\n\n constructor(apiKey: string, options: SessionReplayOptions) {\n const defaultConfig = getDefaultConfig();\n super({\n transportProvider: defaultConfig.transportProvider,\n loggerProvider: new SafeLoggerProvider(options.loggerProvider || defaultConfig.loggerProvider),\n ...options,\n apiKey,\n });\n this.flushMaxRetries =\n options.flushMaxRetries !== undefined && options.flushMaxRetries <= defaultConfig.flushMaxRetries\n ? options.flushMaxRetries\n : defaultConfig.flushMaxRetries;\n\n this.apiKey = apiKey;\n this.sampleRate = options.sampleRate || DEFAULT_SAMPLE_RATE;\n this.serverZone = options.serverZone || DEFAULT_SERVER_ZONE;\n this.configServerUrl = options.configServerUrl;\n this.trackServerUrl = options.trackServerUrl;\n this.shouldInlineStylesheet = options.shouldInlineStylesheet;\n this.version = options.version;\n this.performanceConfig = options.performanceConfig || DEFAULT_PERFORMANCE_CONFIG;\n this.storeType = options.storeType ?? 'idb';\n this.applyBackgroundColorToBlockedElements = options.applyBackgroundColorToBlockedElements ?? false;\n this.enableUrlChangePolling = options.enableUrlChangePolling ?? false;\n this.urlChangePollingInterval = options.urlChangePollingInterval ?? DEFAULT_URL_CHANGE_POLLING_INTERVAL;\n this.captureDocumentTitle = options.captureDocumentTitle ?? false;\n\n if (options.privacyConfig) {\n this.privacyConfig = options.privacyConfig;\n }\n if (options.interactionConfig) {\n this.interactionConfig = options.interactionConfig;\n\n // validate ugcFilterRules, throw error if invalid - throw error at the beginning of the config\n if (this.interactionConfig.ugcFilterRules) {\n validateUGCFilterRules(this.interactionConfig.ugcFilterRules);\n }\n }\n if (options.debugMode) {\n this.debugMode = options.debugMode;\n }\n if (options.experimental) {\n this.experimental = options.experimental;\n }\n if (options.omitElementTags) {\n this.omitElementTags = options.omitElementTags;\n }\n }\n}\n"]}
|
|
@@ -144,6 +144,29 @@ export interface SessionReplayLocalConfig extends IConfig {
|
|
|
144
144
|
* This helps visualize which elements are blocked from being captured.
|
|
145
145
|
*/
|
|
146
146
|
applyBackgroundColorToBlockedElements?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Enables URL change polling as a fallback for SPA route tracking.
|
|
149
|
+
* When enabled, the SDK will periodically check for URL changes every second
|
|
150
|
+
* in addition to patching the History API. This is useful for edge cases where
|
|
151
|
+
* route changes might bypass the standard History API methods.
|
|
152
|
+
*
|
|
153
|
+
* @defaultValue false
|
|
154
|
+
*/
|
|
155
|
+
enableUrlChangePolling?: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Specifies the interval in milliseconds for URL change polling when enableUrlChangePolling is true.
|
|
158
|
+
* The SDK will check for URL changes at this interval as a fallback for SPA route tracking.
|
|
159
|
+
*
|
|
160
|
+
* @defaultValue 1000
|
|
161
|
+
*/
|
|
162
|
+
urlChangePollingInterval?: number;
|
|
163
|
+
/**
|
|
164
|
+
* Whether to capture document title in URL change events.
|
|
165
|
+
* When disabled, the title field will be empty in URL change events.
|
|
166
|
+
*
|
|
167
|
+
* @defaultValue false
|
|
168
|
+
*/
|
|
169
|
+
captureDocumentTitle?: boolean;
|
|
147
170
|
interactionConfig?: InteractionConfig;
|
|
148
171
|
}
|
|
149
172
|
export interface SessionReplayJoinedConfig extends SessionReplayLocalConfig {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAEvE,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE;QACP,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,EAAE,eAAe,EAAE,CAAC;KAC3B,CAAC;IACF,OAAO,CAAC,EAAE;QACR,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;CACH;AAED,MAAM,MAAM,yBAAyB,GAAG;IACtC,kBAAkB,CAAC,EAAE,cAAc,CAAC;IACpC,iBAAiB,CAAC,EAAE,aAAa,CAAC;IAClC,qBAAqB,CAAC,EAAE,iBAAiB,CAAC;IAC1C,iBAAiB,CAAC,EAAE,aAAa,CAAC;CACnC,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 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/config/types.ts"],"names":[],"mappings":";;;AA8Ca,QAAA,kBAAkB,GAAG,QAAQ,CAAC","sourcesContent":["import { IConfig, LogLevel, ILogger } from '@amplitude/analytics-core';\nimport { StoreType, ConsoleLogLevel } from '../typings/session-replay';\n\nexport interface SamplingConfig {\n sample_rate: number;\n capture_enabled: boolean;\n}\n\nexport interface InteractionConfig {\n trackEveryNms?: number;\n enabled: boolean; // defaults to false\n batch: boolean; // defaults to false\n /**\n * UGC filter rules.\n */\n ugcFilterRules?: UGCFilterRule[];\n}\n\nexport interface LoggingConfig {\n console: {\n enabled: boolean;\n levels: ConsoleLogLevel[];\n };\n network?: {\n enabled: boolean;\n };\n}\n\nexport type SessionReplayRemoteConfig = {\n sr_sampling_config?: SamplingConfig;\n sr_privacy_config?: PrivacyConfig;\n sr_interaction_config?: InteractionConfig;\n sr_logging_config?: LoggingConfig;\n};\n\nexport interface SessionReplayRemoteConfigAPIResponse {\n configs: {\n sessionReplay: SessionReplayRemoteConfig;\n };\n}\n\nexport type MaskLevel =\n | 'light' // only mask a subset of inputs that's deemed sensitive - password, credit card, telephone #, email. These are information we never want to capture.\n | 'medium' // mask all inputs\n | 'conservative'; // mask all inputs and all texts\n\nexport const DEFAULT_MASK_LEVEL = 'medium';\n\n// err on the side of excluding more\nexport type PrivacyConfig = {\n blockSelector?: string | string[]; // exclude in the UI\n defaultMaskLevel?: MaskLevel;\n maskSelector?: string[];\n unmaskSelector?: string[];\n};\n\n/**\n * UGC filter rule.\n */\nexport type UGCFilterRule = {\n /**\n * The selector of the UGC element.\n */\n selector: string;\n /**\n * The replacement text for the UGC element.\n */\n replacement: string;\n};\n\nexport interface SessionReplayLocalConfig extends IConfig {\n apiKey: string;\n loggerProvider: ILogger;\n /**\n * LogLevel.None or LogLevel.Error or LogLevel.Warn or LogLevel.Verbose or LogLevel.Debug.\n * Sets the log level.\n *\n * @defaultValue LogLevel.Warn\n */\n logLevel: LogLevel;\n /**\n * The maximum number of retries allowed for sending replay events.\n * Once this limit is reached, failed events will no longer be sent.\n *\n * @defaultValue 2\n */\n flushMaxRetries: number;\n /**\n * Use this option to control how many sessions to select for replay collection.\n * The number should be a decimal between 0 and 1, for example 0.4, representing\n * the fraction of sessions to have randomly selected for replay collection.\n * Over a large number of sessions, 0.4 would select 40% of those sessions.\n * Sample rates as small as six decimal places (0.000001) are supported.\n *\n * @defaultValue 0\n */\n sampleRate: number;\n privacyConfig?: PrivacyConfig;\n /**\n * Adds additional debug event property to help debug instrumentation issues\n * (such as mismatching apps). Only recommended for debugging initial setup,\n * and not recommended for production.\n */\n debugMode?: boolean;\n /**\n * Specifies the endpoint URL to fetch remote configuration.\n * If provided, it overrides the default server zone configuration.\n */\n configServerUrl?: string;\n /**\n * Specifies the endpoint URL for sending session replay data.\n * If provided, it overrides the default server zone configuration.\n */\n trackServerUrl?: string;\n /**\n * If stylesheets are inlined, the contents of the stylesheet will be stored.\n * During replay, the stored stylesheet will be used instead of attempting to fetch it remotely.\n * This prevents replays from appearing broken due to missing stylesheets.\n * Note: Inlining stylesheets may not work in all cases.\n */\n shouldInlineStylesheet?: boolean;\n version?: SessionReplayVersion;\n /**\n * Performance configuration config. If enabled, we will defer compression\n * to be done during the browser's idle periods.\n */\n performanceConfig?: SessionReplayPerformanceConfig;\n /**\n * Specifies how replay events should be stored. `idb` uses IndexedDB to persist replay events\n * when all events cannot be sent during capture. `memory` stores replay events only in memory,\n * meaning events are lost when the page is closed. If IndexedDB is unavailable, the system falls back to `memory`.\n */\n storeType: StoreType;\n\n /**\n * Experimental features.\n */\n experimental?: {\n /**\n * If the SDK should compress the replay events using a webworker.\n */\n useWebWorker: boolean;\n };\n\n /**\n * Remove certain parts of the DOM from being captured. These are typically ignored when blocking by selectors.\n */\n omitElementTags?: {\n /**\n * If true, removes script tags from the DOM, but not noscript tags.\n */\n script?: boolean;\n /**\n * If true, removes comment tags from the DOM.\n */\n comment?: boolean;\n };\n\n /**\n * If true, applies a background color to blocked elements in the replay.\n * This helps visualize which elements are blocked from being captured.\n */\n applyBackgroundColorToBlockedElements?: boolean;\n interactionConfig?: InteractionConfig;\n}\n\nexport interface SessionReplayJoinedConfig extends SessionReplayLocalConfig {\n captureEnabled?: boolean;\n interactionConfig?: InteractionConfig;\n loggingConfig?: LoggingConfig;\n}\n\nexport interface SessionReplayRemoteConfigFetch {\n getServerUrl: () => void;\n getSamplingConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig['sr_sampling_config'] | void>;\n fetchRemoteConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig | void>;\n getRemoteConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig | void>;\n}\n\nexport interface SessionReplayConfigs {\n localConfig: SessionReplayLocalConfig;\n joinedConfig: SessionReplayJoinedConfig;\n remoteConfig: SessionReplayRemoteConfig | undefined;\n}\nexport interface SessionReplayJoinedConfigGenerator {\n generateJoinedConfig: (sessionId?: string | number) => Promise<SessionReplayConfigs>;\n}\n\nexport interface SessionReplayMetadata {\n remoteConfig: SessionReplayRemoteConfig | undefined;\n localConfig: SessionReplayLocalConfig;\n joinedConfig: SessionReplayJoinedConfig;\n framework?: {\n name: string;\n version: string;\n };\n sessionId: string | number | undefined;\n hashValue?: number;\n sampleRate: number;\n replaySDKType: string | null;\n replaySDKVersion: string | undefined;\n standaloneSDKType: string;\n standaloneSDKVersion: string | undefined;\n}\n\nexport interface SessionReplayVersion {\n version: string;\n type: SessionReplayType;\n}\n\n/**\n * Configuration options for session replay performance.\n */\nexport interface SessionReplayPerformanceConfig {\n /**\n * If enabled, event compression will be deferred to occur during the browser's idle periods.\n */\n enabled: boolean;\n /**\n * Optional timeout in milliseconds for the `requestIdleCallback` API.\n * If specified, this value will be used to set a maximum time for the browser to wait\n * before executing the deferred compression task, even if the browser is not idle.\n */\n timeout?: number;\n}\n\nexport type SessionReplayType = 'standalone' | 'plugin' | 'segment';\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/config/types.ts"],"names":[],"mappings":";;;AA8Ca,QAAA,kBAAkB,GAAG,QAAQ,CAAC","sourcesContent":["import { IConfig, LogLevel, ILogger } from '@amplitude/analytics-core';\nimport { StoreType, ConsoleLogLevel } from '../typings/session-replay';\n\nexport interface SamplingConfig {\n sample_rate: number;\n capture_enabled: boolean;\n}\n\nexport interface InteractionConfig {\n trackEveryNms?: number;\n enabled: boolean; // defaults to false\n batch: boolean; // defaults to false\n /**\n * UGC filter rules.\n */\n ugcFilterRules?: UGCFilterRule[];\n}\n\nexport interface LoggingConfig {\n console: {\n enabled: boolean;\n levels: ConsoleLogLevel[];\n };\n network?: {\n enabled: boolean;\n };\n}\n\nexport type SessionReplayRemoteConfig = {\n sr_sampling_config?: SamplingConfig;\n sr_privacy_config?: PrivacyConfig;\n sr_interaction_config?: InteractionConfig;\n sr_logging_config?: LoggingConfig;\n};\n\nexport interface SessionReplayRemoteConfigAPIResponse {\n configs: {\n sessionReplay: SessionReplayRemoteConfig;\n };\n}\n\nexport type MaskLevel =\n | 'light' // only mask a subset of inputs that's deemed sensitive - password, credit card, telephone #, email. These are information we never want to capture.\n | 'medium' // mask all inputs\n | 'conservative'; // mask all inputs and all texts\n\nexport const DEFAULT_MASK_LEVEL = 'medium';\n\n// err on the side of excluding more\nexport type PrivacyConfig = {\n blockSelector?: string | string[]; // exclude in the UI\n defaultMaskLevel?: MaskLevel;\n maskSelector?: string[];\n unmaskSelector?: string[];\n};\n\n/**\n * UGC filter rule.\n */\nexport type UGCFilterRule = {\n /**\n * The selector of the UGC element.\n */\n selector: string;\n /**\n * The replacement text for the UGC element.\n */\n replacement: string;\n};\n\nexport interface SessionReplayLocalConfig extends IConfig {\n apiKey: string;\n loggerProvider: ILogger;\n /**\n * LogLevel.None or LogLevel.Error or LogLevel.Warn or LogLevel.Verbose or LogLevel.Debug.\n * Sets the log level.\n *\n * @defaultValue LogLevel.Warn\n */\n logLevel: LogLevel;\n /**\n * The maximum number of retries allowed for sending replay events.\n * Once this limit is reached, failed events will no longer be sent.\n *\n * @defaultValue 2\n */\n flushMaxRetries: number;\n /**\n * Use this option to control how many sessions to select for replay collection.\n * The number should be a decimal between 0 and 1, for example 0.4, representing\n * the fraction of sessions to have randomly selected for replay collection.\n * Over a large number of sessions, 0.4 would select 40% of those sessions.\n * Sample rates as small as six decimal places (0.000001) are supported.\n *\n * @defaultValue 0\n */\n sampleRate: number;\n privacyConfig?: PrivacyConfig;\n /**\n * Adds additional debug event property to help debug instrumentation issues\n * (such as mismatching apps). Only recommended for debugging initial setup,\n * and not recommended for production.\n */\n debugMode?: boolean;\n /**\n * Specifies the endpoint URL to fetch remote configuration.\n * If provided, it overrides the default server zone configuration.\n */\n configServerUrl?: string;\n /**\n * Specifies the endpoint URL for sending session replay data.\n * If provided, it overrides the default server zone configuration.\n */\n trackServerUrl?: string;\n /**\n * If stylesheets are inlined, the contents of the stylesheet will be stored.\n * During replay, the stored stylesheet will be used instead of attempting to fetch it remotely.\n * This prevents replays from appearing broken due to missing stylesheets.\n * Note: Inlining stylesheets may not work in all cases.\n */\n shouldInlineStylesheet?: boolean;\n version?: SessionReplayVersion;\n /**\n * Performance configuration config. If enabled, we will defer compression\n * to be done during the browser's idle periods.\n */\n performanceConfig?: SessionReplayPerformanceConfig;\n /**\n * Specifies how replay events should be stored. `idb` uses IndexedDB to persist replay events\n * when all events cannot be sent during capture. `memory` stores replay events only in memory,\n * meaning events are lost when the page is closed. If IndexedDB is unavailable, the system falls back to `memory`.\n */\n storeType: StoreType;\n\n /**\n * Experimental features.\n */\n experimental?: {\n /**\n * If the SDK should compress the replay events using a webworker.\n */\n useWebWorker: boolean;\n };\n\n /**\n * Remove certain parts of the DOM from being captured. These are typically ignored when blocking by selectors.\n */\n omitElementTags?: {\n /**\n * If true, removes script tags from the DOM, but not noscript tags.\n */\n script?: boolean;\n /**\n * If true, removes comment tags from the DOM.\n */\n comment?: boolean;\n };\n\n /**\n * If true, applies a background color to blocked elements in the replay.\n * This helps visualize which elements are blocked from being captured.\n */\n applyBackgroundColorToBlockedElements?: boolean;\n /**\n * Enables URL change polling as a fallback for SPA route tracking.\n * When enabled, the SDK will periodically check for URL changes every second\n * in addition to patching the History API. This is useful for edge cases where\n * route changes might bypass the standard History API methods.\n *\n * @defaultValue false\n */\n enableUrlChangePolling?: boolean;\n /**\n * Specifies the interval in milliseconds for URL change polling when enableUrlChangePolling is true.\n * The SDK will check for URL changes at this interval as a fallback for SPA route tracking.\n *\n * @defaultValue 1000\n */\n urlChangePollingInterval?: number;\n /**\n * Whether to capture document title in URL change events.\n * When disabled, the title field will be empty in URL change events.\n *\n * @defaultValue false\n */\n captureDocumentTitle?: boolean;\n interactionConfig?: InteractionConfig;\n}\n\nexport interface SessionReplayJoinedConfig extends SessionReplayLocalConfig {\n captureEnabled?: boolean;\n interactionConfig?: InteractionConfig;\n loggingConfig?: LoggingConfig;\n}\n\nexport interface SessionReplayRemoteConfigFetch {\n getServerUrl: () => void;\n getSamplingConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig['sr_sampling_config'] | void>;\n fetchRemoteConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig | void>;\n getRemoteConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig | void>;\n}\n\nexport interface SessionReplayConfigs {\n localConfig: SessionReplayLocalConfig;\n joinedConfig: SessionReplayJoinedConfig;\n remoteConfig: SessionReplayRemoteConfig | undefined;\n}\nexport interface SessionReplayJoinedConfigGenerator {\n generateJoinedConfig: (sessionId?: string | number) => Promise<SessionReplayConfigs>;\n}\n\nexport interface SessionReplayMetadata {\n remoteConfig: SessionReplayRemoteConfig | undefined;\n localConfig: SessionReplayLocalConfig;\n joinedConfig: SessionReplayJoinedConfig;\n framework?: {\n name: string;\n version: string;\n };\n sessionId: string | number | undefined;\n hashValue?: number;\n sampleRate: number;\n replaySDKType: string | null;\n replaySDKVersion: string | undefined;\n standaloneSDKType: string;\n standaloneSDKVersion: string | undefined;\n}\n\nexport interface SessionReplayVersion {\n version: string;\n type: SessionReplayType;\n}\n\n/**\n * Configuration options for session replay performance.\n */\nexport interface SessionReplayPerformanceConfig {\n /**\n * If enabled, event compression will be deferred to occur during the browser's idle periods.\n */\n enabled: boolean;\n /**\n * Optional timeout in milliseconds for the `requestIdleCallback` API.\n * If specified, this value will be used to set a maximum time for the browser to wait\n * before executing the deferred compression task, even if the browser is not idle.\n */\n timeout?: number;\n}\n\nexport type SessionReplayType = 'standalone' | 'plugin' | 'segment';\n"]}
|
package/lib/cjs/constants.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare const DEFAULT_SERVER_ZONE = ServerZone.US;
|
|
|
8
8
|
export declare const DEFAULT_PERFORMANCE_CONFIG: {
|
|
9
9
|
enabled: boolean;
|
|
10
10
|
};
|
|
11
|
+
export declare const DEFAULT_URL_CHANGE_POLLING_INTERVAL = 1000;
|
|
11
12
|
export declare const SESSION_REPLAY_DEBUG_PROPERTY: string;
|
|
12
13
|
export declare const BLOCK_CLASS = "amp-block";
|
|
13
14
|
export declare const MASK_TEXT_CLASS = "amp-mask";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEzE,eAAO,MAAM,6BAA6B,gBAAgB,CAAC;AAE3D,eAAO,MAAM,+BAA+B,QAAuD,CAAC;AACpG,eAAO,MAAM,2BAA2B,kBAAkB,CAAC;AAC3D,eAAO,MAAM,yBAAyB,gBAAgB,CAAC;AACvD,eAAO,MAAM,mBAAmB,IAAI,CAAC;AACrC,eAAO,MAAM,mBAAmB,gBAAgB,CAAC;AACjD,eAAO,MAAM,0BAA0B;;CAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,UAAU,EAAE,MAA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H = exports.KB_SIZE = exports.MAX_IDB_STORAGE_LENGTH = exports.MAX_INTERVAL = exports.MIN_INTERVAL = exports.INTERACTION_MAX_INTERVAL = exports.INTERACTION_MIN_INTERVAL = exports.MAX_EVENT_LIST_SIZE = exports.STORAGE_PREFIX = exports.SESSION_REPLAY_STAGING_URL = exports.SESSION_REPLAY_EU_URL = exports.SESSION_REPLAY_SERVER_URL = exports.UNMASK_TEXT_CLASS = exports.MASK_TEXT_CLASS = exports.BLOCK_CLASS = exports.SESSION_REPLAY_DEBUG_PROPERTY = exports.DEFAULT_PERFORMANCE_CONFIG = exports.DEFAULT_SERVER_ZONE = exports.DEFAULT_SAMPLE_RATE = exports.DEFAULT_SESSION_END_EVENT = exports.DEFAULT_SESSION_START_EVENT = exports.DEFAULT_SESSION_REPLAY_PROPERTY = exports.DEFAULT_EVENT_PROPERTY_PREFIX = void 0;
|
|
3
|
+
exports.CustomRRwebEvent = exports.MAX_URL_LENGTH = exports.KB_SIZE = exports.MAX_IDB_STORAGE_LENGTH = exports.MAX_INTERVAL = exports.MIN_INTERVAL = exports.INTERACTION_MAX_INTERVAL = exports.INTERACTION_MIN_INTERVAL = exports.MAX_EVENT_LIST_SIZE = exports.STORAGE_PREFIX = exports.SESSION_REPLAY_STAGING_URL = exports.SESSION_REPLAY_EU_URL = exports.SESSION_REPLAY_SERVER_URL = exports.UNMASK_TEXT_CLASS = exports.MASK_TEXT_CLASS = exports.BLOCK_CLASS = exports.SESSION_REPLAY_DEBUG_PROPERTY = exports.DEFAULT_URL_CHANGE_POLLING_INTERVAL = exports.DEFAULT_PERFORMANCE_CONFIG = exports.DEFAULT_SERVER_ZONE = exports.DEFAULT_SAMPLE_RATE = exports.DEFAULT_SESSION_END_EVENT = exports.DEFAULT_SESSION_START_EVENT = exports.DEFAULT_SESSION_REPLAY_PROPERTY = exports.DEFAULT_EVENT_PROPERTY_PREFIX = void 0;
|
|
4
4
|
var analytics_core_1 = require("@amplitude/analytics-core");
|
|
5
5
|
exports.DEFAULT_EVENT_PROPERTY_PREFIX = '[Amplitude]';
|
|
6
6
|
exports.DEFAULT_SESSION_REPLAY_PROPERTY = "".concat(exports.DEFAULT_EVENT_PROPERTY_PREFIX, " Session Replay ID");
|
|
@@ -9,6 +9,7 @@ exports.DEFAULT_SESSION_END_EVENT = 'session_end';
|
|
|
9
9
|
exports.DEFAULT_SAMPLE_RATE = 0;
|
|
10
10
|
exports.DEFAULT_SERVER_ZONE = analytics_core_1.ServerZone.US;
|
|
11
11
|
exports.DEFAULT_PERFORMANCE_CONFIG = { enabled: true };
|
|
12
|
+
exports.DEFAULT_URL_CHANGE_POLLING_INTERVAL = 1000;
|
|
12
13
|
exports.SESSION_REPLAY_DEBUG_PROPERTY = "".concat(exports.DEFAULT_EVENT_PROPERTY_PREFIX, " Session Replay Debug");
|
|
13
14
|
exports.BLOCK_CLASS = 'amp-block';
|
|
14
15
|
exports.MASK_TEXT_CLASS = 'amp-mask';
|
package/lib/cjs/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAA,4DAAyE;AAE5D,QAAA,6BAA6B,GAAG,aAAa,CAAC;AAE9C,QAAA,+BAA+B,GAAG,UAAG,qCAA6B,uBAAoB,CAAC;AACvF,QAAA,2BAA2B,GAAG,eAAe,CAAC;AAC9C,QAAA,yBAAyB,GAAG,aAAa,CAAC;AAC1C,QAAA,mBAAmB,GAAG,CAAC,CAAC;AACxB,QAAA,mBAAmB,GAAG,2BAAU,CAAC,EAAE,CAAC;AACpC,QAAA,0BAA0B,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAA,4DAAyE;AAE5D,QAAA,6BAA6B,GAAG,aAAa,CAAC;AAE9C,QAAA,+BAA+B,GAAG,UAAG,qCAA6B,uBAAoB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wBAAgB,KAAhB,wBAAgB,QAK3B","sourcesContent":["import { AMPLITUDE_PREFIX, ServerZone } from '@amplitude/analytics-core';\n\nexport const DEFAULT_EVENT_PROPERTY_PREFIX = '[Amplitude]';\n\nexport const DEFAULT_SESSION_REPLAY_PROPERTY = `${DEFAULT_EVENT_PROPERTY_PREFIX} Session Replay ID`;\nexport const DEFAULT_SESSION_START_EVENT = 'session_start';\nexport const DEFAULT_SESSION_END_EVENT = 'session_end';\nexport const DEFAULT_SAMPLE_RATE = 0;\nexport const DEFAULT_SERVER_ZONE = ServerZone.US;\nexport const DEFAULT_PERFORMANCE_CONFIG = { enabled: true };\nexport const DEFAULT_URL_CHANGE_POLLING_INTERVAL = 1000;\n\nexport const SESSION_REPLAY_DEBUG_PROPERTY = `${DEFAULT_EVENT_PROPERTY_PREFIX} Session Replay Debug`;\n\nexport const BLOCK_CLASS = 'amp-block';\nexport const MASK_TEXT_CLASS = 'amp-mask';\nexport const UNMASK_TEXT_CLASS = 'amp-unmask';\nexport const SESSION_REPLAY_SERVER_URL = 'https://api-sr.amplitude.com/sessions/v2/track';\nexport const SESSION_REPLAY_EU_URL = 'https://api-sr.eu.amplitude.com/sessions/v2/track';\nexport const SESSION_REPLAY_STAGING_URL = 'https://api-sr.stag2.amplitude.com/sessions/v2/track';\nexport const STORAGE_PREFIX = `${AMPLITUDE_PREFIX}_replay_unsent`;\nexport const MAX_EVENT_LIST_SIZE = 1 * 1000000; // ~1 MB limit for JSON serialized events payload\nexport const INTERACTION_MIN_INTERVAL = 30_000; // 30 seconds\nexport const INTERACTION_MAX_INTERVAL = 60_000; // 1 minute\nexport const MIN_INTERVAL = 500; // 500 ms\nexport const MAX_INTERVAL = 10 * 1000; // 10 seconds\nexport const MAX_IDB_STORAGE_LENGTH = 1000 * 60 * 60 * 24 * 3; // 3 days\nexport const KB_SIZE = 1024;\nexport const MAX_URL_LENGTH = 1000;\n\nexport enum CustomRRwebEvent {\n GET_SR_PROPS = 'get-sr-props',\n DEBUG_INFO = 'debug-info',\n FETCH_REQUEST = 'fetch-request',\n METADATA = 'metadata',\n}\n"]}
|
package/lib/cjs/helpers.d.ts
CHANGED
|
@@ -35,6 +35,9 @@ export declare const getDebugConfig: (config: SessionReplayJoinedConfig) => {
|
|
|
35
35
|
comment?: boolean | undefined;
|
|
36
36
|
} | undefined;
|
|
37
37
|
applyBackgroundColorToBlockedElements?: boolean | undefined;
|
|
38
|
+
enableUrlChangePolling?: boolean | undefined;
|
|
39
|
+
urlChangePollingInterval?: number | undefined;
|
|
40
|
+
captureDocumentTitle?: boolean | undefined;
|
|
38
41
|
flushIntervalMillis: number;
|
|
39
42
|
flushQueueSize: number;
|
|
40
43
|
instanceName?: string | undefined;
|
package/lib/cjs/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAiC,aAAa,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AASxH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAqFvD,eAAO,MAAM,MAAM,gBACH,MAAM,GAAG,OAAO,WAAW,aAAa,YAC/C,MAAM,WAAW,WAAW,GAAG,IAAI,KAAG,MAE5C,CAAC;AAEJ,eAAO,MAAM,gBAAgB,QAAkB,MAAM,WASpD,CAAC;AAEF,eAAO,MAAM,iBAAiB,cAAwB,MAAM,GAAG,MAAM,cAAc,MAAM,YAMxF,CAAC;AAEF,eAAO,MAAM,aAAa,cAGzB,CAAC;AAEF,eAAO,MAAM,uBAAuB,cAAe,MAAM,GAAG,MAAM,YAAY,MAAM,KAAG,MAEtF,CAAC;AAEF,eAAO,MAAM,YAAY,gBAAiB,MAAM,iBAAiB,mBAAmB,MAAM,KAAG,MAc5F,CAAC;AAmBF,eAAO,MAAM,sBAAsB,m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{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":";;;AAAA,gEAAsC","sourcesContent":["export * from './url-tracking-plugin';\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { UGCFilterRule } from '../config/types';
|
|
2
|
+
import { RecordPlugin } from '@amplitude/rrweb-types';
|
|
3
|
+
/**
|
|
4
|
+
* Event emitted when URL changes are detected by the plugin
|
|
5
|
+
* Contains the current page URL, title, and viewport dimensions
|
|
6
|
+
*/
|
|
7
|
+
export interface URLChangeEvent {
|
|
8
|
+
/** The current page URL (may be filtered if UGC rules are applied) */
|
|
9
|
+
href: string;
|
|
10
|
+
/** The current page title */
|
|
11
|
+
title: string;
|
|
12
|
+
/** Viewport height in pixels */
|
|
13
|
+
viewportHeight: number;
|
|
14
|
+
/** Viewport width in pixels */
|
|
15
|
+
viewportWidth: number;
|
|
16
|
+
/** The type of URL change event */
|
|
17
|
+
type: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Configuration options for the URL tracking plugin
|
|
21
|
+
*/
|
|
22
|
+
export interface URLTrackingPluginOptions {
|
|
23
|
+
/** Rules for filtering sensitive URLs (User Generated Content) */
|
|
24
|
+
ugcFilterRules?: UGCFilterRule[];
|
|
25
|
+
/** Whether to use polling instead of history API events for URL detection */
|
|
26
|
+
enablePolling?: boolean;
|
|
27
|
+
/** Interval in milliseconds for polling URL changes (default: 1000ms) */
|
|
28
|
+
pollingInterval?: number;
|
|
29
|
+
/** Whether to capture document title in URL change events (default: false) */
|
|
30
|
+
captureDocumentTitle?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates a URL tracking plugin for rrweb record function
|
|
34
|
+
*
|
|
35
|
+
* This plugin monitors URL changes in the browser and emits events when the URL changes.
|
|
36
|
+
* It supports three tracking modes:
|
|
37
|
+
* 1. Polling (if explicitly enabled) - periodically checks for URL changes
|
|
38
|
+
* 2. History API + Hash routing (default) - patches pushState/replaceState, listens to popstate and hashchange
|
|
39
|
+
* 3. Hash routing only (fallback) - listens to hashchange events when History API is unavailable
|
|
40
|
+
*
|
|
41
|
+
* The plugin handles edge cases gracefully:
|
|
42
|
+
* - Missing or null location objects
|
|
43
|
+
* - Undefined, null, or empty location.href values
|
|
44
|
+
* - Temporal dead zone issues with variable declarations
|
|
45
|
+
* - Consistent URL normalization across all code paths
|
|
46
|
+
*
|
|
47
|
+
* @param options Configuration options for URL tracking
|
|
48
|
+
* @returns RecordPlugin instance that can be used with rrweb
|
|
49
|
+
*/
|
|
50
|
+
export declare function createUrlTrackingPlugin(options?: URLTrackingPluginOptions): RecordPlugin<URLTrackingPluginOptions>;
|
|
51
|
+
/**
|
|
52
|
+
* Default URL tracking plugin instance with default options
|
|
53
|
+
* Can be used directly without custom configuration
|
|
54
|
+
*/
|
|
55
|
+
export declare const urlTrackingPlugin: RecordPlugin<URLTrackingPluginOptions>;
|
|
56
|
+
//# sourceMappingURL=url-tracking-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-tracking-plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/url-tracking-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,+BAA+B;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,kEAAkE;IAClE,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;IACjC,6EAA6E;IAC7E,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,yEAAyE;IACzE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,8EAA8E;IAC9E,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,GAAE,wBAA6B,GACrC,YAAY,CAAC,wBAAwB,CAAC,CA4KxC;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,wCAA4B,CAAC"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.urlTrackingPlugin = exports.createUrlTrackingPlugin = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var helpers_1 = require("../helpers");
|
|
6
|
+
var constants_1 = require("../constants");
|
|
7
|
+
/**
|
|
8
|
+
* Creates a URL tracking plugin for rrweb record function
|
|
9
|
+
*
|
|
10
|
+
* This plugin monitors URL changes in the browser and emits events when the URL changes.
|
|
11
|
+
* It supports three tracking modes:
|
|
12
|
+
* 1. Polling (if explicitly enabled) - periodically checks for URL changes
|
|
13
|
+
* 2. History API + Hash routing (default) - patches pushState/replaceState, listens to popstate and hashchange
|
|
14
|
+
* 3. Hash routing only (fallback) - listens to hashchange events when History API is unavailable
|
|
15
|
+
*
|
|
16
|
+
* The plugin handles edge cases gracefully:
|
|
17
|
+
* - Missing or null location objects
|
|
18
|
+
* - Undefined, null, or empty location.href values
|
|
19
|
+
* - Temporal dead zone issues with variable declarations
|
|
20
|
+
* - Consistent URL normalization across all code paths
|
|
21
|
+
*
|
|
22
|
+
* @param options Configuration options for URL tracking
|
|
23
|
+
* @returns RecordPlugin instance that can be used with rrweb
|
|
24
|
+
*/
|
|
25
|
+
function createUrlTrackingPlugin(options) {
|
|
26
|
+
if (options === void 0) { options = {}; }
|
|
27
|
+
return {
|
|
28
|
+
name: 'amplitude/url-tracking@1',
|
|
29
|
+
observer: function (cb, globalScope, pluginOptions) {
|
|
30
|
+
var _a, _b, _c;
|
|
31
|
+
// Merge options with plugin-level options taking precedence over constructor options
|
|
32
|
+
var config = tslib_1.__assign(tslib_1.__assign({}, options), pluginOptions);
|
|
33
|
+
var ugcFilterRules = config.ugcFilterRules || [];
|
|
34
|
+
var enablePolling = (_a = config.enablePolling) !== null && _a !== void 0 ? _a : false;
|
|
35
|
+
var pollingInterval = (_b = config.pollingInterval) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_URL_CHANGE_POLLING_INTERVAL;
|
|
36
|
+
var captureDocumentTitle = (_c = config.captureDocumentTitle) !== null && _c !== void 0 ? _c : false;
|
|
37
|
+
// Early return if no global scope is available
|
|
38
|
+
if (!globalScope) {
|
|
39
|
+
return function () {
|
|
40
|
+
// No cleanup needed if no global scope available
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// Track the last URL to prevent duplicate events
|
|
44
|
+
// Initialize to undefined to ensure first call always emits an event
|
|
45
|
+
var lastTrackedUrl = undefined;
|
|
46
|
+
// Helper functions
|
|
47
|
+
/**
|
|
48
|
+
* Gets the current URL with proper normalization
|
|
49
|
+
* Handles edge cases where location.href might be undefined, null, or empty
|
|
50
|
+
* Ensures consistent behavior across all code paths
|
|
51
|
+
* @returns Normalized URL string (empty string if location unavailable)
|
|
52
|
+
*/
|
|
53
|
+
var getCurrentUrl = function () {
|
|
54
|
+
if (!globalScope.location)
|
|
55
|
+
return '';
|
|
56
|
+
return globalScope.location.href || '';
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Creates a URL change event with current page information
|
|
60
|
+
* Applies UGC filtering if rules are configured
|
|
61
|
+
* Uses getCurrentUrl() for consistent URL normalization
|
|
62
|
+
* @returns URLChangeEvent with current page state
|
|
63
|
+
*/
|
|
64
|
+
var createUrlChangeEvent = function () {
|
|
65
|
+
var innerHeight = globalScope.innerHeight, innerWidth = globalScope.innerWidth, document = globalScope.document;
|
|
66
|
+
var currentUrl = getCurrentUrl();
|
|
67
|
+
var currentTitle = '';
|
|
68
|
+
if (captureDocumentTitle) {
|
|
69
|
+
currentTitle = (document === null || document === void 0 ? void 0 : document.title) || '';
|
|
70
|
+
}
|
|
71
|
+
// Apply UGC filtering if rules are provided, otherwise use original URL
|
|
72
|
+
var filteredUrl = ugcFilterRules.length > 0 ? (0, helpers_1.getPageUrl)(currentUrl, ugcFilterRules) : currentUrl;
|
|
73
|
+
return {
|
|
74
|
+
href: filteredUrl,
|
|
75
|
+
title: currentTitle,
|
|
76
|
+
viewportHeight: innerHeight,
|
|
77
|
+
viewportWidth: innerWidth,
|
|
78
|
+
type: 'url-change-event',
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Emits a URL change event if the URL has actually changed
|
|
83
|
+
* Always emits on first call (when lastTrackedUrl is undefined)
|
|
84
|
+
* Prevents duplicate events for the same URL on subsequent calls
|
|
85
|
+
* Handles edge cases like undefined/null/empty URLs gracefully
|
|
86
|
+
*/
|
|
87
|
+
var emitUrlChange = function () {
|
|
88
|
+
var currentUrl = getCurrentUrl();
|
|
89
|
+
// Always emit on first call, or if URL actually changed
|
|
90
|
+
if (lastTrackedUrl === undefined || currentUrl !== lastTrackedUrl) {
|
|
91
|
+
lastTrackedUrl = currentUrl;
|
|
92
|
+
var event_1 = createUrlChangeEvent();
|
|
93
|
+
cb(event_1);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Creates a patched version of history methods (pushState/replaceState)
|
|
98
|
+
* that calls the original method and then emits a URL change event
|
|
99
|
+
* Ensures URL changes are detected even when history methods are called programmatically
|
|
100
|
+
* @param originalMethod The original history method to patch
|
|
101
|
+
* @returns Patched function that calls original method then emits URL change event
|
|
102
|
+
*/
|
|
103
|
+
var createHistoryMethodPatch = function (originalMethod) {
|
|
104
|
+
return function () {
|
|
105
|
+
var args = [];
|
|
106
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
107
|
+
args[_i] = arguments[_i];
|
|
108
|
+
}
|
|
109
|
+
// Call the original history method first
|
|
110
|
+
var result = originalMethod.apply(this, args);
|
|
111
|
+
// Then emit URL change event
|
|
112
|
+
emitUrlChange();
|
|
113
|
+
return result;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
// Hashchange event handler - delegates to emitUrlChange for consistency
|
|
117
|
+
var hashChangeHandler = function () {
|
|
118
|
+
emitUrlChange();
|
|
119
|
+
};
|
|
120
|
+
// 1. if explicitly enable polling → use polling
|
|
121
|
+
if (enablePolling) {
|
|
122
|
+
// Use polling (covers everything)
|
|
123
|
+
var urlChangeInterval_1 = globalScope.setInterval(function () {
|
|
124
|
+
emitUrlChange();
|
|
125
|
+
}, pollingInterval);
|
|
126
|
+
// Emit initial URL immediately
|
|
127
|
+
emitUrlChange();
|
|
128
|
+
// Return cleanup function to stop polling
|
|
129
|
+
return function () {
|
|
130
|
+
if (urlChangeInterval_1) {
|
|
131
|
+
globalScope.clearInterval(urlChangeInterval_1);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
// 2. if polling not enabled → check history, if exist, use history
|
|
136
|
+
if (globalScope.history) {
|
|
137
|
+
// Use History API + hashchange (covers History API + hash routing)
|
|
138
|
+
// Store original history methods for restoration during cleanup
|
|
139
|
+
var originalPushState_1 = globalScope.history.pushState.bind(globalScope.history);
|
|
140
|
+
var originalReplaceState_1 = globalScope.history.replaceState.bind(globalScope.history);
|
|
141
|
+
/**
|
|
142
|
+
* Sets up history method patching to intercept pushState and replaceState calls
|
|
143
|
+
* This ensures URL changes are detected even when history methods are called programmatically
|
|
144
|
+
*/
|
|
145
|
+
var setupHistoryPatching = function () {
|
|
146
|
+
// Patch pushState to emit URL change events
|
|
147
|
+
globalScope.history.pushState = createHistoryMethodPatch(originalPushState_1);
|
|
148
|
+
// Patch replaceState to emit URL change events
|
|
149
|
+
globalScope.history.replaceState = createHistoryMethodPatch(originalReplaceState_1);
|
|
150
|
+
};
|
|
151
|
+
// Apply history method patches
|
|
152
|
+
setupHistoryPatching();
|
|
153
|
+
// Listen to popstate events for browser back/forward navigation
|
|
154
|
+
globalScope.addEventListener('popstate', emitUrlChange);
|
|
155
|
+
// Listen to hashchange events for hash routing
|
|
156
|
+
globalScope.addEventListener('hashchange', hashChangeHandler);
|
|
157
|
+
// Emit initial URL immediately
|
|
158
|
+
emitUrlChange();
|
|
159
|
+
// Return cleanup function to restore original state
|
|
160
|
+
return function () {
|
|
161
|
+
// Restore original history methods
|
|
162
|
+
globalScope.history.pushState = originalPushState_1;
|
|
163
|
+
globalScope.history.replaceState = originalReplaceState_1;
|
|
164
|
+
// Remove popstate event listener
|
|
165
|
+
globalScope.removeEventListener('popstate', emitUrlChange);
|
|
166
|
+
// Remove hashchange event listener
|
|
167
|
+
globalScope.removeEventListener('hashchange', hashChangeHandler);
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
// 3. if not, then the framework is probably using hash router → do hash
|
|
171
|
+
// Fallback: just hashchange (for pure hash routing)
|
|
172
|
+
globalScope.addEventListener('hashchange', hashChangeHandler);
|
|
173
|
+
emitUrlChange();
|
|
174
|
+
return function () {
|
|
175
|
+
globalScope.removeEventListener('hashchange', hashChangeHandler);
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
options: options,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
exports.createUrlTrackingPlugin = createUrlTrackingPlugin;
|
|
182
|
+
/**
|
|
183
|
+
* Default URL tracking plugin instance with default options
|
|
184
|
+
* Can be used directly without custom configuration
|
|
185
|
+
*/
|
|
186
|
+
exports.urlTrackingPlugin = createUrlTrackingPlugin();
|
|
187
|
+
//# sourceMappingURL=url-tracking-plugin.js.map
|
|
@@ -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AAG,mBAAiB,CAAC;oBAClD,WAAW,CAAC,OAAO,CAAC,YAAY,GAAG,sBAAoB,CAAC;oBAExD,iCAAiC;oBACjC,WAAW,CAAC,mBAAmB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;oBAC3D,mCAAmC;oBACnC,WAAW,CAAC,mBAAmB,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC;gBACnE,CAAC,CAAC;aACH;YAED,wEAAwE;YACxE,oDAAoD;YACpD,WAAW,CAAC,gBAAgB,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC;YAC9D,aAAa,EAAE,CAAC;YAChB,OAAO;gBACL,WAAW,CAAC,mBAAmB,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC;YACnE,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,SAAA;KACR,CAAC;AACJ,CAAC;AA9KD,0DA8KC;AAED;;;GAGG;AACU,QAAA,iBAAiB,GAAG,uBAAuB,EAAE,CAAC","sourcesContent":["import { getPageUrl } from '../helpers';\nimport { UGCFilterRule } from '../config/types';\nimport { DEFAULT_URL_CHANGE_POLLING_INTERVAL } from '../constants';\nimport { RecordPlugin } from '@amplitude/rrweb-types';\n\n/**\n * Event emitted when URL changes are detected by the plugin\n * Contains the current page URL, title, and viewport dimensions\n */\nexport interface URLChangeEvent {\n /** The current page URL (may be filtered if UGC rules are applied) */\n href: string;\n /** The current page title */\n title: string;\n /** Viewport height in pixels */\n viewportHeight: number;\n /** Viewport width in pixels */\n viewportWidth: number;\n /** The type of URL change event */\n type: string;\n}\n\n/**\n * Configuration options for the URL tracking plugin\n */\nexport interface URLTrackingPluginOptions {\n /** Rules for filtering sensitive URLs (User Generated Content) */\n ugcFilterRules?: UGCFilterRule[];\n /** Whether to use polling instead of history API events for URL detection */\n enablePolling?: boolean;\n /** Interval in milliseconds for polling URL changes (default: 1000ms) */\n pollingInterval?: number;\n /** Whether to capture document title in URL change events (default: false) */\n captureDocumentTitle?: boolean;\n}\n\n/**\n * Creates a URL tracking plugin for rrweb record function\n *\n * This plugin monitors URL changes in the browser and emits events when the URL changes.\n * It supports three tracking modes:\n * 1. Polling (if explicitly enabled) - periodically checks for URL changes\n * 2. History API + Hash routing (default) - patches pushState/replaceState, listens to popstate and hashchange\n * 3. Hash routing only (fallback) - listens to hashchange events when History API is unavailable\n *\n * The plugin handles edge cases gracefully:\n * - Missing or null location objects\n * - Undefined, null, or empty location.href values\n * - Temporal dead zone issues with variable declarations\n * - Consistent URL normalization across all code paths\n *\n * @param options Configuration options for URL tracking\n * @returns RecordPlugin instance that can be used with rrweb\n */\nexport function createUrlTrackingPlugin(\n options: URLTrackingPluginOptions = {},\n): RecordPlugin<URLTrackingPluginOptions> {\n return {\n name: 'amplitude/url-tracking@1',\n observer(cb, globalScope, pluginOptions?: URLTrackingPluginOptions) {\n // Merge options with plugin-level options taking precedence over constructor options\n const config = { ...options, ...pluginOptions };\n const ugcFilterRules = config.ugcFilterRules || [];\n const enablePolling = config.enablePolling ?? false;\n const pollingInterval = config.pollingInterval ?? DEFAULT_URL_CHANGE_POLLING_INTERVAL;\n const captureDocumentTitle = config.captureDocumentTitle ?? false;\n\n // Early return if no global scope is available\n if (!globalScope) {\n return () => {\n // No cleanup needed if no global scope available\n };\n }\n\n // Track the last URL to prevent duplicate events\n // Initialize to undefined to ensure first call always emits an event\n let lastTrackedUrl: string | undefined = undefined;\n\n // Helper functions\n /**\n * Gets the current URL with proper normalization\n * Handles edge cases where location.href might be undefined, null, or empty\n * Ensures consistent behavior across all code paths\n * @returns Normalized URL string (empty string if location unavailable)\n */\n const getCurrentUrl = (): string => {\n if (!globalScope.location) return '';\n return globalScope.location.href || '';\n };\n\n /**\n * Creates a URL change event with current page information\n * Applies UGC filtering if rules are configured\n * Uses getCurrentUrl() for consistent URL normalization\n * @returns URLChangeEvent with current page state\n */\n const createUrlChangeEvent = (): URLChangeEvent => {\n const { innerHeight, innerWidth, document } = globalScope;\n const currentUrl = getCurrentUrl();\n let currentTitle = '';\n if (captureDocumentTitle) {\n currentTitle = document?.title || '';\n }\n\n // Apply UGC filtering if rules are provided, otherwise use original URL\n const filteredUrl = ugcFilterRules.length > 0 ? getPageUrl(currentUrl, ugcFilterRules) : currentUrl;\n\n return {\n href: filteredUrl,\n title: currentTitle,\n viewportHeight: innerHeight,\n viewportWidth: innerWidth,\n type: 'url-change-event',\n };\n };\n\n /**\n * Emits a URL change event if the URL has actually changed\n * Always emits on first call (when lastTrackedUrl is undefined)\n * Prevents duplicate events for the same URL on subsequent calls\n * Handles edge cases like undefined/null/empty URLs gracefully\n */\n const emitUrlChange = (): void => {\n const currentUrl = getCurrentUrl();\n\n // Always emit on first call, or if URL actually changed\n if (lastTrackedUrl === undefined || currentUrl !== lastTrackedUrl) {\n lastTrackedUrl = currentUrl;\n const event = createUrlChangeEvent();\n cb(event);\n }\n };\n\n /**\n * Creates a patched version of history methods (pushState/replaceState)\n * that calls the original method and then emits a URL change event\n * Ensures URL changes are detected even when history methods are called programmatically\n * @param originalMethod The original history method to patch\n * @returns Patched function that calls original method then emits URL change event\n */\n const createHistoryMethodPatch = <T extends typeof history.pushState | typeof history.replaceState>(\n originalMethod: T,\n ) => {\n return function (this: History, ...args: Parameters<T>) {\n // Call the original history method first\n const result = originalMethod.apply(this, args);\n // Then emit URL change event\n emitUrlChange();\n return result;\n };\n };\n\n // Hashchange event handler - delegates to emitUrlChange for consistency\n const hashChangeHandler = () => {\n emitUrlChange();\n };\n\n // 1. if explicitly enable polling → use polling\n if (enablePolling) {\n // Use polling (covers everything)\n const urlChangeInterval = globalScope.setInterval(() => {\n emitUrlChange();\n }, pollingInterval);\n\n // Emit initial URL immediately\n emitUrlChange();\n\n // Return cleanup function to stop polling\n return () => {\n if (urlChangeInterval) {\n globalScope.clearInterval(urlChangeInterval);\n }\n };\n }\n\n // 2. if polling not enabled → check history, if exist, use history\n if (globalScope.history) {\n // Use History API + hashchange (covers History API + hash routing)\n // Store original history methods for restoration during cleanup\n const originalPushState = globalScope.history.pushState.bind(globalScope.history);\n const originalReplaceState = globalScope.history.replaceState.bind(globalScope.history);\n\n /**\n * Sets up history method patching to intercept pushState and replaceState calls\n * This ensures URL changes are detected even when history methods are called programmatically\n */\n const setupHistoryPatching = (): void => {\n // Patch pushState to emit URL change events\n globalScope.history.pushState = createHistoryMethodPatch(originalPushState);\n\n // Patch replaceState to emit URL change events\n globalScope.history.replaceState = createHistoryMethodPatch(originalReplaceState);\n };\n\n // Apply history method patches\n setupHistoryPatching();\n\n // Listen to popstate events for browser back/forward navigation\n globalScope.addEventListener('popstate', emitUrlChange);\n // Listen to hashchange events for hash routing\n globalScope.addEventListener('hashchange', hashChangeHandler);\n\n // Emit initial URL immediately\n emitUrlChange();\n\n // Return cleanup function to restore original state\n return () => {\n // Restore original history methods\n globalScope.history.pushState = originalPushState;\n globalScope.history.replaceState = originalReplaceState;\n\n // Remove popstate event listener\n globalScope.removeEventListener('popstate', emitUrlChange);\n // Remove hashchange event listener\n globalScope.removeEventListener('hashchange', hashChangeHandler);\n };\n }\n\n // 3. if not, then the framework is probably using hash router → do hash\n // Fallback: just hashchange (for pure hash routing)\n globalScope.addEventListener('hashchange', hashChangeHandler);\n emitUrlChange();\n return () => {\n globalScope.removeEventListener('hashchange', hashChangeHandler);\n };\n },\n options,\n };\n}\n\n/**\n * Default URL tracking plugin instance with default options\n * Can be used directly without custom configuration\n */\nexport const urlTrackingPlugin = createUrlTrackingPlugin();\n"]}
|
|
@@ -43,7 +43,7 @@ export declare class SessionReplay implements AmplitudeSessionReplay {
|
|
|
43
43
|
getShouldRecord(): boolean;
|
|
44
44
|
getBlockSelectors(): string | string[] | undefined;
|
|
45
45
|
getMaskTextSelectors(): string | undefined;
|
|
46
|
-
getRecordingPlugins(loggingConfig: LoggingConfig | undefined): Promise<import("@amplitude/rrweb-types").RecordPlugin<unknown>[] | undefined>;
|
|
46
|
+
getRecordingPlugins(loggingConfig: LoggingConfig | undefined): Promise<(import("@amplitude/rrweb-types").RecordPlugin<import("./plugins/url-tracking-plugin").URLTrackingPluginOptions> | import("@amplitude/rrweb-types").RecordPlugin<unknown>)[] | undefined>;
|
|
47
47
|
private getRecordFunction;
|
|
48
48
|
recordEvents(shouldLogMetadata?: boolean): Promise<void>;
|
|
49
49
|
addCustomRRWebEvent: (eventName: CustomRRwebEvent, eventData?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,OAAO,EAER,MAAM,2BAA2B,CAAC;AAKnC,OAAO,EACL,aAAa,EACb,yBAAyB,EACzB,kCAAkC,EAInC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,gBAAgB,EAMjB,MAAM,aAAa,CAAC;AAOrB,OAAO,EACL,sBAAsB,EACtB,0BAA0B,IAAI,mCAAmC,EAIjE,kBAAkB,IAAI,mBAAmB,EACzC,oBAAoB,EACrB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,OAAO,EAER,MAAM,2BAA2B,CAAC;AAKnC,OAAO,EACL,aAAa,EACb,yBAAyB,EACzB,kCAAkC,EAInC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,gBAAgB,EAMjB,MAAM,aAAa,CAAC;AAOrB,OAAO,EACL,sBAAsB,EACtB,0BAA0B,IAAI,mCAAmC,EAIjE,kBAAkB,IAAI,mBAAmB,EACzC,oBAAoB,EACrB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAM5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,KAAK,WAAW,GAAG,CAAC,CAAC,EAAE,mBAAmB,GAAG,KAAK,KAAK,IAAI,CAAC;AAE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AAI,MAAM,GAAG,SAAS;IAapC,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,SAAS;YAyCpD,iBAAiB;IAezB,YAAY,CAAC,iBAAiB,UAAO;IA4G3C,mBAAmB,cACN,gBAAgB;;kDAmC3B;IAEF,mBAAmB,aAUjB;IAEF,WAAW;IAIX,YAAY;IAIN,KAAK,CAAC,QAAQ,UAAQ;IAI5B,QAAQ;IAMR,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,WAAW;YAyBL,0BAA0B;CAUzC"}
|
|
@@ -16,6 +16,7 @@ var identifiers_1 = require("./identifiers");
|
|
|
16
16
|
var version_1 = require("./version");
|
|
17
17
|
var event_compressor_1 = require("./events/event-compressor");
|
|
18
18
|
var logger_1 = require("./logger");
|
|
19
|
+
var url_tracking_plugin_1 = require("./plugins/url-tracking-plugin");
|
|
19
20
|
var SessionReplay = /** @class */ (function () {
|
|
20
21
|
function SessionReplay() {
|
|
21
22
|
var _this = this;
|
|
@@ -359,24 +360,37 @@ var SessionReplay = /** @class */ (function () {
|
|
|
359
360
|
return maskSelector;
|
|
360
361
|
};
|
|
361
362
|
SessionReplay.prototype.getRecordingPlugins = function (loggingConfig) {
|
|
362
|
-
var _a;
|
|
363
|
+
var _a, _b, _c, _d, _e, _f;
|
|
363
364
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
364
|
-
var plugins, getRecordConsolePlugin, error_3;
|
|
365
|
-
return tslib_1.__generator(this, function (
|
|
366
|
-
switch (
|
|
365
|
+
var plugins, urlTrackingPlugin, getRecordConsolePlugin, error_3;
|
|
366
|
+
return tslib_1.__generator(this, function (_g) {
|
|
367
|
+
switch (_g.label) {
|
|
367
368
|
case 0:
|
|
368
369
|
plugins = [];
|
|
369
|
-
|
|
370
|
-
|
|
370
|
+
// Add URL tracking plugin
|
|
371
|
+
try {
|
|
372
|
+
urlTrackingPlugin = (0, url_tracking_plugin_1.createUrlTrackingPlugin)({
|
|
373
|
+
ugcFilterRules: ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.interactionConfig) === null || _b === void 0 ? void 0 : _b.ugcFilterRules) || [],
|
|
374
|
+
enablePolling: ((_c = this.config) === null || _c === void 0 ? void 0 : _c.enableUrlChangePolling) || false,
|
|
375
|
+
pollingInterval: (_d = this.config) === null || _d === void 0 ? void 0 : _d.urlChangePollingInterval,
|
|
376
|
+
captureDocumentTitle: (_e = this.config) === null || _e === void 0 ? void 0 : _e.captureDocumentTitle,
|
|
377
|
+
});
|
|
378
|
+
plugins.push(urlTrackingPlugin);
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
this.loggerProvider.warn('Failed to create URL tracking plugin:', error);
|
|
382
|
+
}
|
|
383
|
+
if (!((_f = loggingConfig === null || loggingConfig === void 0 ? void 0 : loggingConfig.console) === null || _f === void 0 ? void 0 : _f.enabled)) return [3 /*break*/, 4];
|
|
384
|
+
_g.label = 1;
|
|
371
385
|
case 1:
|
|
372
|
-
|
|
386
|
+
_g.trys.push([1, 3, , 4]);
|
|
373
387
|
return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require('@amplitude/rrweb-plugin-console-record')); })];
|
|
374
388
|
case 2:
|
|
375
|
-
getRecordConsolePlugin = (
|
|
389
|
+
getRecordConsolePlugin = (_g.sent()).getRecordConsolePlugin;
|
|
376
390
|
plugins.push(getRecordConsolePlugin({ level: loggingConfig.console.levels }));
|
|
377
391
|
return [3 /*break*/, 4];
|
|
378
392
|
case 3:
|
|
379
|
-
error_3 =
|
|
393
|
+
error_3 = _g.sent();
|
|
380
394
|
this.loggerProvider.warn('Failed to load console plugin:', error_3);
|
|
381
395
|
return [3 /*break*/, 4];
|
|
382
396
|
case 4: return [2 /*return*/, plugins.length > 0 ? plugins : undefined];
|