| 427 | } |
| 428 | |
| 429 | async function waitForExpression(client, expression, timeoutMs, label) { |
| 430 | const deadline = Date.now() + timeoutMs |
| 431 | let lastError = null |
| 432 | while (Date.now() < deadline) { |
| 433 | try { |
| 434 | const value = await evaluate(client, expression) |
| 435 | if (value) return value |
| 436 | } catch (err) { |
| 437 | lastError = err |
| 438 | } |
| 439 | await sleep(50) |
| 440 | } |
| 441 | throw new Error(`Timed out waiting for ${label}: ${lastError?.message ?? 'condition not met'}`) |
| 442 | } |
| 443 | |
| 444 | async function prepareWebDist() { |
| 445 | if (!skipWebBuild || !(await fileExists(webDistIndex))) { |