fix(browser): retain startup owners and coordinate retryable close

Validation: integrated changes passed formatting, typecheck, lint, resolved module-boundary verification and git diff --check. Tests and real-provider workflows were not run.
This commit is contained in:
morluto
2026-10-11 00:03:22 +08:00
parent d1235fadc9
commit 2a66ec9094
7 changed files with 184 additions and 81 deletions
+10 -2
View File
@@ -33,6 +33,7 @@ export class CdpConnection {
>();
#nextId = 1;
#closed = false;
#closePromise: Promise<void> | undefined;
#protocolFailed = false;
#transportFailure: "disconnected" | "payload_limit" = "disconnected";
@@ -151,8 +152,15 @@ export class CdpConnection {
}
/** Close only REA's socket; never close the browser or selected page. */
async close(): Promise<void> {
if (this.#closed) return;
close(): Promise<void> {
this.#closePromise ??= this.#closeTransport().catch((cause: unknown) => {
this.#closePromise = undefined;
throw cause;
});
return this.#closePromise;
}
async #closeTransport(): Promise<void> {
this.#closed = true;
this.#failPending("disconnected");
if (this.socket.readyState === WebSocket.CLOSED) return;