(label, fn, timeoutMs)
| 61 | }; |
| 62 | |
| 63 | const waitFor = async (label, fn, timeoutMs) => { |
| 64 | const deadline = Date.now() + timeoutMs; |
| 65 | for (;;) { |
| 66 | const value = await fn().catch(() => null); |
| 67 | if (value) return value; |
| 68 | if (Date.now() >= deadline) throw new Error(`timed out waiting for ${label}`); |
| 69 | await delay(250); |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | // --- minimal CDP page client over the built-in WebSocket ------------------- |
| 74 | class Cdp { |