@@ -66,6 +66,36 @@ interface McpLaunchOptions {
6666 logFile ?: fs . WriteStream ;
6767}
6868
69+ function resolveExecutablePath ( channel : Channel ) : string | undefined {
70+ if ( os . platform ( ) !== 'win32' ) {
71+ return undefined ;
72+ }
73+ const programFiles = process . env [ 'PROGRAMFILES' ] ;
74+ if ( ! programFiles ) {
75+ return undefined ;
76+ }
77+
78+ const channelPathPart =
79+ channel === 'canary'
80+ ? 'Chrome SxS'
81+ : channel === 'dev'
82+ ? 'Chrome Dev'
83+ : channel === 'beta'
84+ ? 'Chrome Beta'
85+ : '' ;
86+
87+ const chromePath = path . join (
88+ programFiles ,
89+ 'Google' ,
90+ 'Chrome' ,
91+ channelPathPart ,
92+ 'Application' ,
93+ 'chrome.exe' ,
94+ ) ;
95+
96+ return fs . existsSync ( chromePath ) ? chromePath : undefined ;
97+ }
98+
6999export async function launch ( options : McpLaunchOptions ) : Promise < Browser > {
70100 const { channel, executablePath, customDevTools, headless, isolated} = options ;
71101 const profileDirName =
@@ -85,13 +115,19 @@ export async function launch(options: McpLaunchOptions): Promise<Browser> {
85115 recursive : true ,
86116 } ) ;
87117 }
88-
89118 const args : LaunchOptions [ 'args' ] = [ '--hide-crash-restore-bubble' ] ;
90119 if ( customDevTools ) {
91120 args . push ( `--custom-devtools-frontend=file://${ customDevTools } ` ) ;
92121 }
122+
93123 let puppeterChannel : ChromeReleaseChannel | undefined ;
94- if ( ! executablePath ) {
124+ let resolvedExecutablePath = executablePath ;
125+
126+ if ( ! resolvedExecutablePath ) {
127+ resolvedExecutablePath = resolveExecutablePath ( channel as Channel ) ;
128+ }
129+
130+ if ( ! resolvedExecutablePath ) {
95131 puppeterChannel =
96132 channel && channel !== 'stable'
97133 ? ( `chrome-${ channel } ` as ChromeReleaseChannel )
@@ -102,7 +138,7 @@ export async function launch(options: McpLaunchOptions): Promise<Browser> {
102138 const browser = await puppeteer . launch ( {
103139 ...connectOptions ,
104140 channel : puppeterChannel ,
105- executablePath,
141+ executablePath : resolvedExecutablePath ,
106142 defaultViewport : null ,
107143 userDataDir,
108144 pipe : true ,
0 commit comments