MCPcopy Index your code
hub / github.com/codeaashu/claude-code / detectAvailableBrowser

Function detectAvailableBrowser

src/utils/claudeInChrome/common.ts:345–409  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

343 * Returns the first available browser, or null if none found
344 */
345export async function detectAvailableBrowser(): Promise<ChromiumBrowser | null> {
346 const platform = getPlatform()
347
348 for (const browserId of BROWSER_DETECTION_ORDER) {
349 const config = CHROMIUM_BROWSERS[browserId]
350
351 switch (platform) {
352 case 'macos': {
353 // Check if the .app bundle (a directory) exists
354 const appPath = `/Applications/${config.macos.appName}.app`
355 try {
356 const stats = await stat(appPath)
357 if (stats.isDirectory()) {
358 logForDebugging(
359 `[Claude in Chrome] Detected browser: ${config.name}`,
360 )
361 return browserId
362 }
363 } catch (e) {
364 if (!isFsInaccessible(e)) throw e
365 // App not found, continue checking
366 }
367 break
368 }
369 case 'wsl':
370 case 'linux': {
371 // Check if any binary exists
372 for (const binary of config.linux.binaries) {
373 if (await which(binary).catch(() => null)) {
374 logForDebugging(
375 `[Claude in Chrome] Detected browser: ${config.name}`,
376 )
377 return browserId
378 }
379 }
380 break
381 }
382 case 'windows': {
383 // Check if data path exists (indicates browser is installed)
384 const home = homedir()
385 if (config.windows.dataPath.length > 0) {
386 const appDataBase = config.windows.useRoaming
387 ? join(home, 'AppData', 'Roaming')
388 : join(home, 'AppData', 'Local')
389 const dataPath = join(appDataBase, ...config.windows.dataPath)
390 try {
391 const stats = await stat(dataPath)
392 if (stats.isDirectory()) {
393 logForDebugging(
394 `[Claude in Chrome] Detected browser: ${config.name}`,
395 )
396 return browserId
397 }
398 } catch (e) {
399 if (!isFsInaccessible(e)) throw e
400 // Browser not found, continue checking
401 }
402 }

Callers 1

openInChromeFunction · 0.85

Calls 4

getPlatformFunction · 0.85
statFunction · 0.85
logForDebuggingFunction · 0.85
isFsInaccessibleFunction · 0.85

Tested by

no test coverage detected