Unverified Commit 6a9cda57 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure browser instances are not re-created un-necessarily (#29091)

parent ae305f6a
......@@ -25,6 +25,7 @@ class Playwright extends BrowserInterface {
private browserName: string
async setup(browserName: string) {
if (browser) return
this.browserName = browserName
const headless = !!process.env.HEADLESS
......@@ -35,6 +36,7 @@ class Playwright extends BrowserInterface {
} else {
browser = await chromium.launch({ headless, devtools: !headless })
}
context = await browser.newContext()
}
async get(url: string): Promise<void> {
......@@ -42,11 +44,10 @@ class Playwright extends BrowserInterface {
}
async loadPage(url: string) {
if (context) {
await context.close()
context = undefined
// clean-up existing pages
for (const oldPage of context.pages()) {
await oldPage.close()
}
context = await browser.newContext()
page = await context.newPage()
pageLogs = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment