Spaces:
Running
Running
Liam Dyer commited on
Clear playwright singleton on close (#1170)
Browse files* fix: clear playwright singleton on close
* chore: spelling mistake
src/lib/server/websearch/scrape/playwright.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { PlaywrightBlocker } from "@cliqz/adblocker-playwright";
|
|
| 10 |
import { env } from "$env/dynamic/private";
|
| 11 |
|
| 12 |
// Singleton initialized by initPlaywrightService
|
| 13 |
-
let playwrightService: Promise<{ ctx: BrowserContext; blocker: PlaywrightBlocker }>;
|
| 14 |
|
| 15 |
async function initPlaywrightService() {
|
| 16 |
if (playwrightService) return playwrightService;
|
|
@@ -42,6 +42,12 @@ async function initPlaywrightService() {
|
|
| 42 |
if (env.WEBSEARCH_JAVASCRIPT === "false") return mostBlocked.blockScripts();
|
| 43 |
return mostBlocked;
|
| 44 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
return Object.freeze({ ctx, blocker });
|
| 46 |
}
|
| 47 |
|
|
|
|
| 10 |
import { env } from "$env/dynamic/private";
|
| 11 |
|
| 12 |
// Singleton initialized by initPlaywrightService
|
| 13 |
+
let playwrightService: Promise<{ ctx: BrowserContext; blocker: PlaywrightBlocker }> | undefined;
|
| 14 |
|
| 15 |
async function initPlaywrightService() {
|
| 16 |
if (playwrightService) return playwrightService;
|
|
|
|
| 42 |
if (env.WEBSEARCH_JAVASCRIPT === "false") return mostBlocked.blockScripts();
|
| 43 |
return mostBlocked;
|
| 44 |
});
|
| 45 |
+
|
| 46 |
+
// Clear the singleton when the context closes
|
| 47 |
+
ctx.on("close", () => {
|
| 48 |
+
playwrightService = undefined;
|
| 49 |
+
});
|
| 50 |
+
|
| 51 |
return Object.freeze({ ctx, blocker });
|
| 52 |
}
|
| 53 |
|