@@ -33,6 +33,7 @@ import type { Playwright } from './playwright';
3333import type { ElementInfo , Mode } from '@recorder/recorderTypes' ;
3434import type { Progress } from '@protocol/progress' ;
3535import type * as actions from '@recorder/actions' ;
36+ import type { Page } from './page' ;
3637
3738export class DebugController extends SdkObject {
3839 static Events = {
@@ -44,7 +45,7 @@ export class DebugController extends SdkObject {
4445 } ;
4546
4647 private _reportState = false ;
47- private _disposeListeners : ( ( ) => void ) [ ] = [ ] ;
48+ private _disposeListeners = new Set < ( ) => void > ( ) ;
4849 private _playwright : Playwright ;
4950 _sdkLanguage : Language = 'javascript' ;
5051
@@ -71,17 +72,19 @@ export class DebugController extends SdkObject {
7172 this . _emitSnapshot ( false ) ;
7273 const handleNavigation = ( ) => this . _emitSnapshot ( false ) ;
7374 page . mainFrame ( ) . on ( Frame . Events . InternalNavigation , handleNavigation ) ;
74- this . _disposeListeners . push ( ( ) => page . mainFrame ( ) . off ( Frame . Events . InternalNavigation , handleNavigation ) ) ;
75+ const dispose = ( ) => page . mainFrame ( ) . off ( Frame . Events . InternalNavigation , handleNavigation ) ;
76+ this . _disposeListeners . add ( dispose ) ;
77+ page . on ( Page . Events . Close , ( ) => this . _disposeListeners . delete ( dispose ) ) ;
7578 } ,
7679 onPageClose : ( ) => this . _emitSnapshot ( false ) ,
7780 } ;
7881 this . _playwright . instrumentation . addListener ( listener , null ) ;
79- this . _disposeListeners . push ( ( ) => this . _playwright . instrumentation . removeListener ( listener ) ) ;
82+ this . _disposeListeners . add ( ( ) => this . _playwright . instrumentation . removeListener ( listener ) ) ;
8083 this . _emitSnapshot ( true ) ;
8184 } else {
8285 for ( const dispose of this . _disposeListeners )
8386 dispose ( ) ;
84- this . _disposeListeners = [ ] ;
87+ this . _disposeListeners . clear ( ) ;
8588 }
8689 }
8790
0 commit comments