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

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

Closed
fastingsamurai opened this issue Jan 11, 2024 · 3 comments
Closed
Labels

Comments

@fastingsamurai
Copy link

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

AlecBlance commented Mar 22, 2024

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

@AlecBlance
Copy link

AlecBlance commented Mar 22, 2024

After a few hours of digging and testing, the only thing that makes everything work is the flag --disable-dev-shm-usage mentioned here #225 (comment). 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
Copy link
Author

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

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

No branches or pull requests

2 participants