22
33import { existsSync } from "node:fs" ;
44import { createHash } from "node:crypto" ;
5+ import { win32 as pathWin32 } from "node:path" ;
56import {
67 createStudioDevRenderBodyScripts ,
78 readStudioDevManualEditManifestContent ,
@@ -14,20 +15,34 @@ import { seekThumbnailPreview } from "./vite.thumbnail";
1415let _browser : import ( "puppeteer-core" ) . Browser | null = null ;
1516let _browserLaunchPromise : Promise < import ( "puppeteer-core" ) . Browser > | null = null ;
1617
17- const CHROME_PATHS = [
18- "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" ,
19- "/usr/bin/google-chrome" ,
20- "/usr/bin/chromium-browser" ,
21- ] ;
18+ function systemChromePaths ( env : NodeJS . ProcessEnv , platform : NodeJS . Platform ) : string [ ] {
19+ if ( platform === "win32" ) {
20+ const programFiles = env [ "PROGRAMFILES" ] ?? "C:\\Program Files" ;
21+ const programFilesX86 = env [ "PROGRAMFILES(X86)" ] ?? "C:\\Program Files (x86)" ;
22+ const localAppData = env [ "LOCALAPPDATA" ] ;
23+ return [
24+ pathWin32 . join ( programFiles , "Google" , "Chrome" , "Application" , "chrome.exe" ) ,
25+ pathWin32 . join ( programFilesX86 , "Google" , "Chrome" , "Application" , "chrome.exe" ) ,
26+ ...( localAppData
27+ ? [ pathWin32 . join ( localAppData , "Google" , "Chrome" , "Application" , "chrome.exe" ) ]
28+ : [ ] ) ,
29+ ] ;
30+ }
31+ if ( platform === "darwin" ) {
32+ return [ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" ] ;
33+ }
34+ return [ "/usr/bin/google-chrome" , "/usr/bin/chromium-browser" ] ;
35+ }
2236
2337/** Resolve the same explicit browser overrides used by the CLI before system paths. */
2438export function findSystemChrome (
2539 env : NodeJS . ProcessEnv = process . env ,
2640 pathExists : ( path : string ) => boolean = existsSync ,
41+ platform : NodeJS . Platform = process . platform ,
2742) : string | undefined {
2843 const override = env [ "HYPERFRAMES_BROWSER_PATH" ] ?? env [ "PRODUCER_HEADLESS_SHELL_PATH" ] ;
2944 if ( override && pathExists ( override ) ) return override ;
30- return CHROME_PATHS . find ( ( path ) => pathExists ( path ) ) ;
45+ return systemChromePaths ( env , platform ) . find ( ( path ) => pathExists ( path ) ) ;
3146}
3247
3348async function getSharedBrowser ( ) : Promise < import ( "puppeteer-core" ) . Browser | null > {
0 commit comments