Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Puppeteer fixes and improvements #550

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading