@@ -15,6 +15,7 @@ import {
1515 distroLabel ,
1616 parseLddMissingLibs ,
1717} from "./linuxDeps.js" ;
18+ import { closeManagedBrowser , launchManagedBrowser } from "./launch.js" ;
1819import { getFreeDiskMb } from "../telemetry/system.js" ;
1920import { runCancellableProcess } from "../utils/cancellableProcess.js" ;
2021import { normalizeErrorMessage } from "../utils/errorMessage.js" ;
@@ -255,6 +256,33 @@ function chromeLaunchFailureDetails(error: unknown): string {
255256 . join ( ", " ) ;
256257}
257258
259+ /**
260+ * chrome.exe is a GUI-subsystem binary: `--version` prints nothing and can exit non-zero (21)
261+ * on a Chrome that renders fine. On Windows ask the browser capture launches instead.
262+ */
263+ async function chromeVersionBanner ( executablePath : string , signal ?: AbortSignal ) : Promise < string > {
264+ if ( process . platform !== "win32" ) {
265+ const { stdout } = await runCancellableProcess ( executablePath , [ "--version" ] , {
266+ signal,
267+ timeoutMs : FIRST_LAUNCH_TIMEOUT_MS ,
268+ maxBufferBytes : 64 * 1024 ,
269+ } ) ;
270+ return stdout ;
271+ }
272+ const puppeteer = await import ( "puppeteer-core" ) ;
273+ const browser = await launchManagedBrowser ( puppeteer . default , {
274+ headless : true ,
275+ executablePath,
276+ timeout : FIRST_LAUNCH_TIMEOUT_MS ,
277+ signal,
278+ } ) ;
279+ try {
280+ return await browser . version ( ) ;
281+ } finally {
282+ await closeManagedBrowser ( browser ) ;
283+ }
284+ }
285+
258286async function chromeLaunchOutcome (
259287 executablePath : string ,
260288 found : EnvironmentCheckOutcome ,
@@ -263,12 +291,10 @@ async function chromeLaunchOutcome(
263291 const libraries = await chromeSharedLibOutcome ( executablePath , found , signal ) ;
264292 if ( ! libraries . ok ) return libraries ;
265293 try {
266- const { stdout } = await runCancellableProcess ( executablePath , [ "--version" ] , {
267- signal,
268- timeoutMs : FIRST_LAUNCH_TIMEOUT_MS ,
269- maxBufferBytes : 64 * 1024 ,
270- } ) ;
271- return { ...found , versionMajor : extractMajorVersion ( stdout ) } ;
294+ return {
295+ ...found ,
296+ versionMajor : extractMajorVersion ( await chromeVersionBanner ( executablePath , signal ) ) ,
297+ } ;
272298 } catch ( error ) {
273299 if ( signal ?. aborted ) signal . throwIfAborted ( ) ;
274300 const details = chromeLaunchFailureDetails ( error ) ;
@@ -277,7 +303,7 @@ async function chromeLaunchOutcome(
277303 ok : false ,
278304 level : "error" ,
279305 title : "Chrome cannot start" ,
280- detail : `Failed to run "${ executablePath } " --version ${ details ? ` (${ details } )` : "" } .` ,
306+ detail : `Failed to start "${ executablePath } "${ details ? ` (${ details } )` : "" } .` ,
281307 hint :
282308 "Select a working Chrome/Chromium binary for this OS and architecture with " +
283309 "HYPERFRAMES_BROWSER_PATH, or reinstall with: npx hyperframes browser ensure --force" ,
0 commit comments