()
| 24 | } |
| 25 | |
| 26 | export async function closeBrowser(): Promise<void> { |
| 27 | if (!browserPromise) return; |
| 28 | // Claim shutdown and detach the promise BEFORE awaiting, so a concurrent |
| 29 | // getBrowser() rejects cleanly instead of handing back a browser we're |
| 30 | // about to close out from under it. |
| 31 | closing = true; |
| 32 | const pending = browserPromise; |
| 33 | browserPromise = undefined; |
| 34 | const b = await pending.catch(() => undefined); |
| 35 | await b?.close().catch(() => {}); |
| 36 | } |