hardkoded / puppeteer-sharp

Headless Chrome .NET API
https://www.puppeteersharp.com
MIT License
3.36k stars 440 forks source link

NewPageAsync hangs up with .NET 8 #2715

Closed michael-eckhart-woellkart closed 2 months ago

michael-eckhart-woellkart commented 2 months ago

Description

We use puppeteer to generate PNG, which works quite good. But after updating from .NET 7 to .NET 8 it stopped working. The app runs in a linux docker container based on the "mcr.microsoft.com/dotnet/aspnet:8.0" image. I enabled the dump an see a endless loop in the log:

[152:187:0730/084147.843252:ERROR:gpu_channel.cc(823)] GpuChannel: Failed to create SharedImageStub [152:187:0730/084147.843310:ERROR:check.cc(376)] Check failed: false. NOTREACHED log messages are omitted in official builds. Sorry! [152:187:0730/084147.843323:ERROR:gpu_channel_manager.cc(957)] Failed to create GLES3 context, fallback to GLES2. [152:187:0730/084147.843327:ERROR:check.cc(376)] Check failed: false. NOTREACHED log messages are omitted in official builds. Sorry! [152:187:0730/084147.843332:ERROR:gpu_channel_manager.cc(968)] ContextResult::kFatalFailure: Failed to create shared context for virtualization. [152:187:0730/084147.843336:ERROR:shared_image_stub.cc(676)] SharedImageStub: unable to create context [152:187:0730/084147.843340:ERROR:gpu_channel.cc(823)] GpuChannel: Failed to create SharedImageStub [152:187:0730/084147.843362:ERROR:check.cc(376)] Check failed: false. NOTREACHED log messages are omitted in official builds. Sorry! [152:187:0730/084147.843369:ERROR:gpu_channel_manager.cc(957)] Failed to create GLES3 context, fallback to GLES2. [152:187:0730/084147.843372:ERROR:check.cc(376)] Check failed: false. NOTREACHED log messages are omitted in official builds. Sorry! [152:187:0730/084147.843377:ERROR:gpu_channel_manager.cc(968)] ContextResult::kFatalFailure: Failed to create shared context for virtualization. [152:187:0730/084147.843381:ERROR:shared_image_stub.cc(676)] SharedImageStub: unable to create context [152:187:0730/084147.843385:ERROR:gpu_channel.cc(823)] GpuChannel: Failed to create SharedImageStub [152:187:0730/084147.843445:ERROR:check.cc(376)] Check failed: false. NOTREACHED log messages are omitted in official builds. Sorry! [152:187:0730/084147.843457:ERROR:gpu_channel_manager.cc(957)] Failed to create GLES3 context, fallback to GLES2. [152:187:0730/084147.843461:ERROR:check.cc(376)] Check failed: false. NOTREACHED log messages are omitted in official builds. Sorry! [152:187:0730/084147.843466:ERROR:gpu_channel_manager.cc(968)] ContextResult::kFatalFailure: Failed to create shared context for virtualization. [152:187:0730/084147.843470:ERROR:shared_image_stub.cc(676)] SharedImageStub: unable to create context [152:187:0730/084147.843475:ERROR:gpu_channel.cc(823)] GpuChannel: Failed to create SharedImageStub [152:187:0730/084147.843503:ERROR:check.cc(376)] Check failed: false. NOTREACHED log messages are omitted in official builds. Sorry! [152:187:0730/084147.843511:ERROR:gpu_channel_manager.cc(957)] Failed to create GLES3 context, fallback to GLES2. [152:187:0730/084147.843515:ERROR:check.cc(376)] Check failed: false. NOTREACHED log messages are omitted in official builds. Sorry!

Complete minimal example reproducing the issue

The code just hangs up in the line "page = await browser.NewPageAsync().ConfigureAwait(false);" and never completes.

E.g.

_logger.LogError("Test 5.1");
var options = new LaunchOptions
{
    DumpIO = true,
    HeadlessMode = HeadlessMode.True,
    IgnoreHTTPSErrors = true,
    Args = new string[] { "--single-process", "--no-zygote", "--no-sandbox", "--disable-setuid-sandbox", "--disable-infobars", "--ignore-ICertificatePolicy-errors", "--allow-file-access-from-file", "--proxy-server=\"direct://\"", "--proxy-bypass-list=*" },
    ExecutablePath = _executablePath,
    Devtools = false
};
var browser = await Puppeteer.LaunchAsync(options).ConfigureAwait(false);
_logger.LogError("Test 5.2");
ChildProcessTracker.AddProcess(browser.Process);
_logger.LogError("Test 5.3");
page = await browser.NewPageAsync().ConfigureAwait(false);
_logger.LogError("Test 5.4");
page.Request += Page_Request;
_logger.LogError("Test 5.5");
await page.SetRequestInterceptionAsync(true);
_logger.LogError("Test 5.6");
await page.SetJavaScriptEnabledAsync(false);
_logger.LogError("Test 5.7");
await page.GoToAsync(_blankFileUrl);
_logger.LogError("Test 5.8");
_logger.LogInformation("New chrome process started!");
``

Versions

michael-eckhart-woellkart commented 2 months ago

It works if I use the google-chrome and not the chromium browser on linux

kblok commented 2 months ago

It's not the first time I've heard about that. Were you using a chromium version that you manually downloaded?

michael-eckhart-woellkart commented 2 months ago

It seems that the new debian version has a different chromium version that has a bug. I installed the newst version manually and it works now again.

kemmis commented 2 months ago

@michael-eckhart-woellkart What version of chromium or google chrome is working for your? I think I'm having the same issue. I've been installing chromium in dockerfile like this:

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

And this week I started getting a timeout exception when calling browser.NewPageAsync(). Can you share what's working for you?

michael-eckhart-woellkart commented 1 month ago

@kemmis I use now:

RUN echo 'deb http://deb.debian.org/debian bullseye main' > /etc/apt/sources.list RUN apt-get install -y --no-install-recommends chromium -t bullseye

So, for now i use the old version again. I also added "ConfigureAwait(false);" on the "Puppeteer.LaunchAsync" and "browser.NewPageAsync()" function.

kemmis commented 1 month ago

@michael-eckhart-woellkart are you using bookworm or do you have a way to set your base docker image to bullseye?

kemmis commented 1 month ago

I was finally able to downgrade chromium to the older version available to Debian 12 (bookworm).

I had to see what version was available using apt policy chromium. Then install the older chromium-common package, and then the old chromium package:

RUN apt update && \
    apt install chromium-common=121.0.6167.139-1~deb12u1 -y && \
    apt install chromium=121.0.6167.139-1~deb12u1 -y --no-install-recommends

This fixed the NewPageAsync issue for me.

kemmis commented 3 weeks ago

So chromium 121 went away on the debian package feed. And I've had no luck getting things working using newer chromium versions. So I ended up switching to using google chrome instead. And it seems to be working great now.

Installed it in my dockerfile like this:

RUN apt-get update
RUN apt-get install -y wget
RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt-get install -y ./google-chrome-stable_current_amd64.deb --fix-missing

Then set the executable path in my pup# code like this: ExecutablePath = "/usr/bin/google-chrome-stable"