Skip to content

Commit 0bb6c27

Browse files
authored
Clear playwright singleton on close (#1170)
* fix: clear playwright singleton on close * chore: spelling mistake
1 parent 102ff2d commit 0bb6c27

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/lib/server/websearch/scrape/playwright.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { PlaywrightBlocker } from "@cliqz/adblocker-playwright";
1010
import { env } from "$env/dynamic/private";
1111

1212
// Singleton initialized by initPlaywrightService
13-
let playwrightService: Promise<{ ctx: BrowserContext; blocker: PlaywrightBlocker }>;
13+
let playwrightService: Promise<{ ctx: BrowserContext; blocker: PlaywrightBlocker }> | undefined;
1414

1515
async function initPlaywrightService() {
1616
if (playwrightService) return playwrightService;
@@ -42,6 +42,12 @@ async function initPlaywrightService() {
4242
if (env.WEBSEARCH_JAVASCRIPT === "false") return mostBlocked.blockScripts();
4343
return mostBlocked;
4444
});
45+
46+
// Clear the singleton when the context closes
47+
ctx.on("close", () => {
48+
playwrightService = undefined;
49+
});
50+
4551
return Object.freeze({ ctx, blocker });
4652
}
4753

0 commit comments

Comments
 (0)