Zenika / alpine-chrome

Chrome Headless docker images built upon alpine official image
https://hub.docker.com/r/zenika/alpine-chrome
Apache License 2.0
1.78k stars 239 forks source link

Chrome hangs when taking a screenshot of a page with a large image #240

Closed fastingsamurai closed 4 months ago

fastingsamurai commented 6 months ago

Describe the bug When capturing a screenshot of an HTML page with a large jpeg image in it, instead of capturing a screenshot, Chrome will hang and refuse to respond to any further commands. This does not happen when running the same commands on the host OS, this is only reproducible in the alpine-chrome Docker container.

To Reproduce

  1. Unzip included chrome-bug.zip file on system with docker installed
  2. Run docker compose build ; docker compose up

chrome-bug.zip

What is the expected behavior?

The line "Screenshot captured" will eventually be printed to the console

What is the actual behavior?

Chrome will hang at some point in the loading process or when trying to take the screenshot itself. Once this happens the Chrome process seems to become totally unresponsive to any command sent by the remote interface.

Additional context

If you edit the page.html file and change "large.jpg" to "small.jpg", the script runs as expected. This issue only seems to happen when viewing larger images, around 1MB or greater.

This bug happens both on ARM and x64.

AlecBlance commented 4 months ago

Experienced this as well. Do you have a fix now?

AlecBlance commented 4 months ago

After a few hours of digging and testing, the only thing that makes everything work is the flag --disable-dev-shm-usage mentioned here https://github.com/Zenika/alpine-chrome/issues/225#issue-1639376911. It was because /dev/shm partition is too small in some VMs, causing Chrome to crash. Thanks to @sfcgeorge for documenting the flags.

So in your code the changes should be

spawn(
  "/usr/bin/chromium-browser",
  [
    "--headless",
    "--no-sandbox",
    "--remote-debugging-address=0.0.0.0",
    "--remote-debugging-port=9222",
+   "--disable-dev-shm-usage",
    "about:blank",
  ],
  {
    detached: true,
  }
);

image

fastingsamurai commented 4 months ago

Amazing!! Thank you so much! You're awesome!