@@ -18,7 +18,7 @@ import { EventEmitter } from 'events';
1818
1919import { eventsHelper } from '../utils/eventsHelper' ;
2020import { ValidationError , createMetadataValidator , findValidator } from '../../protocol/validator' ;
21- import { assert , monotonicTime , rewriteErrorMessage } from '../../utils' ;
21+ import { assert , monotonicTime , rewriteErrorMessage , debugLogger } from '../../utils' ;
2222import { isUnderTest } from '../utils/debug' ;
2323import { TargetClosedError , isTargetClosedError , serializeError } from '../errors' ;
2424import { createRootSdkObject , SdkObject } from '../instrumentation' ;
@@ -101,7 +101,11 @@ export class Dispatcher<Type extends SdkObject, ChannelType, ParentScopeType ext
101101 }
102102
103103 async _runCommand ( callMetadata : CallMetadata , method : string , validParams : any ) {
104- const controller = new ProgressController ( callMetadata , this . _object ) ;
104+ const controller = new ProgressController ( callMetadata , message => {
105+ const logName = this . _object . logName || 'api' ;
106+ debugLogger . log ( logName , message ) ;
107+ this . _object . instrumentation . onCallLog ( this . _object , callMetadata , logName , message ) ;
108+ } ) ;
105109 this . _activeProgressControllers . add ( controller ) ;
106110 try {
107111 return await controller . run ( progress => ( this as any ) [ method ] ( validParams , progress ) , validParams ?. timeout ) ;
@@ -318,7 +322,8 @@ export class DispatcherConnection {
318322 return ;
319323 }
320324
321- if ( methodMetainfo . get ( dispatcher . _type + '.' + method ) ?. internal ) {
325+ const metainfo = methodMetainfo . get ( dispatcher . _type + '.' + method ) ;
326+ if ( metainfo ?. internal ) {
322327 // For non-js ports, it is easier to detect internal calls here rather
323328 // than generate protocol metainfo for each language.
324329 validMetadata . internal = true ;
@@ -396,12 +401,20 @@ export class DispatcherConnection {
396401 } finally {
397402 callMetadata . endTime = monotonicTime ( ) ;
398403 await sdkObject . instrumentation . onAfterCall ( sdkObject , callMetadata ) ;
404+ if ( metainfo ?. slowMo )
405+ await this . _doSlowMo ( sdkObject ) ;
399406 }
400407
401408 if ( response . error )
402409 response . log = compressCallLog ( callMetadata . log ) ;
403410 this . onmessage ( response ) ;
404411 }
412+
413+ private async _doSlowMo ( sdkObject : SdkObject ) : Promise < void > {
414+ const slowMo = sdkObject . attribution . browser ?. options . slowMo ;
415+ if ( slowMo )
416+ await new Promise ( f => setTimeout ( f , slowMo ) ) ;
417+ }
405418}
406419
407420function closeReason ( sdkObject : SdkObject ) : string | undefined {
0 commit comments