From ad53564c8a6884496786c0be602813bd666c74c4 Mon Sep 17 00:00:00 2001 From: Trevor Richards Date: Wed, 30 Oct 2024 14:53:23 -0700 Subject: [PATCH] fix: dead browser instance after one PDF run Also fixes the return value whe getBrowserContext already has a valid instance --- backend/src/util/browser.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/util/browser.js b/backend/src/util/browser.js index 111c893d1..24e97c8fb 100644 --- a/backend/src/util/browser.js +++ b/backend/src/util/browser.js @@ -14,7 +14,8 @@ let browser = null; async function getBrowserContext() { try { if (browser instanceof puppeteer.Browser && browser.process() !== null) { - return browser; + log.info('Puppeteer :: getBrowserContext reusing browser process'); + return browser.createBrowserContext(); } // To debug locally add {headless: false, devtools: true} in options // make sure they are boolean and not string @@ -57,6 +58,7 @@ async function closeBrowser() { const pages = await browser.pages(); if (pages.length === 1) { await browser.close(); + browser = null; } else { log.warn('Puppeteer :: closeBrowser was called with pages open'); }