Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
traveling-developer opened this issue Oct 23, 2020 · 10 comments
Open

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

traveling-developer opened this issue Oct 23, 2020 · 10 comments

Comments

@traveling-developer
Copy link

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
Copy link
Owner

xvrh commented Oct 23, 2020

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

@xvrh
Copy link
Owner

xvrh commented Oct 23, 2020

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

@traveling-developer
Copy link
Author

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
Copy link

derkweijers commented Nov 3, 2020

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
Copy link

orrios commented Nov 5, 2020

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
Copy link

derkweijers commented Nov 7, 2020

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
Copy link

orrios commented Nov 9, 2020

@derkweijers This is the way it was solved on a a popular node dockerfile buildkite/docker-puppeteer#91 (comment):

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
Copy link

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

@lycstar
Copy link

lycstar commented Mar 5, 2022

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
Copy link

ysyfff commented Nov 20, 2022

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants