Skip to content

Commit b53bec7

Browse files
Copilotkobenguyent
andauthored
Fix browser hanging during cleanup by not waiting for browser.close() to complete (#5319)
* Initial plan * Fix test hang issue when restart: false by properly mapping to context restart Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com> * Fix browser close hanging by ensuring all pages and contexts are closed first Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com> * Don't wait for browser.close() to prevent hanging - fire and forget approach Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
1 parent c21bfa6 commit b53bec7

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/helper/Playwright.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,7 @@ class Playwright extends Helper {
13891389
}
13901390
}
13911391

1392+
// Close browserContext if recordHar is enabled
13921393
if (this.options.recordHar && this.browserContext) {
13931394
try {
13941395
await this.browserContext.close()
@@ -1398,16 +1399,16 @@ class Playwright extends Helper {
13981399
}
13991400
this.browserContext = null
14001401

1402+
// Initiate browser close without waiting for it to complete
1403+
// The browser process will be cleaned up when the Node process exits
14011404
if (this.browser) {
14021405
try {
1403-
// Add timeout to prevent browser.close() from hanging indefinitely
1404-
await Promise.race([this.browser.close(), new Promise((_, reject) => setTimeout(() => reject(new Error('Browser close timeout')), 5000))])
1406+
// Fire and forget - don't wait for close to complete
1407+
this.browser.close().catch(() => {
1408+
// Silently ignore any errors during async close
1409+
})
14051410
} catch (e) {
1406-
// Ignore errors if browser is already closed or timeout
1407-
if (!e.message?.includes('Browser close timeout')) {
1408-
// Non-timeout error, can be ignored as well
1409-
}
1410-
// Force cleanup even on error
1411+
// Ignore any synchronous errors
14111412
}
14121413
}
14131414
this.browser = null

0 commit comments

Comments
 (0)