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 { ...@@ -25,6 +25,7 @@ class Playwright extends BrowserInterface {
private browserName: string private browserName: string
async setup(browserName: string) { async setup(browserName: string) {
if (browser) return
this.browserName = browserName this.browserName = browserName
const headless = !!process.env.HEADLESS const headless = !!process.env.HEADLESS
...@@ -35,6 +36,7 @@ class Playwright extends BrowserInterface { ...@@ -35,6 +36,7 @@ class Playwright extends BrowserInterface {
} else { } else {
browser = await chromium.launch({ headless, devtools: !headless }) browser = await chromium.launch({ headless, devtools: !headless })
} }
context = await browser.newContext()
} }
async get(url: string): Promise<void> { async get(url: string): Promise<void> {
...@@ -42,11 +44,10 @@ class Playwright extends BrowserInterface { ...@@ -42,11 +44,10 @@ class Playwright extends BrowserInterface {
} }
async loadPage(url: string) { async loadPage(url: string) {
if (context) { // clean-up existing pages
await context.close() for (const oldPage of context.pages()) {
context = undefined await oldPage.close()
} }
context = await browser.newContext()
page = await context.newPage() page = await context.newPage()
pageLogs = [] 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