简体   繁体   中英

Cannot launch puppeteer browser instance in docker image

I am using Node.js 10 I am trying to create a PDF with puppeteer. Here is the docker file

FROM node:10-alpine

RUN echo "http://dl-2.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories
RUN echo "http://dl-2.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
RUN echo "http://dl-2.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories

ENV CHROME_BIN="/usr/bin/chromium-browser" \
    PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"

RUN set -x \
    && apk update \
    && apk upgrade \
    && apk add --no-cache \
    udev \
    ttf-freefont \
    chromium \
    && npm install puppeteer@1.17.0

RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app

WORKDIR /home/node/app

ENV PATH /home/node/app/node_modules/.bin:$PATH

COPY package*.json ./

RUN apk --no-cache --virtual build-dependencies add \
    python \
    make \
    g++ \
    && npm install \
    && apk del build-dependencies

USER node

RUN npm install

RUN mkdir -p /home/node/app/logs

COPY --chown=node:node . .

EXPOSE 4000

EXPOSE 3050

CMD [ "node", "app.js" ]

I am getting the below error when trying to launch a browser instance.

{ Error: Protocol error (IO.read): Invalid parameters handle: string value expected
    at Promise (/home/node/app/node_modules/puppeteer/lib/Connection.js:183:56)
    at new Promise (<anonymous>)
    at CDPSession.send (/home/node/app/node_modules/puppeteer/lib/Connection.js:182:12)
    at Function.readProtocolStream (/home/node/app/node_modules/puppeteer/lib/helper.js:241:37)
    at Page.pdf (/home/node/app/node_modules/puppeteer/lib/Page.js:988:25)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  -- ASYNC --
    at Page.<anonymous> (/home/node/app/node_modules/puppeteer/lib/helper.js:111:15)
    at fetchLedgerPdf (/home/node/app/Models/post/pdfCreation.js:316:39)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  message:
   'Protocol error (IO.read): Invalid parameters handle: string value expected' }

I have ensured that my chromium and puppeteer version are the same as mentioned on a lot of forums. I am using puppeteer@1.17.0 , with the edge image of alpine that uses chromium 76.0.3809.132-r0. I also tried with puppeeteer@1.18.0 but the issue still persists

I was able to resolve this issue by creating a container from this image, Browserless Chrome This image takes care of all the dependencies and puppeteer works as a charm. I recommend using this image instead of manually adding dependencies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM