()
| 544 | * that should not share browser state. |
| 545 | */ |
| 546 | export async function drainBrowserPool(): Promise<void> { |
| 547 | // Await any in-flight launch first — otherwise the launch resolves after we |
| 548 | // drain and produces a browser that nobody references (orphan). |
| 549 | const pending = _pooledBrowserLaunchPromise; |
| 550 | _pooledBrowserLaunchPromise = null; |
| 551 | if (pending) { |
| 552 | await pending.then((r) => r.browser.close()).catch(() => {}); |
| 553 | } |
| 554 | if (pooledBrowser) { |
| 555 | const browser = pooledBrowser; |
| 556 | pooledBrowser = null; |
| 557 | pooledBrowserRefCount = 0; |
| 558 | await browser.close().catch(() => {}); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | /** Test-only: reset all pool state. */ |
| 563 | export function _resetBrowserPoolForTests(): void { |
no test coverage detected