Reputation: 25
I am using puppeteer to generate pdf. Also i am using selenium for zerodha automation. i need to configure the docker file to work fine for both selenium and puppeteer.
This is docker file
FROM node:16-alpine
# Set the working directory
WORKDIR /app
# Install dependencies
RUN apk update && apk add --no-cache \
chromium \
chromium-chromedriver \
bash \
curl \
wget \
unzip \
make \
g++ \
&& npm install -g selenium-webdriver
# Set environment variables
ENV CHROME_BIN=/usr/bin/chromium-browser
ENV CHROMEDRIVER_PATH=/usr/bin/chromedriver
ENV PUPPETEER_SKIP_DOWNLOAD=true
# Copy application code
COPY package*.json ./
RUN npm install
COPY . .
# Expose the port
EXPOSE 8004
# Start the server
CMD ["node", "server.js"]
the code i use to generate pdf
const browser = await puppeteer.launch({ headless: "new",
args: ['--no-sandbox', '--disable-setuid-sandbox'],
});
const page = await browser.newPage();
await page.setContent(req.query.html, { waitUntil: 'domcontentloaded' });
await page.emulateMediaType('screen');
await page.waitForSelector('body', { visible: true });
await delay(2000);
const pdf = await page.pdf({
path: 'result.pdf',
margin: { top: '100px', right: '50px', bottom: '100px', left: '50px' },
printBackground: true,
format: 'A4',
});
await browser.close();
in AWS EC2 i am getting the below error
message: 'Could not find Chrome (ver. 131.0.6778.204). This can occur if either\n' +
' 1. you did not perform an installation before running the script (e.g. npx puppeteer browsers install chrome) or\n' +
' 2. your cache path is incorrectly configured (which is: /root/.cache/puppeteer).\n' +
'For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.',
data: undefined
Kindly help me to fix this error.
Upvotes: -1
Views: 62