MCPcopy
hub / github.com/vitejs/vite / openBrowser

Function openBrowser

packages/vite/src/node/server/openBrowser.ts:24–40  ·  view source on GitHub ↗
(
  url: string,
  opt: string | true,
  logger: Logger,
)

Source from the content-addressed store, hash-verified

22 * Reads the BROWSER environment variable and decides what to do with it.
23 */
24export function openBrowser(
25 url: string,
26 opt: string | true,
27 logger: Logger,
28): void {
29 // The browser executable to open.
30 // See https://github.com/sindresorhus/open#app for documentation.
31 const browser = typeof opt === 'string' ? opt : process.env.BROWSER || ''
32 if (browser.toLowerCase().endsWith('.js')) {
33 executeNodeScript(browser, url, logger)
34 } else if (browser.toLowerCase() !== 'none') {
35 const browserArgs = process.env.BROWSER_ARGS
36 ? process.env.BROWSER_ARGS.split(' ')
37 : []
38 startBrowserProcess(browser, browserArgs, url, logger)
39 }
40}
41
42function executeNodeScript(scriptPath: string, url: string, logger: Logger) {
43 const extraArgs = process.argv.slice(2)

Callers 2

actionFunction · 0.90
previewFunction · 0.90

Calls 2

executeNodeScriptFunction · 0.85
startBrowserProcessFunction · 0.85

Tested by

no test coverage detected