This commit is contained in:
seb
2026-10-07 22:10:24 +02:00
parent d49ec77043
commit 3d1601595e
2 changed files with 71 additions and 6 deletions

View File

@@ -89,14 +89,25 @@ class CdpConnection {
send(method, params = {}, timeoutMs = 30000) {
const callId = ++this.id;
return new Promise((resolve, reject) => {
this.pending.set(callId, { resolve, reject });
this.sendFrame(0x1, Buffer.from(JSON.stringify({ id: callId, method, params })));
setTimeout(() => {
const timer = setTimeout(() => {
if (this.pending.has(callId)) {
this.pending.delete(callId);
reject(new Error(`CDP timeout: ${method}`));
}
}, timeoutMs);
// Don't let a settled call's timer hold the process open.
timer.unref?.();
this.pending.set(callId, {
resolve: (v) => {
clearTimeout(timer);
resolve(v);
},
reject: (e) => {
clearTimeout(timer);
reject(e);
},
});
this.sendFrame(0x1, Buffer.from(JSON.stringify({ id: callId, method, params })));
});
}