INNER CODE UNIT · JavaScript
waitCdp
tiliondev/fortress · sdk/node/index.js:107
async function waitCdp(port, timeoutMs = 90000) {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
try { const r = await fetch(`http://127.0.0.1:${port}/json/version`); if (r.ok) return (await r.json()).webSocketDebuggerUrl; }
catch {}
await new Promise((r) => setTimeout(r, 500));
}
throw new Error("Fortress CDP endpoint did not come up");
}
export class Fortress {
constructor({ port = 9222, persona = null, extraArgs = [], headless = true, channel = DEFAULT_CHANNEL } = {}) {
if (!CHANNELS[channel]) throw new Error(`unknown channel '${channel}'; use one of ${Object.keys(CHANNELS)}`);
const { tag, docker } = CHANNELS[channel];
Object.assign(this, { port, persona, extraArgs, headless, channel, tag, docker, host: hostFor(tag),
proc: null, dockerName: null, cdpUrl: null });
}
static async launch(opts) { return new Fortress(opts).start(); }