Skip to content

Commit 59e86cf

Browse files
committed
chore: adress code review comments
1 parent a62db0b commit 59e86cf

2 files changed

Lines changed: 36 additions & 18 deletions

File tree

src/helpers/APIHelper.ts

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,55 +158,72 @@ POST /api/execute/:windowId body: {"jsCode": "" }<br>
158158
`
159159
})
160160

161-
162161
router.get('/debug/remote-debug', async (ctx) => {
163-
164162
// Expose a simple page that lists the open remote debugging targets and link to them
165163

166-
let remoteDebuggingPort: string | undefined = undefined
164+
let remoteDebuggingPort: number | undefined = undefined
167165
for (const arg of process.argv) {
168166
if (arg.startsWith('--remote-debugging-port=')) {
169167
const words = arg.split('=')
170168
if (words.length === 2) {
171-
remoteDebuggingPort = words[1]
169+
remoteDebuggingPort = parseInt(words[1], 10)
172170
break
173171
}
174172
}
175173
}
176-
if (!remoteDebuggingPort) {
174+
if (!remoteDebuggingPort || isNaN(remoteDebuggingPort)) {
177175
ctx.response.status = 500
178-
ctx.body = 'Remote debugging not enabled. To enable, start Chef with --remote-debugging-port=PORT'
176+
ctx.body =
177+
'Remote debugging not enabled. To enable, start Chef with CLI arguments: --remote-debugging-port=PORT --remote-allow-origins=*'
179178
return
180179
}
181180
try {
181+
const abortController = new AbortController()
182+
const timeout = setTimeout(() => abortController.abort(), 3000)
182183

183-
const list: {
184-
description: string,
185-
devtoolsFrontendUrl: string,
186-
id: string,
187-
title: string,
188-
type: string,
189-
url: string,
184+
try {
185+
const list: {
186+
description: string
187+
devtoolsFrontendUrl: string
188+
id: string
189+
title: string
190+
type: string
191+
url: string
190192
webSocketDebuggerUrl: string
191-
}[] = (await (await fetch(`http://localhost:${remoteDebuggingPort}/json/list`)).json()) as any
193+
}[] = (await (
194+
await fetch(`http://localhost:${remoteDebuggingPort}/json/list`, {
195+
signal: abortController.signal,
196+
})
197+
).json()) as any
192198

193-
ctx.response.status = 200
194-
ctx.body = `
199+
ctx.response.status = 200
200+
ctx.body = `
195201
<html>
196202
<body>
197203
<div>Available remote debugging pages:</div>
198204
<script>
199205
const list = ${JSON.stringify(list)}
200206
list.forEach((page) => {
201207
const div = document.createElement('div')
202-
div.innerHTML = '<a href="http://'+window.location.hostname+':${remoteDebuggingPort}/devtools/inspector.html?ws='+(page.webSocketDebuggerUrl.replace('ws://', ''))+'">'+page.title+' '+page.url+'</a>'
208+
const a = document.createElement('a')
209+
a.href =
210+
'http://' +
211+
window.location.hostname +
212+
':${remoteDebuggingPort}/devtools/inspector.html?ws=' +
213+
page.webSocketDebuggerUrl.replace('ws://', '')
214+
a.textContent = page.title + ' ' + page.url
215+
div.appendChild(a)
203216
document.body.appendChild(div)
204217
})
205218
</script>
206219
</body>
207220
</html>
208221
`
209-
} catch(e) {
222+
clearTimeout(timeout)
223+
} finally {
224+
clearTimeout(timeout)
225+
}
226+
} catch (e) {
210227
this.logger.error(`Error connecting to remote debugging port ${remoteDebuggingPort}: ${e}`)
211228

212229
ctx.response.status = 500

src/helpers/ConfigHelper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export class ConfigHelper extends EventEmitter {
130130

131131
for (const window of Object.values<ConfigWindow>(config.windows)) {
132132
if (window.disable === undefined) window.disable = false
133+
if (window.canSpanMultipleDisplays === undefined) window.canSpanMultipleDisplays = false
133134
}
134135
}
135136
/** Returns the path of the folder where we store the config file. */

0 commit comments

Comments
 (0)