feat(cli): improve session new output and add session delete command
This commit is contained in:
@@ -1173,6 +1173,29 @@ export async function startPlayWriterCDPRelayServer({
|
|||||||
app.get('/cli/session/suggest', (c) => {
|
app.get('/cli/session/suggest', (c) => {
|
||||||
return c.json({ next: nextSessionNumber })
|
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
|
// Recording Endpoints - For screen recording via chrome.tabCapture
|
||||||
|
|||||||
+32
-1
@@ -141,7 +141,8 @@ cli
|
|||||||
try {
|
try {
|
||||||
const res = await fetch(`${serverUrl}/cli/session/suggest`)
|
const res = await fetch(`${serverUrl}/cli/session/suggest`)
|
||||||
const { next } = await res.json() as { next: number }
|
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) {
|
} catch (error: any) {
|
||||||
console.error(`Error: ${error.message}`)
|
console.error(`Error: ${error.message}`)
|
||||||
process.exit(1)
|
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
|
cli
|
||||||
.command('session reset <sessionId>', 'Reset the browser connection for a session')
|
.command('session reset <sessionId>', 'Reset the browser connection for a session')
|
||||||
.option('--host <host>', 'Remote relay server host')
|
.option('--host <host>', 'Remote relay server host')
|
||||||
|
|||||||
Reference in New Issue
Block a user