From 305e72995bd52caee7ad8b42aae531b8924e7d0d Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Sat, 25 Jul 2026 09:12:17 +0000 Subject: [PATCH] perf(browser): lazy-load Playwright sessions --- src/browser/PlaywrightBrowserScenarioProvider.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/browser/PlaywrightBrowserScenarioProvider.ts b/src/browser/PlaywrightBrowserScenarioProvider.ts index 66924bec7..15c2a54a9 100644 --- a/src/browser/PlaywrightBrowserScenarioProvider.ts +++ b/src/browser/PlaywrightBrowserScenarioProvider.ts @@ -29,9 +29,19 @@ import type { BrowserScenarioSessionPort, } from "./BrowserScenarioSessionPort.js"; import { BrowserScenarioCaptureBudget } from "./PlaywrightScenarioArtifacts.js"; -import { PlaywrightScenarioSessionFactory } from "./PlaywrightScenarioSession.js"; const OPERATION = "capture_browser_scenario" as const; +let defaultFactory: Promise | undefined; + +const lazyPlaywrightFactory: BrowserScenarioSessionFactory = { + async open(scenario, options) { + defaultFactory ??= import("./PlaywrightScenarioSession.js").then( + ({ PlaywrightScenarioSessionFactory }) => + new PlaywrightScenarioSessionFactory(), + ); + return (await defaultFactory).open(scenario, options); + }, +}; export const PLAYWRIGHT_BROWSER_SCENARIO_PROVIDER_IDENTITY: ProviderIdentity = Object.freeze({ @@ -353,7 +363,7 @@ export class PlaywrightBrowserScenarioProvider implements BrowserScenarioCapturePort { constructor( - private readonly factory: BrowserScenarioSessionFactory = new PlaywrightScenarioSessionFactory(), + private readonly factory: BrowserScenarioSessionFactory = lazyPlaywrightFactory, ) {} identity(): ProviderIdentity {