@@ -1389,29 +1389,7 @@ class Playwright extends Helper {
13891389 }
13901390 }
13911391
1392- // Close all contexts and pages before closing browser to prevent hanging
1393- if ( this . browser ) {
1394- try {
1395- const contexts = await Promise . race ( [
1396- this . browser . contexts ( ) ,
1397- new Promise ( ( _ , reject ) => setTimeout ( ( ) => reject ( new Error ( 'Get contexts timeout' ) ) , 1000 ) )
1398- ] )
1399- // Close all pages in all contexts first
1400- await Promise . allSettled ( contexts . map ( async ( ctx ) => {
1401- try {
1402- const pages = await ctx . pages ( )
1403- await Promise . allSettled ( pages . map ( p => p . close ( ) . catch ( ( ) => { } ) ) )
1404- } catch ( e ) {
1405- // Ignore errors getting or closing pages
1406- }
1407- } ) )
1408- // Then close all contexts
1409- await Promise . allSettled ( contexts . map ( c => c . close ( ) . catch ( ( ) => { } ) ) )
1410- } catch ( e ) {
1411- // Ignore errors if browser is already closed or timeout getting contexts
1412- }
1413- }
1414-
1392+ // Close browserContext if recordHar is enabled
14151393 if ( this . options . recordHar && this . browserContext ) {
14161394 try {
14171395 await this . browserContext . close ( )
@@ -1421,16 +1399,16 @@ class Playwright extends Helper {
14211399 }
14221400 this . browserContext = null
14231401
1402+ // Initiate browser close without waiting for it to complete
1403+ // The browser process will be cleaned up when the Node process exits
14241404 if ( this . browser ) {
14251405 try {
1426- // Add timeout to prevent browser.close() from hanging indefinitely
1427- await Promise . race ( [ this . browser . close ( ) , new Promise ( ( _ , reject ) => setTimeout ( ( ) => reject ( new Error ( 'Browser close timeout' ) ) , 5000 ) ) ] )
1406+ // Fire and forget - don't wait for close to complete
1407+ this . browser . close ( ) . catch ( ( ) => {
1408+ // Silently ignore any errors during async close
1409+ } )
14281410 } catch ( e ) {
1429- // Ignore errors if browser is already closed or timeout
1430- if ( ! e . message ?. includes ( 'Browser close timeout' ) ) {
1431- // Non-timeout error, can be ignored as well
1432- }
1433- // Force cleanup even on error
1411+ // Ignore any synchronous errors
14341412 }
14351413 }
14361414 this . browser = null
0 commit comments