@@ -202,8 +202,10 @@ export class Replayer {
202
202
203
203
/**
204
204
* Exposes mirror to the plugins
205
- * We ignore plugins here, as we don't have any
206
205
*/
206
+ for ( const plugin of this . config . plugins || [ ] ) {
207
+ if ( plugin . getMirror ) plugin . getMirror ( { nodeMirror : this . mirror } ) ;
208
+ }
207
209
208
210
this . emitter . on ( ReplayerEvents . Flush , ( ) => {
209
211
if ( this . usingVirtualDom ) {
@@ -234,7 +236,11 @@ export class Replayer {
234
236
else if ( data . source === IncrementalSource . StyleDeclaration )
235
237
this . applyStyleDeclaration ( data , styleSheet ) ;
236
238
} ,
237
- // we ignore plugins here, as we don't have any
239
+ afterAppend : ( node : Node , id : number ) => {
240
+ for ( const plugin of this . config . plugins || [ ] ) {
241
+ if ( plugin . onBuild ) plugin . onBuild ( node , { id, replayer : this } ) ;
242
+ }
243
+ } ,
238
244
} ;
239
245
if ( this . iframe . contentDocument )
240
246
try {
@@ -717,7 +723,9 @@ export class Replayer {
717
723
castFn ( ) ;
718
724
}
719
725
720
- // we ignore plugins here, as we don't have any
726
+ for ( const plugin of this . config . plugins || [ ] ) {
727
+ if ( plugin . handler ) plugin . handler ( event , isSync , { replayer : this } ) ;
728
+ }
721
729
722
730
this . service . send ( { type : 'CAST_EVENT' , payload : { event } } ) ;
723
731
@@ -770,7 +778,13 @@ export class Replayer {
770
778
const collected : AppendedIframe [ ] = [ ] ;
771
779
const afterAppend = ( builtNode : Node , id : number ) => {
772
780
this . collectIframeAndAttachDocument ( collected , builtNode ) ;
773
- // we ignore plugins here, as we don't have any
781
+ for ( const plugin of this . config . plugins || [ ] ) {
782
+ if ( plugin . onBuild )
783
+ plugin . onBuild ( builtNode , {
784
+ id,
785
+ replayer : this ,
786
+ } ) ;
787
+ }
774
788
} ;
775
789
776
790
/**
@@ -863,7 +877,7 @@ export class Replayer {
863
877
type TMirror = typeof mirror extends Mirror ? Mirror : RRDOMMirror ;
864
878
865
879
const collected : AppendedIframe [ ] = [ ] ;
866
- const afterAppend = ( builtNode : Node , _id : number ) => {
880
+ const afterAppend = ( builtNode : Node , id : number ) => {
867
881
this . collectIframeAndAttachDocument ( collected , builtNode ) ;
868
882
const sn = ( mirror as TMirror ) . getMeta ( builtNode as unknown as TNode ) ;
869
883
if (
@@ -878,7 +892,14 @@ export class Replayer {
878
892
}
879
893
880
894
// Skip the plugin onBuild callback in the virtual dom mode
881
- // we ignore plugins here, as we don't have any
895
+ if ( this . usingVirtualDom ) return ;
896
+ for ( const plugin of this . config . plugins || [ ] ) {
897
+ if ( plugin . onBuild )
898
+ plugin . onBuild ( builtNode , {
899
+ id,
900
+ replayer : this ,
901
+ } ) ;
902
+ }
882
903
} ;
883
904
884
905
buildNodeWithSN ( mutation . node , {
@@ -1498,7 +1519,13 @@ export class Replayer {
1498
1519
) ;
1499
1520
return ;
1500
1521
}
1501
- // we ignore plugins here, as we don't have any
1522
+ const afterAppend = ( node : Node | RRNode , id : number ) => {
1523
+ // Skip the plugin onBuild callback for virtual dom
1524
+ if ( this . usingVirtualDom ) return ;
1525
+ for ( const plugin of this . config . plugins || [ ] ) {
1526
+ if ( plugin . onBuild ) plugin . onBuild ( node , { id, replayer : this } ) ;
1527
+ }
1528
+ } ;
1502
1529
1503
1530
const target = buildNodeWithSN ( mutation . node , {
1504
1531
doc : targetDoc as Document , // can be Document or RRDocument
@@ -1510,6 +1537,7 @@ export class Replayer {
1510
1537
* caveat: `afterAppend` only gets called on child nodes of target
1511
1538
* we have to call it again below when this target was added to the DOM
1512
1539
*/
1540
+ afterAppend,
1513
1541
} ) as Node | RRNode ;
1514
1542
1515
1543
// legacy data, we should not have -1 siblings any more
@@ -1584,7 +1612,10 @@ export class Replayer {
1584
1612
} else {
1585
1613
( parent as TNode ) . appendChild ( target as TNode ) ;
1586
1614
}
1587
- // we ignore plugins here, as we don't have any
1615
+ /**
1616
+ * target was added, execute plugin hooks
1617
+ */
1618
+ afterAppend ( target , mutation . node . id ) ;
1588
1619
1589
1620
/**
1590
1621
* https://github.com/rrweb-io/rrweb/pull/887
0 commit comments