MCPcopy
hub / github.com/garrytan/gstack / openBrowser

Function openBrowser

design/src/serve.ts:245–272  ·  view source on GitHub ↗

* Open a URL in the user's default browser. * Handles macOS (open), Linux (xdg-open), and headless environments.

(url: string)

Source from the content-addressed store, hash-verified

243 * Handles macOS (open), Linux (xdg-open), and headless environments.
244 */
245function openBrowser(url: string): void {
246 const platform = process.platform;
247 let cmd: string;
248
249 if (platform === "darwin") {
250 cmd = "open";
251 } else if (platform === "linux") {
252 cmd = "xdg-open";
253 } else {
254 // Windows or unknown — just print the URL
255 console.error(`SERVE_BROWSER_MANUAL: url=${url}`);
256 console.error(`Open this URL in your browser: ${url}`);
257 return;
258 }
259
260 try {
261 const child = spawn(cmd, [url], {
262 stdio: "ignore",
263 detached: true,
264 });
265 child.unref();
266 console.error(`SERVE_BROWSER_OPENED: url=${url}`);
267 } catch {
268 // open/xdg-open not available (headless CI environment)
269 console.error(`SERVE_BROWSER_MANUAL: url=${url}`);
270 console.error(`Open this URL in your browser: ${url}`);
271 }
272}

Callers 1

serveFunction · 0.70

Calls 1

spawnFunction · 0.85

Tested by

no test coverage detected