puppeteer-sharp icon indicating copy to clipboard operation
puppeteer-sharp copied to clipboard

PuppeteerSharp.ProcessException: Timed out after 30000 ms while trying to connect to Base!

Open salmanelahi93 opened this issue 7 months ago • 9 comments

PuppeteerSharp for generating PDFs is not working in Windows Server 2022 Standard. It was working for 6 months before, but it has stopped working in the last few days.

I'm using dot net core. PuppeteerSharp is generating PDF in my local machine fine, but it's not generating on VPS (Windows Server 2022) and giving the error:

PuppeteerSharp.ProcessException: Timed out after 30000 ms while trying to connect to Base!

Following is my code snippet:

public async Task ConvertHtmlToPdfAsync(string path, string html)
{
    try
    {
        using var browser = await Puppeteer.LaunchAsync(new LaunchOptions
        {
            Headless = true,
            ExecutablePath = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
            Args = new[]
            {
                "--no-sandbox",
                "--disable-setuid-sandbox"
            },
        });

        using var page = await browser.NewPageAsync();
        await page.SetContentAsync(html);

        await page.PdfAsync(path, new PdfOptions
        {
            Format = PaperFormat.A4
        });
    }
    catch (Exception ex)
    {
        _logger.LogError(ex.Message);
        _logger.LogError(ex.StackTrace);
        throw;
    }
}

salmanelahi93 avatar May 04 '25 11:05 salmanelahi93

Got the same error here.

wilsonbredaneto avatar May 05 '25 13:05 wilsonbredaneto

Same issue

npenza-fc avatar May 06 '25 00:05 npenza-fc

Looks like it is an issue with the new version of Chrome 136.X.

We reverted to 132.0.6834.111 - working now.

Edit: Chrome 135.X also works.

npenza-fc avatar May 06 '25 00:05 npenza-fc

Thanks @npenza-fc .. it's working after downgrading the Google Chrome.

salmanelahi93 avatar May 06 '25 08:05 salmanelahi93

This is why it is not working: https://developer.chrome.com/blog/remote-debugging-port FIX:

var browser = await Puppeteer.LaunchAsync(new LaunchOptions { 
                    Headless = true,
                    ExecutablePath = "PATH_TO_CHROME", 
                    UserDataDir= Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())})

Add "UserDataDir" to random folder, or any specific folder

krizda avatar May 09 '25 12:05 krizda

I have this issue with Chrome 136.0.7103.93 on 2 servers but on a third it works fine. Thank you for your fix which I will try, but I am curious - is there any reason why it may work sometimes without the fix?

alecjames avatar May 09 '25 14:05 alecjames

I have this issue with Chrome 136.0.7103.93 on 2 servers but on a third it works fine. Thank you for your fix which I will try, but I am curious - is there any reason why it may work sometimes without the fix?

You probably dont have 136 on the third server. Chrome made it a security issue, and setting user folder makes it, so that autonomous chrome workers cant access normal user data like passwords etc

krizda avatar May 09 '25 14:05 krizda

I copied the version string 136.0.7103.93 from the 3rd server log file, the app fetches it from chrome and its this version read that fails on the other 2 servers - they throw a process exception with the time out. It will be puzzling till I find out why :)

alecjames avatar May 09 '25 14:05 alecjames

I copied the version string 136.0.7103.93 from the 3rd server log file, the app fetches it from chrome and its this version read that fails on the other 2 servers - they throw a process exception with the time out. It will be puzzling till I find out why :)

On my DEV server, the Application Pool’s Advanced Settings → Load User Profile was set to True, whereas on TEST it was False. From my logs, I can see that under both settings, the application itself has read/write access to the specified user-data directory. However, when the App Pool isn't loading the full user profile, the spawned Chrome process seems unable to read from or write to the user-data directory. It throws the same exception I encountered when no userDataDir was specified— Timed out after 30000 ms while trying to connect to Base! i.e., Chrome 136 fails to access its data directory when running headless.

Enabling Load User Profile on my TEST server resolves the issue for me.

alecjames avatar May 19 '25 12:05 alecjames