@@ -6,14 +6,15 @@ import { disabledUntil, logger } from '@sentry/utils';
6
6
import { EventType , record } from 'rrweb' ;
7
7
8
8
import {
9
+ ERROR_CHECKOUT_TIME ,
9
10
MAX_SESSION_LIFE ,
10
11
SESSION_IDLE_DURATION ,
11
12
VISIBILITY_CHANGE_TIMEOUT ,
12
13
WINDOW ,
13
- ERROR_CHECKOUT_TIME ,
14
14
} from './constants' ;
15
15
import { setupPerformanceObserver } from './coreHandlers/performanceObserver' ;
16
16
import { createEventBuffer } from './eventBuffer' ;
17
+ import { EventBufferProxy } from './eventBuffer/EventBufferProxy' ;
17
18
import { getSession } from './session/getSession' ;
18
19
import { saveSession } from './session/saveSession' ;
19
20
import type {
@@ -328,9 +329,18 @@ export class ReplayContainer implements ReplayContainerInterface {
328
329
* from calling both `flush` and `_debouncedFlush`. Otherwise, there could be
329
330
* cases of mulitple flushes happening closely together.
330
331
*/
331
- public flushImmediate ( ) : Promise < void > {
332
+ public async flushImmediate ( waitForCompression ?: boolean ) : Promise < void > {
332
333
this . _debouncedFlush ( ) ;
333
334
// `.flush` is provided by the debounced function, analogously to lodash.debounce
335
+
336
+ // Ensure the worker is loaded, so the sent event is compressed
337
+ if ( waitForCompression && this . eventBuffer instanceof EventBufferProxy ) {
338
+ try {
339
+ await this . eventBuffer . ensureWorkerIsLoaded ( ) ;
340
+ } catch ( error ) {
341
+ // If this fails, we'll just send uncompressed events
342
+ }
343
+ }
334
344
return this . _debouncedFlush . flush ( ) as Promise < void > ;
335
345
}
336
346
@@ -541,7 +551,8 @@ export class ReplayContainer implements ReplayContainerInterface {
541
551
// replays (e.g. opening and closing a tab quickly), but these can be
542
552
// filtered on the UI.
543
553
if ( this . recordingMode === 'session' ) {
544
- void this . flushImmediate ( ) ;
554
+ // We want to ensure the worker is ready, as otherwise we'd always send the first event uncompressed
555
+ void this . flushImmediate ( true ) ;
545
556
}
546
557
547
558
return true ;
0 commit comments