node-html-to-image
node-html-to-image copied to clipboard
node-html-to-image timout error inside docker container
My code for generating image looks like
async generateImage(html: string) {
return nodeHtmlToImage({
html: html.toString(),
puppeteerArgs: {
args: ['--no-sandbox', '--disable-setuid-sandbox'],
executablePath: '/usr/bin/google-chrome',
},
timeout: 50000
});
}
it is actually working when i star it locally
error:
Error: Timeout hit: 50000
at /build/node_modules/puppeteer-cluster/dist/util.js:69:23
at Generator.next (<anonymous>)
at fulfilled (/build/node_modules/puppeteer-cluster/dist/util.js:5:58)
how i installed puppeteer:
FROM node:18
# Install Google Chrome Stable and fonts
# Note: this installs the necessary libs to make the browser work with Puppeteer.
RUN apt-get update && apt-get install gnupg wget -y && \
wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
apt-get update && \
apt-get install google-chrome-stable -y --no-install-recommends && \
rm -rf /var/lib/apt/lists/*
I too am getting this same issue - I saw a few other open issues that actually look related. I added $25 bounty to this issue in hopes it gets looked at. If others have the same issue and want to increase the bounty in hopes to see this worked on, you can add USDC or DAI via https://app.gitgig.io/create-bounty/45
I got the related project using this lib with the issue to add an extra $25 to the bounty as well...so its up to $50 total! :)
Wasn't able to replicate the error. Works okay for me. Code-
const nodeHtmlToImage = require('node-html-to-image');
const express = require('express');
async function generateImage(html) {
try {
console.log('Launching image generation...');
const image = await nodeHtmlToImage({
html: html.toString(),
puppeteerArgs: {
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
],
executablePath: '/usr/bin/google-chrome',
},
timeout: 50000,
});
console.log('Image generation successful');
console.log(image);
return image;
} catch (error) {
console.error('Error during image generation:', error.message);
throw error;
}
}
const app = express();
const port = 3000;
app.use(express.json());
app.post('/generate-image', async (req, res) => {
const { html } = req.body;
if (!html) {
return res.status(400).json({ error: 'HTML content is required' });
}
try {
const imageBuffer=await generateImage(html);
res.set('Content-Type', 'image/png');
res.send(imageBuffer);
} catch (error) {
res.status(500).json({ error: 'Failed to generate image' });
}
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
Dockerfile-
FROM node:18
RUN apt-get update && apt-get install gnupg wget -y && \
wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
apt-get update && \
apt-get install google-chrome-stable -y --no-install-recommends && \
rm -rf /var/lib/apt/lists/*
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["node", "index.js"]
@ShukurovOzodbek do you still have the issue with the code provided by @SherbetLemon47?
@ShukurovOzodbek do you still have the issue with the code provided by @SherbetLemon47?
I actually forgot but some libraries was not working with my nodejs version and i just changed nodejs version to 18th and worked fine