feat(cli): improve session new output and add session delete command

This commit is contained in:
Tommy D. Rossi
2026-01-27 18:35:23 +01:00
parent e03f1abc0f
commit 1de0f6d1a4
2 changed files with 55 additions and 1 deletions
+23
View File
@@ -1173,6 +1173,29 @@ export async function startPlayWriterCDPRelayServer({
app.get('/cli/session/suggest', (c) => {
return c.json({ next: nextSessionNumber })
})
app.post('/cli/session/delete', async (c) => {
try {
const body = await c.req.json() as { sessionId: string }
const { sessionId } = body
if (!sessionId) {
return c.json({ error: 'sessionId is required' }, 400)
}
const manager = await getExecutorManager()
const deleted = manager.deleteExecutor(sessionId)
if (!deleted) {
return c.json({ error: `Session ${sessionId} not found` }, 404)
}
return c.json({ success: true })
} catch (error: any) {
logger?.error('Delete session endpoint error:', error)
return c.json({ error: error.message }, 500)
}
})
// ============================================================================
// Recording Endpoints - For screen recording via chrome.tabCapture
+32 -1
View File
@@ -141,7 +141,8 @@ cli
try {
const res = await fetch(`${serverUrl}/cli/session/suggest`)
const { next } = await res.json() as { next: number }
console.log(next)
console.log(`Session ${next} created.`)
console.log(`Use it with: playwriter -s ${next} -e "await page.goto('https://example.com')"`)
} catch (error: any) {
console.error(`Error: ${error.message}`)
process.exit(1)
@@ -191,6 +192,36 @@ cli
}
})
cli
.command('session delete <sessionId>', 'Delete a session and clear its state')
.option('--host <host>', 'Remote relay server host')
.action(async (sessionId: string, options: { host?: string }) => {
const serverUrl = await getServerUrl(options.host)
if (!options.host && !process.env.PLAYWRITER_HOST) {
await ensureRelayServer({ logger: console, env: cliRelayEnv })
}
try {
const response = await fetch(`${serverUrl}/cli/session/delete`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ sessionId }),
})
if (!response.ok) {
const result = await response.json() as { error: string }
console.error(`Error: ${result.error}`)
process.exit(1)
}
console.log(`Session ${sessionId} deleted.`)
} catch (error: any) {
console.error(`Error: ${error.message}`)
process.exit(1)
}
})
cli
.command('session reset <sessionId>', 'Reset the browser connection for a session')
.option('--host <host>', 'Remote relay server host')