Home / Function/ startBrowserProcess() — vite Function Reference

startBrowserProcess() — vite Function Reference

Architecture documentation for the startBrowserProcess() function in openBrowser.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  f47cb7fa_50d3_70ae_0732_99509f08904e["startBrowserProcess()"]
  42b33c04_e36e_8276_32b6_47412295d0b2["openBrowser.ts"]
  f47cb7fa_50d3_70ae_0732_99509f08904e -->|defined in| 42b33c04_e36e_8276_32b6_47412295d0b2
  9e1e86ba_9f46_dbe1_a8b7_cee1ecb37905["openBrowser()"]
  9e1e86ba_9f46_dbe1_a8b7_cee1ecb37905 -->|calls| f47cb7fa_50d3_70ae_0732_99509f08904e
  282a71ff_1347_2907_2030_87242c1032c0["execAsync()"]
  f47cb7fa_50d3_70ae_0732_99509f08904e -->|calls| 282a71ff_1347_2907_2030_87242c1032c0
  style f47cb7fa_50d3_70ae_0732_99509f08904e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/server/openBrowser.ts lines 72–137

async function startBrowserProcess(
  browser: string | undefined,
  browserArgs: string[],
  url: string,
  logger: Logger,
) {
  // If we're on OS X, the user hasn't specifically
  // requested a different browser, we can try opening
  // a Chromium browser with JXA. This lets us reuse an
  // existing tab when possible instead of creating a new one.
  const preferredOSXBrowser =
    browser === 'google chrome' ? 'Google Chrome' : browser
  const shouldTryOpenChromeWithJXA =
    process.platform === 'darwin' &&
    (!preferredOSXBrowser ||
      supportedChromiumBrowsers.includes(preferredOSXBrowser))

  if (shouldTryOpenChromeWithJXA) {
    try {
      const ps = await execAsync('ps cax')
      const openedBrowser =
        preferredOSXBrowser && ps.includes(preferredOSXBrowser)
          ? preferredOSXBrowser
          : supportedChromiumBrowsers.find((b) => ps.includes(b))
      if (openedBrowser) {
        // Try our best to reuse existing tab with JXA
        await execAsync(`osascript openChrome.js "${url}" "${openedBrowser}"`, {
          cwd: join(VITE_PACKAGE_DIR, 'bin'),
        })
        return true
      }
    } catch {
      // Ignore errors
    }
  }

  // Another special case: on OS X, check if BROWSER has been set to "open".
  // In this case, instead of passing the string `open` to `open` function (which won't work),
  // just ignore it (thus ensuring the intended behavior, i.e. opening the system browser):
  // https://github.com/facebook/create-react-app/pull/1690#issuecomment-283518768
  if (process.platform === 'darwin' && browser === 'open') {
    browser = undefined
  }

  // Fallback to open
  // (It will always open new tab)
  try {
    const options: Options = browser
      ? { app: { name: browser, arguments: browserArgs } }
      : {}

    new Promise((_, reject) => {
      open(url, options)
        .then((subprocess) => {
          subprocess.on('error', reject)
        })
        .catch(reject)
    }).catch((err) => {
      logger.error(err.stack || err.message)
    })

    return true
  } catch {
    return false
  }
}

Domain

Subdomains

Calls

Called By

Frequently Asked Questions

What does startBrowserProcess() do?
startBrowserProcess() is a function in the vite codebase, defined in packages/vite/src/node/server/openBrowser.ts.
Where is startBrowserProcess() defined?
startBrowserProcess() is defined in packages/vite/src/node/server/openBrowser.ts at line 72.
What does startBrowserProcess() call?
startBrowserProcess() calls 1 function(s): execAsync.
What calls startBrowserProcess()?
startBrowserProcess() is called by 1 function(s): openBrowser.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free