Monday, 11 February 2019

Puppeteer Error: Protocol error (Page.captureScreenshot): Target closed

I have this error running puppeteer@1.12.2 on node:8-slim container.

The full error:

Error: Protocol error (Page.captureScreenshot): Target closed.
    at Promise (/app/node_modules/puppeteer/lib/Connection.js:183:56)
    at new Promise (<anonymous>)
    at CDPSession.send (/app/node_modules/puppeteer/lib/Connection.js:182:12)
    at Page._screenshotTask (/app/node_modules/puppeteer/lib/Page.js:903:39)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
  -- ASYNC --
    at Page.<anonymous> (/app/node_modules/puppeteer/lib/helper.js:108:27)
    at /app/test.js:9:15
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)

The js file (inspired by GoogleChrome/puppeteer/examples/screenshot.js):

const puppeteer = require('puppeteer');
(async() => {
         const browser = await puppeteer.launch({
                headless: true,
                args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gpu', '--disable-dev-shm-usage']
         });
          const page = await browser.newPage();
          await page.goto('http://google.com');
          await page.screenshot({path: 'example.png'});
          await browser.close();
})();

The Dockerfile (inspired by troubleshooting.md#running-puppeteer-in-docker):


FROM node:8-slim

RUN apt-get update && apt-get install -yq libgconf-2-4

RUN apt-get update && apt-get install -y wget --no-install-recommends \
    && 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-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont \
      --no-install-recommends \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get purge --auto-remove -y curl \
    && rm -rf /src/*.deb

    user node

    COPY ./ ./
    RUN npm i --unsafe-perm=true

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


The same test.js makes high quality screenshots on the host OS, but fails in a container.

Is there any magic parameter to run it in node-slim container? I am happy with any version of puppeteer that works.

Version of google-chrome-unstable installed from Dockerfile is "73.0.3683.20 dev". Version of chrome installed by npm is "73.0.3679.0".



from Puppeteer Error: Protocol error (Page.captureScreenshot): Target closed

No comments:

Post a Comment