diff --git a/src/constants.ts b/src/constants.ts index ec9cbddc9..7c0fda8de 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -14,6 +14,7 @@ export const AUTOCAPTURE_DISABLED_SERVER_SIDE = '$autocapture_disabled_server_si export const SESSION_RECORDING_ENABLED_SERVER_SIDE = '$session_recording_enabled_server_side' export const CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE = '$console_log_recording_enabled_server_side' export const SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE = '$session_recording_recorder_version_server_side' // follows rrweb versioning +export const SESSION_RECORDING_NETWORK_PAYLOAD_CAPTURE = '$session_recording_network_payload_capture' export const SESSION_ID = '$sesid' export const SESSION_RECORDING_IS_SAMPLED = '$session_is_sampled' export const ENABLED_FEATURE_FLAGS = '$enabled_feature_flags' diff --git a/src/extensions/replay/sessionrecording.ts b/src/extensions/replay/sessionrecording.ts index 7814f4454..4da866dac 100644 --- a/src/extensions/replay/sessionrecording.ts +++ b/src/extensions/replay/sessionrecording.ts @@ -2,6 +2,7 @@ import { CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE, SESSION_RECORDING_ENABLED_SERVER_SIDE, SESSION_RECORDING_IS_SAMPLED, + SESSION_RECORDING_NETWORK_PAYLOAD_CAPTURE, SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE, } from '../../constants' import { @@ -92,7 +93,6 @@ export class SessionRecording { private receivedDecide: boolean private rrwebRecord: rrwebRecord | undefined private isIdle = false - private _networkPayloadCapture: Pick | undefined = undefined private _linkedFlagSeen: boolean = false private _lastActivityTimestamp: number = Date.now() @@ -148,6 +148,19 @@ export class SessionRecording { return recordingVersion_client_side || recordingVersion_server_side || 'v1' } + private get networkPayloadCapture(): Pick | undefined { + const networkPayloadCapture_server_side = this.instance.get_property(SESSION_RECORDING_NETWORK_PAYLOAD_CAPTURE) + const networkPayloadCapture_client_side = { + recordHeaders: this.instance.config.session_recording?.recordHeaders, + recordBody: this.instance.config.session_recording?.recordBody, + } + const headersEnabled = + networkPayloadCapture_client_side?.recordHeaders || networkPayloadCapture_server_side?.recordHeaders + const bodyEnabled = + networkPayloadCapture_client_side?.recordBody || networkPayloadCapture_server_side?.recordBody + return headersEnabled || bodyEnabled ? { recordHeaders: headersEnabled, recordBody: bodyEnabled } : undefined + } + /** * defaults to buffering mode until a decide response is received * once a decide response is received status can be disabled, active or sampled @@ -252,11 +265,10 @@ export class SessionRecording { [SESSION_RECORDING_ENABLED_SERVER_SIDE]: !!response['sessionRecording'], [CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE]: response.sessionRecording?.consoleLogRecordingEnabled, [SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE]: response.sessionRecording?.recorderVersion, + [SESSION_RECORDING_NETWORK_PAYLOAD_CAPTURE]: response.sessionRecording?.networkPayloadCapture, }) } - this._networkPayloadCapture = response.sessionRecording?.networkPayloadCapture - const receivedSampleRate = response.sessionRecording?.sampleRate this._sampleRate = _isUndefined(receivedSampleRate) || _isNull(receivedSampleRate) ? null : parseFloat(receivedSampleRate) @@ -472,14 +484,12 @@ export class SessionRecording { if ((window as any).rrwebConsoleRecord && this.isConsoleLogCaptureEnabled) { plugins.push((window as any).rrwebConsoleRecord.getRecordConsolePlugin()) } - if (this._networkPayloadCapture) { - if (_isFunction((window as any).getRecordNetworkPlugin)) { - plugins.push( - (window as any).getRecordNetworkPlugin( - buildNetworkRequestOptions(this.instance.config, this._networkPayloadCapture) - ) + if (this.networkPayloadCapture && _isFunction((window as any).getRecordNetworkPlugin)) { + plugins.push( + (window as any).getRecordNetworkPlugin( + buildNetworkRequestOptions(this.instance.config, this.networkPayloadCapture) ) - } + ) } this.stopRrweb = this.rrwebRecord({