Skip to content

Commit e60075c

Browse files
committed
fix: add count max for auto open devtool
1 parent 250d9fc commit e60075c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/network-debugger/src/fork/devtool.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,30 @@ export class DevtoolServer {
103103
wait: true
104104
})
105105

106-
if (process.platform !== 'darwin') {
106+
cdpConnect: if (process.platform !== 'darwin') {
107107
const json = await new Promise<{ webSocketDebuggerUrl: string; id: string }[]>(
108108
(resolve) => {
109+
let count = 0
109110
let stop = setInterval(async () => {
111+
if (count > 5) {
112+
clearInterval(stop)
113+
resolve([])
114+
}
110115
try {
116+
count++
111117
resolve((await fetch(`http://localhost:${REMOTE_DEBUGGER_PORT}/json`)).json())
112118
clearInterval(stop)
113119
} catch {
114-
log('waiting for chrome to open')
120+
// ignore
115121
}
116122
}, 500)
117123
}
118124
)
119-
const { id, webSocketDebuggerUrl } = json[0]
125+
const [data] = json
126+
if (!data) {
127+
break cdpConnect
128+
}
129+
const { id, webSocketDebuggerUrl } = data
120130
const debuggerWs = new WebSocket(webSocketDebuggerUrl)
121131

122132
debuggerWs.on('open', () => {

0 commit comments

Comments
 (0)