Skip to content

Commit 8843969

Browse files
committed
fix(replay): Fix recording size incorrect due to encoding
For uncompressed payloads, we were potentially sending the incorrect size due to encoding issues. Instead encode to UTF8 when determining the payload size. Note that `TextEncoder` mostly overlaps with `MutationObserver` support *except* for IE11. So we will not be supporting IE11.
1 parent 770a33d commit 8843969

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/replay/src/util/createReplayEnvelope.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { DsnComponents, ReplayEnvelope, ReplayEvent, ReplayRecordingData } from '@sentry/types';
2-
import { createEnvelope, createEventEnvelopeHeaders, getSdkMetadataForEnvelopeHeader } from '@sentry/utils';
2+
import { createEnvelope, createEventEnvelopeHeaders, encodeUTF8, getSdkMetadataForEnvelopeHeader } from '@sentry/utils';
33

44
/**
55
* Create a replay envelope ready to be sent.
@@ -18,7 +18,10 @@ export function createReplayEnvelope(
1818
[
1919
{
2020
type: 'replay_recording',
21-
length: recordingData.length,
21+
// If string then we need to encode to UTF8, otherwise will have
22+
// wrong size. TextEncoder has similar browser support to
23+
// MutationObserver, although it does not accept IE11.
24+
length: typeof recordingData === 'string' ? encodeUTF8(recordingData).length : recordingData.length,
2225
},
2326
recordingData,
2427
],

packages/utils/src/envelope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function forEachEnvelopeItem<E extends Envelope>(
5353
});
5454
}
5555

56-
function encodeUTF8(input: string, textEncoder?: TextEncoderInternal): Uint8Array {
56+
export function encodeUTF8(input: string, textEncoder?: TextEncoderInternal): Uint8Array {
5757
const utf8 = textEncoder || new TextEncoder();
5858
return utf8.encode(input);
5959
}

0 commit comments

Comments
 (0)