Skip to content

Commit 00b6b32

Browse files
committed
fix(cli): handle browser open failures gracefully
1 parent 46bcec2 commit 00b6b32

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

packages/slidev/node/cli.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ cli.command(
143143
server: {
144144
port,
145145
strictPort: true,
146-
open,
147146
host,
148147
// @ts-expect-error Vite <= 4
149148
force,
@@ -206,10 +205,22 @@ cli.command(
206205
publicIp = await import('public-ip').then(r => r.publicIpv4())
207206

208207
lastRemoteUrl = printInfo(options, port, base, remote, tunnelUrl, publicIp)
208+
if (open)
209+
await openSlidevInBrowser()
209210

210211
return options
211212
}
212213

214+
async function openSlidevInBrowser() {
215+
const url = `http://localhost:${port}${base}`
216+
try {
217+
await openBrowser(url)
218+
}
219+
catch {
220+
console.log(yellow(`\n Could not open the browser automatically. Please open ${url} in your browser.\n`))
221+
}
222+
}
223+
213224
async function openTunnel(port: number) {
214225
const { startTunnel } = await import('untun')
215226
const tunnel = await startTunnel({
@@ -231,7 +242,7 @@ cli.command(
231242
name: 'o',
232243
fullname: 'open',
233244
action() {
234-
openBrowser(`http://localhost:${port}${base}`)
245+
openSlidevInBrowser()
235246
},
236247
},
237248
{

0 commit comments

Comments
 (0)