mrafiqk / html-pdf-node

187 stars 119 forks source link

Navigation timeout on Docker #52

Open john8329 opened 2 years ago

john8329 commented 2 years ago

Printing works perfectly in local development (using a Mac), but as soon as I create the production build and run it under Docker, I get often this error:

(node:1) UnhandledPromiseRejectionWarning: TimeoutError: Navigation timeout of 30000 ms exceeded

    at /app/node_modules/puppeteer/lib/cjs/puppeteer/common/LifecycleWatcher.js:106:111

Sometimes it works, most often it doesn't. Here's the Dockerfile:

FROM node:14

# First install dependencies
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
RUN apt-get update \
    && apt-get install -y wget gnupg \
    && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && 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 -y google-chrome-stable fonts-ipafont-gothic fonts-freefont-ttf libxss1 \
      --no-install-recommends \
    && rm -rf /var/lib/apt/lists/*

# Install app dependencies
COPY ./package.json ./package-lock.json /app/
WORKDIR /app
RUN npm install --no-progress --production

# Later, copy the app files. That improves development speed as buiding the Docker image will not have 
# to download and install all the NPM dependencies every time there's a change in the source code
COPY ./docker-entrypoint.sh /app/
COPY ./src /app/

ENV NODE_ENV production
EXPOSE 3000
ENTRYPOINT ["bash", "/app/docker-entrypoint.sh"]
CMD ["node", "index.js"]

And the code which is generating the PDF:

     const url = "http://127.0.0.1:" + config.www.port + "/blahblahblah"; 
     const file = {url: url};
     const options = {
            width: "21cm",
            height: "2cm",
            printBackground: true,
        };
     html_to_pdf.generatePdf(file, options).then(pdfBuffer => {
            console.log("Generated")
...

Any hint? Thanks a lot

azzi907 commented 2 years ago

Same case here ... upto ten entries pdf is being generated but with large number of entries ... Navigation time out happens. Any solution ?

ankitbansal-gc commented 2 years ago

Facing the same issue randomly. Retrying the same document works. Seems like the browser puppeteer object becomes slower as more and more documents are processed. Is it possible to increase the timeout or cleanup the browser object after every few document generation?

xor83 commented 2 years ago

Facing same issue. Any solution?