wait for extension only if ws restarted
This commit is contained in:
@@ -56,18 +56,19 @@ async function executeCode(options: {
|
|||||||
|
|
||||||
// Ensure relay server is running (only for local)
|
// Ensure relay server is running (only for local)
|
||||||
if (!host && !process.env.PLAYWRITER_HOST) {
|
if (!host && !process.env.PLAYWRITER_HOST) {
|
||||||
await ensureRelayServer({ logger: console, env: cliRelayEnv })
|
const restarted = await ensureRelayServer({ logger: console, env: cliRelayEnv })
|
||||||
// Wait for extension to reconnect after server (re)start
|
if (restarted){
|
||||||
const connected = await waitForExtension({ logger: console, timeoutMs: 10000 })
|
const connected = await waitForExtension({ logger: console, timeoutMs: 10000 })
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
console.error('Warning: Extension not connected. Commands may fail.')
|
console.error('Warning: Extension not connected. Commands may fail.')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Session is required
|
// Session is required
|
||||||
if (!sessionId) {
|
if (!sessionId) {
|
||||||
console.error('Error: -s/--session is required.')
|
console.error('Error: -s/--session is required.')
|
||||||
console.error('Run `playwriter session new` to get a session ID.')
|
console.error('Always run `playwriter session new` first to get a session ID to use.')
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ export interface EnsureRelayServerOptions {
|
|||||||
* Ensures the relay server is running. Starts it if not running.
|
* Ensures the relay server is running. Starts it if not running.
|
||||||
* Optionally restarts on version mismatch.
|
* Optionally restarts on version mismatch.
|
||||||
*/
|
*/
|
||||||
export async function ensureRelayServer(options: EnsureRelayServerOptions = {}): Promise<void> {
|
export async function ensureRelayServer(options: EnsureRelayServerOptions = {}): Promise<true | undefined> {
|
||||||
const { logger, restartOnVersionMismatch = true, env: additionalEnv } = options
|
const { logger, restartOnVersionMismatch = true, env: additionalEnv } = options
|
||||||
const serverVersion = await getRelayServerVersion(RELAY_PORT)
|
const serverVersion = await getRelayServerVersion(RELAY_PORT)
|
||||||
|
|
||||||
@@ -159,12 +159,9 @@ export async function ensureRelayServer(options: EnsureRelayServerOptions = {}):
|
|||||||
if (newVersion) {
|
if (newVersion) {
|
||||||
logger?.log(pc.green('CDP relay server started successfully'))
|
logger?.log(pc.green('CDP relay server started successfully'))
|
||||||
await sleep(1000)
|
await sleep(1000)
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
throw new Error(`Failed to start CDP relay server after 5 seconds. Check logs at: ${LOG_FILE_PATH}`)
|
throw new Error(`Failed to start CDP relay server after 5 seconds. Check logs at: ${LOG_FILE_PATH}`)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user