( browser: Browser, config?: Partial<Pick<EngineConfig, "enableBrowserPool">>, )
| 486 | } |
| 487 | |
| 488 | export async function releaseBrowser( |
| 489 | browser: Browser, |
| 490 | config?: Partial<Pick<EngineConfig, "enableBrowserPool">>, |
| 491 | ): Promise<void> { |
| 492 | const enablePool = config?.enableBrowserPool ?? DEFAULT_CONFIG.enableBrowserPool; |
| 493 | if (!enablePool) { |
| 494 | await browser.close().catch(() => {}); |
| 495 | return; |
| 496 | } |
| 497 | if (pooledBrowser && pooledBrowser === browser) { |
| 498 | pooledBrowserRefCount = Math.max(0, pooledBrowserRefCount - 1); |
| 499 | if (pooledBrowserRefCount === 0) { |
| 500 | await browser.close().catch(() => {}); |
| 501 | pooledBrowser = null; |
| 502 | _pooledBrowserLaunchPromise = null; |
| 503 | } |
| 504 | return; |
| 505 | } |
| 506 | await browser.close().catch(() => {}); |
| 507 | } |
| 508 | |
| 509 | export function forceReleaseBrowser(browser: Browser): void { |
| 510 | if (pooledBrowser && pooledBrowser === browser) { |
no test coverage detected