Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/replay/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { getCurrentHub } from '@sentry/core';
import type { ReplayRecordingData, Transport } from '@sentry/types';
import {TextEncoder} from 'util';

import type { ReplayContainer, Session } from './src/types';

// @ts-ignore TS error, this is replaced in prod builds bc of rollup
global.__SENTRY_REPLAY_VERSION__ = 'version:Test';

(global as any).TextEncoder = TextEncoder;

type MockTransport = jest.MockedFunction<Transport['send']>;

jest.mock('./src/util/isBrowser', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/replay/src/util/createReplayEnvelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export function createReplayEnvelope(
[
{
type: 'replay_recording',
length: recordingData.length,
// If string then we need to encode to UTF8, otherwise will have
// wrong size. TextEncoder has similar browser support to
// MutationObserver, although it does not accept IE11.
length:
typeof recordingData === 'string' ? new TextEncoder().encode(recordingData).length : recordingData.length,
},
recordingData,
],
Expand Down
3 changes: 3 additions & 0 deletions packages/utils/src/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export function forEachEnvelopeItem<E extends Envelope>(
});
}

/**
* Encode a string to UTF8.
*/
function encodeUTF8(input: string, textEncoder?: TextEncoderInternal): Uint8Array {
const utf8 = textEncoder || new TextEncoder();
return utf8.encode(input);
Expand Down