kklisura / chrome-devtools-java-client

Chrome DevTools java client.
Apache License 2.0
222 stars 76 forks source link

Failed while waiting for chrome to start: Timeout expired! Chrome output: #6

Open Vad1mo opened 5 years ago

Vad1mo commented 5 years ago

I am trying to run the example in a docker container but the chrome process is closes immediately,

23:06:44.769 [main] INFO  io.micronaut.runtime.Micronaut - Startup completed in 17ms. Server Running: http://623714484c50:8080
23:06:55.620 [pool-2-thread-3] INFO  c.g.k.cdt.launch.ChromeLauncher - Launching chrome process /usr/bin/chromium with arguments {disable-software-rasterizer=null, disable-dev-shm-usage=null, user-data-dir=/tmp/cdt-user-data-dir3872197855285647012}
23:06:55.714 [pool-2-thread-3] INFO  c.g.k.cdt.launch.ChromeLauncher - Closing chrome process...
23:06:55.714 [pool-2-thread-3] INFO  c.g.k.cdt.launch.ChromeLauncher - Chrome process closed.
..
..
..
Caused by: com.github.kklisura.cdt.launch.exceptions.ChromeProcessTimeoutException: Failed while waiting for chrome to start: Timeout expired! Chrome output: 
    at java.lang.Throwable.<init>(Throwable.java:265)
    at java.lang.Exception.<init>(Exception.java:66)
    at java.lang.RuntimeException.<init>(RuntimeException.java:62)
    at com.github.kklisura.cdt.launch.exceptions.ChromeProcessException.<init>(ChromeProcessException.java:35)
    at com.github.kklisura.cdt.launch.exceptions.ChromeProcessTimeoutException.<init>(ChromeProcessTimeoutException.java:35)
    at com.github.kklisura.cdt.launch.ChromeLauncher.waitForDevToolsServer(ChromeLauncher.java:346)
    at com.github.kklisura.cdt.launch.ChromeLauncher.launchChromeProcess(ChromeLauncher.java:280)
    at com.github.kklisura.cdt.launch.ChromeLauncher.launch(ChromeLauncher.java:143)
    at com.github.kklisura.cdt.launch.ChromeLauncher.launch(ChromeLauncher.java:157)

this is my launcher code (the only thing different from the example)

        final ChromeLauncher launcher = new ChromeLauncher();
        ChromeArguments args = ChromeArguments.defaults(true)
                .additionalArguments("disable-software-rasterizer", null)
                .additionalArguments("disable-dev-shm-usage", null).build();
        chromeService = launcher.launch(args);

Starting headless chromium works as expected

chromium --no-sandbox --headless --disable-gpu --disable-software-rasterizer --disable-dev-shm-usage  --remote-debugging-port=9222
[1217/230628.349717:ERROR:gpu_process_transport_factory.cc(967)] Lost UI shared context.
Failed to create secure directory (/home/appuser/.config/pulse): No such file or directory

DevTools listening on ws://127.0.0.1:9222/devtools/browser/628c3a40-6646-49d4-bfd5-7e21df027bef

This is the dockerfile I am using it plain debian:stretch with the default chromium. Nothing fancy.

FROM debian:stretch-slim

COPY --from=pdfgenerator /app/pdfgenerator

RUN apt-get update && apt-get install -y \
    chromium \
    fonts-liberation2 \
    fonts-roboto \
    --no-install-recommends \
     && rm -rf /var/lib/apt/lists/*

# Add chromium user
RUN groupadd -r appuser && useradd -r -g appuser -G audio,video appuser \
    && mkdir -p /app/temp && chown -R appuser:appuser /app

USER appuser

ENV CHROME_PATH=/usr/bin/chromium
WORKDIR /app

#ENTRYPOINT ["chromium-browser", "--headless", "--disable-gpu", "--disable-software-rasterizer", "--disable-dev-shm-usage"]
CMD ["./pdfgenerator"]

Maybe you have an idea what it might be, but I'll investigate some more in the following days.

kklisura commented 5 years ago

Hi!

I'm trying to understand your use case. Are you running java application with chromium inside a docker container or are you running just chromium inside a docker container?

Anyhow, the reason launcher is timing out is that it waits for process (chrome) to output DevTools listening on, in order to get the port it's listening on, but that line never occurs.

If you're starting chrome manually (regardless if its docker container or standalone), you can instantiate a new ChromeService as ChromeServiceImpl, just pass it a port or host, if needed (also make sure port you're using is exposed, if you're using docker container`.

Vad1mo commented 5 years ago

I'm trying to understand your use case. Are you running java application with chromium inside a docker container or are you running just chromium inside a docker container?

Yes the java application is running together with chromium in the same container. The java application should start chrome on demand.

Anyhow, the reason launcher is timing out is that it waits for process (chrome) to output DevTools listening on , in order to get the port it's listening on, but that line never occurs.

The question is why? I verified that I can start the chromium inside the container by hand, as seen in the code example. I am not sure why the application fails to do so.

If you're starting chrome manually (regardless if its docker container or standalone), you can instantiate a new ChromeService as ChromeServiceImpl, just pass it a port or host, if needed (also make sure port you're using is exposed, if you're using docker container.

I could try that as an workaround, but I would prefer that the java application controls chrome fully.

I am going to investigate a bit more to find out more about to root cause.