@@ -47,6 +47,13 @@ import type * as api from '../../types/types';
4747import type { URLMatch } from '../utils/isomorphic/urlMatch' ;
4848import type { Platform } from './platform' ;
4949import type * as channels from '@protocol/channels' ;
50+ import type * as actions from '@recorder/actions' ;
51+
52+ interface RecorderEventSink {
53+ actionAdded ( page : Page , actionInContext : actions . ActionInContext ) : void ;
54+ actionUpdated ( page : Page , actionInContext : actions . ActionInContext ) : void ;
55+ signalAdded ( page : Page , signal : actions . SignalInContext ) : void ;
56+ }
5057
5158export class BrowserContext extends ChannelOwner < channels . BrowserContextChannel > implements api . BrowserContext {
5259 _pages = new Set < Page > ( ) ;
@@ -71,7 +78,7 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
7178 _closingStatus : 'none' | 'closing' | 'closed' = 'none' ;
7279 private _closeReason : string | undefined ;
7380 private _harRouters : HarRouter [ ] = [ ] ;
74- private _onRecorderEventSink : ( ( event : string , data : any ) => void ) | undefined ;
81+ private _onRecorderEventSink : RecorderEventSink | undefined ;
7582
7683 static from ( context : channels . BrowserContextChannel ) : BrowserContext {
7784 return ( context as any ) . _object ;
@@ -141,7 +148,14 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
141148 this . _channel . on ( 'requestFailed' , ( { request, failureText, responseEndTiming, page } ) => this . _onRequestFailed ( network . Request . from ( request ) , responseEndTiming , failureText , Page . fromNullable ( page ) ) ) ;
142149 this . _channel . on ( 'requestFinished' , params => this . _onRequestFinished ( params ) ) ;
143150 this . _channel . on ( 'response' , ( { response, page } ) => this . _onResponse ( network . Response . from ( response ) , Page . fromNullable ( page ) ) ) ;
144- this . _channel . on ( 'recorderEvent' , ( { event, data } ) => this . _onRecorderEventSink ?.( event , data ) ) ;
151+ this . _channel . on ( 'recorderEvent' , ( { event, data, page } ) => {
152+ if ( event === 'actionAdded' )
153+ this . _onRecorderEventSink ?. actionAdded ( Page . from ( page ) , data as actions . ActionInContext ) ;
154+ else if ( event === 'actionUpdated' )
155+ this . _onRecorderEventSink ?. actionUpdated ( Page . from ( page ) , data as actions . ActionInContext ) ;
156+ else if ( event === 'signalAdded' )
157+ this . _onRecorderEventSink ?. signalAdded ( Page . from ( page ) , data as actions . SignalInContext ) ;
158+ } ) ;
145159 this . _closedPromise = new Promise ( f => this . once ( Events . BrowserContext . Close , f ) ) ;
146160
147161 this . _setEventToSubscriptionMapping ( new Map < string , channels . BrowserContextUpdateSubscriptionParams [ 'event' ] > ( [
@@ -501,9 +515,9 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
501515 await this . _closedPromise ;
502516 }
503517
504- async _enableRecorder ( params : channels . BrowserContextEnableRecorderParams , callback ?: ( event : string , data : any ) => void ) {
505- if ( callback )
506- this . _onRecorderEventSink = callback ;
518+ async _enableRecorder ( params : channels . BrowserContextEnableRecorderParams , eventSink ?: RecorderEventSink ) {
519+ if ( eventSink )
520+ this . _onRecorderEventSink = eventSink ;
507521 await this . _channel . enableRecorder ( params ) ;
508522 }
509523
0 commit comments