Skip to content

Commit 6a9cda5

Browse files
authored
Ensure browser instances are not re-created un-necessarily (vercel#29091)
1 parent ae305f6 commit 6a9cda5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

test/lib/browsers/playwright.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Playwright extends BrowserInterface {
2525
private browserName: string
2626

2727
async setup(browserName: string) {
28+
if (browser) return
2829
this.browserName = browserName
2930
const headless = !!process.env.HEADLESS
3031

@@ -35,18 +36,18 @@ class Playwright extends BrowserInterface {
3536
} else {
3637
browser = await chromium.launch({ headless, devtools: !headless })
3738
}
39+
context = await browser.newContext()
3840
}
3941

4042
async get(url: string): Promise<void> {
4143
return page.goto(url) as any
4244
}
4345

4446
async loadPage(url: string) {
45-
if (context) {
46-
await context.close()
47-
context = undefined
47+
// clean-up existing pages
48+
for (const oldPage of context.pages()) {
49+
await oldPage.close()
4850
}
49-
context = await browser.newContext()
5051
page = await context.newPage()
5152
pageLogs = []
5253

0 commit comments

Comments
 (0)