Comments (6)
Hi @lucacasonato, @halvardssm.
I solved this.
I checked the error message by adding console.log (line);
between lines 167 and 168 of BrowserRunner.ts
in deno-puppeteer
.
I found that the cause of the error was that some required packages were not installed.
The packages listed in troubleshooting of puppeteer
are not enough for Docker containers, need the following:
libdrm2
libxkbcommon0
libxshmfence1
And one more important thing is written here.
If we run as root user inside a Docker container, we need to use --no-sandbox
mode when launching Puppeteer.
Otherwise error will occur.
Yet one more thing, Troubleshooting has tips on shared memory issues in Docker containers.
Based on these, the parameters of the launch
method should be as follows:
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
'--disable-dev-shm-usage'
],
});
This is my Dockerfile:
FROM debian:buster-slim
ENV DENO_VERSION=1.10.1
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get -qq update \
&& apt-get -qq install -y --no-install-recommends \
curl \
ca-certificates \
unzip \
# ↓ https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix
# Since I want to leave the contents of troubleshooting.md as it is, ca-certificates is intentionally duplicated here.
ca-certificates \
fonts-liberation \
libappindicator3-1 \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libc6 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgbm1 \
libgcc1 \
libglib2.0-0 \
libgtk-3-0 \
libnspr4 \
libnss3 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libxss1 \
libxtst6 \
lsb-release \
wget \
xdg-utils \
# ↑ https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix
# ↓ Added based on the information obtained from by console.log(line) at https://deno.land/x/[email protected]/src/deno/BrowserRunner.ts#L168.
libdrm2 \
libxkbcommon0 \
libxshmfence1 \
# ↑ Added based on the information obtained from by console.log(line) at https://deno.land/x/[email protected]/src/deno/BrowserRunner.ts#L168.
&& curl -fsSL https://github.com/denoland/deno/releases/download/v${DENO_VERSION}/deno-x86_64-unknown-linux-gnu.zip \
--output deno.zip \
&& unzip deno.zip \
&& rm deno.zip \
&& chmod 755 deno \
&& mv deno /usr/bin/deno \
&& apt-get -qq remove --purge -y \
curl \
# Do not remove ca-certificates as it is required by puppeteer.
# ca-certificates \
unzip \
&& apt-get -y -qq autoremove \
&& apt-get -qq clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN useradd --uid 1993 --user-group deno \
&& mkdir /deno-dir/ \
&& chown deno:deno /deno-dir/
ENV DENO_DIR /deno-dir/
# https://deno.land/x/[email protected]#installation
RUN PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/[email protected]/install.ts
WORKDIR /root
ENTRYPOINT ["deno"]
CMD ["run", "https://deno.land/std/examples/welcome.ts"]
Thank you.
from deno-puppeteer.
Added an example Dockerfile and info to the README. Thanks everyone for figuring this out. Especially @mt-u who got it working in the end :-)
from deno-puppeteer.
Same goes for running with WSL 2.
from deno-puppeteer.
same here
from deno-puppeteer.
Source:
deno-puppeteer/src/deno/BrowserRunner.ts
Lines 156 to 183 in aa7dc66
Haven't tried to debug this yet, but here are some initial thoughts:
- Is the "listening" message still being emitted to
stderr
and notstdout
? - Is the regex still accurate?
from deno-puppeteer.
Hi @lucacasonato .
When I run deno and puppeteer on a Docker container, I get the same error message as @halvardssm.
So I recreated the Dockerfile according to the trouble shooting link shown in the error message.
Then I got another error.
error: Uncaught (in promise) BadResource: Bad resource ID
Does this help anything?
Dockerfile is
FROM debian:buster-20210511-slim
ENV DENO_VERSION=1.10.1
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get -qq update \
&& apt-get -qq install -y --no-install-recommends \
curl \
ca-certificates \
unzip \
# ↓ from puppeteer instruction https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-in-docker
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-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
--no-install-recommends \
# ↑ from puppeteer instruction https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-in-docker
&& curl -fsSL https://github.com/denoland/deno/releases/download/v${DENO_VERSION}/deno-x86_64-unknown-linux-gnu.zip \
--output deno.zip \
&& unzip deno.zip \
&& rm deno.zip \
&& chmod 755 deno \
&& mv deno /usr/bin/deno \
&& apt-get -qq remove --purge -y \
curl \
ca-certificates \
unzip \
&& apt-get -y -qq autoremove \
&& apt-get -qq clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN useradd --uid 1993 --user-group deno \
&& mkdir /deno-dir/ \
&& chown deno:deno /deno-dir/
ENV DENO_DIR /deno-dir/
# https://deno.land/x/[email protected]#installation
RUN PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/[email protected]/install.ts
WORKDIR /root
ENTRYPOINT ["deno"]
CMD ["run", "https://deno.land/std/examples/welcome.ts"]
Script file(sample.ts) is
import puppeteer from "https://deno.land/x/[email protected]/mod.ts";
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://sample.com");
await page.screenshot({ path: '/root/sample.png' });
await browser.close();
Error message is
$ docker build -t deno .
... building docker image ...
... after successfully built ...
$ docker run --rm -it -v path-to-sample-script-dir:/root deno:latest run -A --unstable sample.ts
Check file:///root/sample.ts
error: Uncaught (in promise) BadResource: Bad resource ID
const result = await reader.read(inspectArr);
^
at deno:core/core.js:86:46
at unwrapOpResult (deno:core/core.js:106:13)
at async read (deno:runtime/js/12_io.js:97:19)
at async readDelim (https://deno.land/[email protected]/io/bufio.ts:652:20)
at async readStringDelim (https://deno.land/[email protected]/io/bufio.ts:702:20)
at async readLines (https://deno.land/[email protected]/io/bufio.ts:711:18)
at async waitForWSEndpoint (https://deno.land/x/[email protected]/src/deno/BrowserRunner.ts:167:20)
at async BrowserRunner.setupConnection (https://deno.land/x/[email protected]/src/deno/BrowserRunner.ts:145:31)
at async ChromeLauncher.launch (https://deno.land/x/[email protected]/src/deno/Launcher.ts:114:26)
at async file:///root/sample.ts:4:17
from deno-puppeteer.
Related Issues (20)
- [uncaught application error]: TypeError - Invalid CString pointer, not valid UTF-8
- Question: what is the strategy of keeping this fork repo in sync with the forked repo? HOT 3
- Adding `{headless:false}` to readme examples when using Chrome makes them hang for 30 seconds and then throw a `TimeoutError` (browser doesn't launch) HOT 2
- How to use it with browserless.io? HOT 2
- Error when saving output of `page.pdf` into variable
- getting PermissionDenied: 'Deno.makeTempDir' is not allowed in this context HOT 8
- Error: Could not find browser revision XXX. Run "PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/puppeteer@VERSION/install.ts" to download a supported browser binary. HOT 6
- TypeError: reader is not async iterable at getReadableStreamAsUint8Array HOT 4
- `Deno.core.runMicrotasks()` is not supported in this environment HOT 2
- Buffer is not defined HOT 5
- Excited to try out `--headless=new` in Chrome 112+ HOT 3
- `deno check` errors out saying `"data" is unexpectedly null for "https://esm.sh/v111/node.ns.d.ts"` HOT 1
- Question: why is browser.close() crasching when using browserless.io HOT 2
- Can't build docker image. It hangs. Package is not usable HOT 4
- NetworkError: failed to connect to WebSocket: Invalid status code HOT 3
- Update docs to detail actual required permissions
- Non try/catchable TimeoutError HOT 3
- cannot connect to remove browser using wss
- Won't run on an M2 MacBook Air HOT 1
- Issue with running in docker HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deno-puppeteer.