@@ -41,6 +41,8 @@ export class AIOBrowser {
4141 */
4242 private logger : Logger ;
4343
44+ private launchOptions ?: LaunchOptions ;
45+
4446 /**
4547 * Creates an instance of AIOBrowser
4648 * @param {AIOBrowserOptions } options - Configuration options
@@ -64,6 +66,7 @@ export class AIOBrowser {
6466 try {
6567 await this . browser . launch ( options ) ;
6668 this . logger . success ( 'Browser launched successfully' ) ;
69+ this . launchOptions = options ;
6770 } catch ( error ) {
6871 this . logger . error ( 'Failed to launch browser:' , error ) ;
6972 throw error ;
@@ -148,6 +151,7 @@ export class AIOBrowser {
148151 async getActivePage ( ) : Promise < Page > {
149152 this . logger . info ( 'Getting active page' ) ;
150153 const pages = await this . browser . getBrowser ( ) . pages ( ) ;
154+ this . logger . info ( `getActivePage pages length: ${ pages . length } ` ) ;
151155 try {
152156 // First try to find a visible page without waiting
153157 for ( const page of pages ) {
@@ -192,10 +196,14 @@ export class AIOBrowser {
192196 continue ;
193197 }
194198 }
195- this . logger . success ( 'Active original page retrieved successfully ' ) ;
199+ this . logger . success ( 'Active original page retrieved failed, fallback to active page ' ) ;
196200 return this . browser . getActivePage ( ) ;
197201 } catch ( error ) {
198202 this . logger . error ( 'Failed to get active page:' , error ) ;
203+ if ( ( error as Error ) . message . includes ( 'Protocol error: Connection closed' ) ) {
204+ this . logger . error ( 'Connection closed, reconnecting...' ) ;
205+ this . browser . launch ( this . launchOptions ) ;
206+ }
199207 throw error ;
200208 }
201209 }
0 commit comments