@@ -147,6 +147,7 @@ async function probeHardwareWebGlInfo(
147147 ? options . probeLifecycle . launch ( ppt , launchOptions )
148148 : ppt . launch ( launchOptions ) ;
149149 } ) ;
150+ absorbBrowserPipeErrors ( probeBrowser ) ;
150151 const browser = probeBrowser ;
151152 return await rejectAfter (
152153 readWebGlInfo ( browser ) . then ( async ( info ) => ( {
@@ -985,18 +986,25 @@ async function launchBrowser(
985986 protocolTimeout : fingerprint . protocolTimeoutMs ,
986987 signal,
987988 } ) ;
988- } ) . catch ( async ( error : unknown ) => {
989- throwIfAborted ( ) ;
990- const remediation =
991- process . platform === "darwin" &&
992- sandboxDeniedRemediation ( error instanceof Error ? error . message : "" ) ;
993- if ( remediation ) throw new Error ( remediation , { cause : error } ) ;
994- const defaults = await ppt . defaultArgs ( {
995- headless : true ,
996- args : withHyperframesBrowserMarker ( attempted ) ,
989+ } )
990+ . then ( ( launched ) => {
991+ absorbBrowserPipeErrors ( launched ) ;
992+ return launched ;
993+ } )
994+ . catch ( async ( error : unknown ) => {
995+ throwIfAborted ( ) ;
996+ const remediation =
997+ process . platform === "darwin" &&
998+ sandboxDeniedRemediation ( error instanceof Error ? error . message : "" ) ;
999+ if ( remediation ) throw new Error ( remediation , { cause : error } ) ;
1000+ const defaults = await ppt . defaultArgs ( {
1001+ headless : true ,
1002+ args : withHyperframesBrowserMarker ( attempted ) ,
1003+ } ) ;
1004+ throw await explainChromeLaunchFailure ( error , fingerprint . executablePath , defaults , {
1005+ env,
1006+ } ) ;
9971007 } ) ;
998- throw await explainChromeLaunchFailure ( error , fingerprint . executablePath , defaults , { env } ) ;
999- } ) ;
10001008 } ;
10011009 const probe = ( target : Browser , timeoutMs ?: number ) =>
10021010 probeBeginFrameSupport ( target , timeoutMs ) . catch ( ( error ) => ( {
@@ -1055,17 +1063,34 @@ async function launchBrowser(
10551063 }
10561064}
10571065
1066+ const guardedBrowserPipes = new WeakSet < NodeJS . EventEmitter > ( ) ;
1067+
1068+ // Puppeteer's PipeTransport.close() drops its pipe error listener; absorb late EPIPE/ECONNRESET on dying browsers.
1069+ export function absorbBrowserPipeErrors ( browser : Browser ) : void {
1070+ const proc = (
1071+ browser as unknown as {
1072+ process ?: ( ) => {
1073+ stdio ?: ReadonlyArray < NodeJS . EventEmitter | null | undefined > ;
1074+ } | null ;
1075+ }
1076+ ) . process ?.( ) ;
1077+ for ( const stream of proc ?. stdio ?? [ ] ) {
1078+ if ( ! stream || guardedBrowserPipes . has ( stream ) ) continue ;
1079+ guardedBrowserPipes . add ( stream ) ;
1080+ stream . on ( "error" , ( ) => { } ) ;
1081+ }
1082+ }
1083+
10581084function forceCloseBrowserProcess ( browser : Browser ) : void {
1085+ absorbBrowserPipeErrors ( browser ) ;
10591086 const proc = (
10601087 browser as unknown as {
10611088 process ?: ( ) => {
10621089 kill : ( signal ?: NodeJS . Signals ) => boolean ;
10631090 killed ?: boolean ;
1064- stdio ?: ReadonlyArray < NodeJS . EventEmitter | null | undefined > ;
10651091 } | null ;
10661092 }
10671093 ) . process ?.( ) ;
1068- for ( const stream of proc ?. stdio ?? [ ] ) stream ?. on ( "error" , ( ) => { } ) ;
10691094 if ( proc && ! proc . killed ) {
10701095 try {
10711096 proc . kill ( "SIGKILL" ) ;
0 commit comments