Skip to content

Commit

Permalink
Merge pull request #550 from bcgov/ccfri-3694-debug-puppeteer
Browse files Browse the repository at this point in the history
More Puppeteer fixes and improvements
  • Loading branch information
trev-dev authored Oct 25, 2024
2 parents a9fc7ef + a52e79f commit 1430f2b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM artifacts.developer.gov.bc.ca/docker-remote/node:20.18.0-alpine3.20
FROM artifacts.developer.gov.bc.ca/docker-remote/node:20.18.0-alpine3.19

ENV NPM_CONFIG_CACHE /tmp/npm
RUN mkdir -p /logs \
Expand Down
10 changes: 8 additions & 2 deletions backend/src/util/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function getBrowserContext() {
browserProcess
.on('close', code => log.info(`Puppeteer :: browser process closed, status: ${code}`));

return browser.createBrowserContext();
return await browser.createBrowserContext();
} catch (e) {
log.error('Puppeteer :: Browser process could not be retrieved', e);
return null;
Expand All @@ -49,7 +49,13 @@ async function getBrowserContext() {
* Gracefully close the browser and all of its pages/contexts.
*/
async function closeBrowser() {
if (browser.pages().length === 0) {
if (browser === null) {
log.warn('Puppeteer :: closeBrowser called with null browser');
return;
}

const pages = await browser.pages();
if (pages.length === 1) {
await browser.close();
} else {
log.warn('Puppeteer :: closeBrowser was called with pages open');
Expand Down

0 comments on commit 1430f2b

Please sign in to comment.