@@ -15,7 +15,6 @@ import {
1515 distroLabel ,
1616 parseLddMissingLibs ,
1717} from "./linuxDeps.js" ;
18- import { closeManagedBrowser , launchManagedBrowser } from "./launch.js" ;
1918import { getFreeDiskMb } from "../telemetry/system.js" ;
2019import { runCancellableProcess } from "../utils/cancellableProcess.js" ;
2120import { normalizeErrorMessage } from "../utils/errorMessage.js" ;
@@ -256,27 +255,31 @@ function chromeLaunchFailureDetails(error: unknown): string {
256255 . join ( ", " ) ;
257256}
258257
259- // Windows chrome.exe prints nothing for --version and can exit 21 while rendering fine: launch it as capture does.
260- async function chromeVersionBanner ( executablePath : string , signal ?: AbortSignal ) : Promise < string > {
261- if ( process . platform !== "win32" ) {
262- const { stdout } = await runCancellableProcess ( executablePath , [ "--version" ] , {
263- signal,
264- timeoutMs : FIRST_LAUNCH_TIMEOUT_MS ,
265- maxBufferBytes : 64 * 1024 ,
266- } ) ;
267- return stdout ;
268- }
269- const puppeteer = await import ( "puppeteer-core" ) ;
270- const browser = await launchManagedBrowser ( puppeteer . default , {
271- headless : true ,
272- executablePath,
273- timeout : FIRST_LAUNCH_TIMEOUT_MS ,
274- signal,
275- } ) ;
258+ // Windows chrome.exe prints nothing for --version and can exit 21 while rendering fine: read the file's version.
259+ async function windowsChromeVersionMajor (
260+ executablePath : string ,
261+ signal ?: AbortSignal ,
262+ ) : Promise < number | undefined > {
276263 try {
277- return await browser . version ( ) ;
278- } finally {
279- await closeManagedBrowser ( browser ) ;
264+ const { stdout } = await runCancellableProcess (
265+ "powershell.exe" ,
266+ [
267+ "-NoProfile" ,
268+ "-NonInteractive" ,
269+ "-Command" ,
270+ "(Get-Item -LiteralPath $env:HF_CHROME).VersionInfo.ProductVersion" ,
271+ ] ,
272+ {
273+ signal,
274+ timeoutMs : 10_000 ,
275+ maxBufferBytes : 4 * 1024 ,
276+ env : { ...process . env , HF_CHROME : executablePath } ,
277+ } ,
278+ ) ;
279+ return extractMajorVersion ( stdout ) ;
280+ } catch {
281+ if ( signal ?. aborted ) signal . throwIfAborted ( ) ;
282+ return undefined ;
280283 }
281284}
282285
@@ -287,11 +290,16 @@ async function chromeLaunchOutcome(
287290) : Promise < EnvironmentCheckOutcome > {
288291 const libraries = await chromeSharedLibOutcome ( executablePath , found , signal ) ;
289292 if ( ! libraries . ok ) return libraries ;
293+ if ( process . platform === "win32" ) {
294+ return { ...found , versionMajor : await windowsChromeVersionMajor ( executablePath , signal ) } ;
295+ }
290296 try {
291- return {
292- ...found ,
293- versionMajor : extractMajorVersion ( await chromeVersionBanner ( executablePath , signal ) ) ,
294- } ;
297+ const { stdout } = await runCancellableProcess ( executablePath , [ "--version" ] , {
298+ signal,
299+ timeoutMs : FIRST_LAUNCH_TIMEOUT_MS ,
300+ maxBufferBytes : 64 * 1024 ,
301+ } ) ;
302+ return { ...found , versionMajor : extractMajorVersion ( stdout ) } ;
295303 } catch ( error ) {
296304 if ( signal ?. aborted ) signal . throwIfAborted ( ) ;
297305 const details = chromeLaunchFailureDetails ( error ) ;
@@ -300,7 +308,7 @@ async function chromeLaunchOutcome(
300308 ok : false ,
301309 level : "error" ,
302310 title : "Chrome cannot start" ,
303- detail : `Failed to start "${ executablePath } "${ details ? ` (${ details } )` : "" } .` ,
311+ detail : `Failed to run "${ executablePath } " --version ${ details ? ` (${ details } )` : "" } .` ,
304312 hint :
305313 "Select a working Chrome/Chromium binary for this OS and architecture with " +
306314 "HYPERFRAMES_BROWSER_PATH, or reinstall with: npx hyperframes browser ensure --force" ,
0 commit comments