MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / browserOpenCommand

Function browserOpenCommand

src/ui-server/open-browser.ts:27–53  ·  view source on GitHub ↗
(
  url: string,
  platform: NodeJS.Platform,
  override?: string
)

Source from the content-addressed store, hash-verified

25 * without launching anything.
26 */
27export function browserOpenCommand(
28 url: string,
29 platform: NodeJS.Platform,
30 override?: string
31): OpenCommand | null {
32 if (override !== undefined) {
33 const trimmed = override.trim();
34 if (SUPPRESS_VALUES.has(trimmed.toLowerCase())) return null;
35 // Windows: go through `cmd /c` rather than spawning the override directly.
36 // `spawn` there is CreateProcess, which only ever launches a real .exe — a
37 // `.cmd`/`.bat` browser shim (how most Windows wrappers are written) fails
38 // outright, and an extension-less name only resolves because CreateProcess
39 // appends `.exe`. Routing through cmd makes .exe, .cmd and .bat all work,
40 // and node quotes each argument, so a path with spaces survives. Caught on
41 // the Windows VM, where the direct spawn silently launched nothing.
42 if (platform === 'win32') return { command: 'cmd', args: ['/c', trimmed, url] };
43 return { command: trimmed, args: [url] };
44 }
45 if (platform === 'darwin') return { command: 'open', args: [url] };
46 if (platform === 'win32') {
47 // `start` is a cmd builtin, not an executable. The empty string is the
48 // window title — without it `start` treats a quoted URL as the title and
49 // opens a blank console instead.
50 return { command: 'cmd', args: ['/c', 'start', '', url] };
51 }
52 return { command: 'xdg-open', args: [url] };
53}
54
55/**
56 * Open `url` in the user's default browser, best effort.

Callers 2

ui-server.test.tsFile · 0.90
openBrowserFunction · 0.85

Calls 1

hasMethod · 0.80

Tested by

no test coverage detected