lucacasonato/deno-puppeteer

Issue with running in docker

Opened this issue · 3 comments

Not sure what I'm doing wrong, but can't seem to get deno-puppeteer working in docker. It works fine if I run the deno --allow-all main.js.

Error

Interrupted: operation canceled
    at async read (ext:deno_io/12_io.js:102:17)
    at async readDelim (https://deno.land/std@0.93.0/io/bufio.ts:652:20)
    at async readStringDelim (https://deno.land/std@0.93.0/io/bufio.ts:702:20)
    at async readLines (https://deno.land/std@0.93.0/io/bufio.ts:711:18)
    at async waitForWSEndpoint (https://deno.land/x/puppeteer@16.2.0/src/deno/BrowserRunner.ts:168:20)
    at async BrowserRunner.setupConnection (https://deno.land/x/puppeteer@16.2.0/src/deno/BrowserRunner.ts:146:31)
    at async ChromeLauncher.launch (https://deno.land/x/puppeteer@16.2.0/src/deno/Launcher.ts:114:26)
    at async loginToRouter (file:///app/main.js:55:19)
    at async maintainInternetConnectivity (file:///app/main.js:144:9) {
  name: "Interrupted",
  code: "EINTR"
}

If I leave it running longer it'll give a timeout error.

Code snippet

import puppeteer from "https://deno.land/x/puppeteer@16.2.0/mod.ts";
...
async function loginToRouter() {
  const browser = await puppeteer.launch({
    headless: true,
    args: ["--no-sandbox", "--disable-setuid-sandbox", "--disable-dev-shm-usage"],
  });
}
...

Dockerfile

FROM denoland/deno:1.39.0

WORKDIR /app

USER root # have tried with an without root

COPY . .

RUN deno cache main.js

RUN PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/puppeteer@16.2.0/install.ts

CMD ["deno", "run", "--allow-all", "--unstable", "main.js"] # for testing only, but still doesn't work

@crbon did you solve this? I'm running into the same issue.

@BrunoBernardino unfortunately I haven't worked it out, the issues is still present.

Thanks. I also tried npm:puppeteer and ran into similar issues. I basically ended up switching to using wkhtmltopdf since I was using puppeteer to generate a PDF of an HTML document. I install the command in the docker machine and just call new Deno.Command('wkhtmltopdf', { args: ['file://<htmlFilePath>', '<pdfFilePath>'] }); from the code, now.

If anyone's curious, here's my Dockerfile:

# wkhtmltopdf image needed to more quickly build bins
FROM surnet/alpine-wkhtmltopdf:3.19.0-0.12.6-full as wkhtmltopdf
FROM denoland/deno:alpine-1.39.3

# wkhtmltopdf install dependencies
RUN apk add --no-cache \
        libstdc++ \
        libx11 \
        libxrender \
        libxext \
        libssl1.1 \
        xvfb \
        ca-certificates \
        fontconfig \
        freetype \
        ttf-droid \
        ttf-freefont \
        ttf-liberation \
        # more fonts
        ;

# wkhtmltopdf copy bins from ext image
COPY --from=wkhtmltopdf /bin/wkhtmltopdf /bin/libwkhtmltox.so /bin/

RUN ln -s /bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf;
RUN chmod +x /usr/local/bin/wkhtmltopdf;

EXPOSE 8000

# Prefer not to run as root.
USER deno

WORKDIR /app

# These steps will be re-run upon each file change in your working directory:
ADD . /app

# Compile the main app so that it doesn't need to be compiled each startup/entry.
RUN deno cache --reload main.ts

CMD ["run", "--allow-all", "main.ts"]