xvrh / puppeteer-dart

A Dart library to automate the Chrome browser over the DevTools Protocol. This is a port of the Puppeteer API
BSD 3-Clause "New" or "Revised" License
232 stars 59 forks source link

Running in docker 'Exception: Websocket url not found' #128

Open traveling-developer opened 4 years ago

traveling-developer commented 4 years ago

I build a small dart console app and compiled it via dart2native. Everything works fine until puppeteer starts up. I see in the docker that chrome is downloaded and the folder .local-chromium is created.

But nevertheless I get the exception: 'Exception: Websocket url not found' Is there something missing?

I call puppeteer as following:

await puppeteer.launch(
      headless: true,
      noSandboxFlag: true,
      args: ['--window-size=1024,768', '--disable-features=site-per-process'],
    );
xvrh commented 4 years ago

Hi @yudansha , Can you share your Dockerfile so we can see the base image and try to reproduce? Thanks.

xvrh commented 4 years ago

Also it's possible that you need the noSandboxFlag: true parameter on the launch method.

traveling-developer commented 4 years ago

Hi @xvrh, thanks for your fast reply. As you see above I already set this flag to true. I tried it now with installing chrome and setting the path as an argument. This works, but it would be nice to know why the default way does not work. Here my docker file:

FROM ubuntu:20.10

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

RUN apt-get update && \
    apt-get -y install \
    zip \
    unzip \
    curl \
    poppler-utils \
    default-jre-headless

# add files

ADD /scripts/generate.sh /home
RUN chmod +x /home/generate.sh

RUN mkdir -p /home/generator
ADD /scripts/PdfHandout.jar /home/generator

RUN mkdir -p /home/converter
ADD /src/workshop_builder /home/converter
RUN chmod +x /home/converter/workshop_builder

WORKDIR /home/converter

RUN mkdir -p /home/output
RUN mkdir -p /home/input
RUN mkdir -p /home/generated

WORKDIR /home
derkweijers commented 4 years ago

Hi!

I'm running into the same issue. I'm using the following Dockerfile:

FROM google/dart

WORKDIR /app
RUN apt-get update && apt-get install -y unzip

ADD pubspec.* /app/
RUN pub get
ADD . /app
RUN pub get --offline

CMD []
ENTRYPOINT ["dart", "./bin/importer.dart"]

I'm running the app in the Dart VM. I'm launching puppeteer without any options:

var browser = await puppeteer.launch();
orrios commented 4 years ago

On a docker container with chromium installed when you try to run on bash chromium-browser You get the following error: Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

So launching puppeteer as:

puppeteer.launch(
      headless: true,
      args: ['--no-sandbox'],
    );

Launches puppeteer correctly. Running it as non root user should not need the no sandbox flag

derkweijers commented 4 years ago

Installing Chromium in the container fixes the issue for me. I'm a bit confused though, as there is also a local-chromium installed. Why would I need Chromium installed as well?

Thanks!

orrios commented 4 years ago

@derkweijers This is the way it was solved on a a popular node dockerfile https://github.com/buildkite/docker-puppeteer/issues/91#issuecomment-618824443:

Unfortunately we need to install Chromium, because otherwise you miss out on all the dependencies that are required by the bundled node binary. I've added a note here to hopefully explain the issue: https://github.com/buildkite/docker-puppeteer/blob/master/Dockerfile#L13-L18

derkweijers commented 4 years ago

Thanks! It's running in production for a few days now without problems. For me, this issue is solved.

lycstar commented 2 years ago

I encountered this problem on Ubuntu 20.04, then I tried to run chrome in .local-chromium directly, I found that some so files such as libatk and libgdm were missing, then I installed these dependencies by apt install, the problem solved.

ysyfff commented 1 year ago

Problem Sovled!

问题完美解决了!(我是在树莓派上遇到的这个问题,mac上是没有这个问题的)

让我们来分析下这个问题。

为什么报“Websocket url not found”这个错误?

通过看源码以及对比mac上可以猜测出应该是puppeteer准备下载chromium的时候没有找到对应当前操作系统的chromium版本。所以也就无法去下载了,也就没有后续了。(puppeteer应该只是准备了mac,windows,linux等主流操作系统的chromium版本,所以当遇到树莓派等其他操作系统的时候就找不到合适的chromium包了,所以出现该错误)

如何解决该问题?

知道了问题所在就很简单了,我们知道puppeteer.launch的时候有个executablePath的入参,这个是关键,那我们可以在树莓派上自己安装chromium-browser版本,然后指定到我们的chromium-browser即可

sudo apt install chromium-browser -y  # 安装完成后路径是 /usr/bin/chromium-browser

安装完成后指定executablePath

browser = await puppeteer.launch(
    headless: true,
    noSandboxFlag: true,
    executablePath: '/usr/bin/chromium-browser',
    args: [
      '--use-fake-ui-for-media-stream',
      '--disable-setuid-sandbox',
      '--no-sandbox'
    ]);

That‘s the way to solve this problem and I trust it works for you too!