hardkoded/puppeteer-sharp

Exception:System.TimeoutException: Timeout of 180000 ms exceeded at PuppeteerSharp.Helpers.TaskHelper on await page.PdfAsync

AlexMata260 opened this issue · 4 comments

Description

The code below is working fine in my local development environment. It creates the PDF without issue. However when the project is published and loaded to the application server, there is a timeout exception thrown at "await page.PdfAsync" and throws the following error:

Error in method:

Exception:System.TimeoutException: Timeout of 180000 ms exceeded at PuppeteerSharp.Helpers.TaskHelper.d__81.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at PuppeteerSharp.Cdp.CdpCDPSession.d__13.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at PuppeteerSharp.CDPSession.d__341.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at PuppeteerSharp.Cdp.CdpPage.d__88.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at PuppeteerSharp.Page.d__203.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at

My code:

var browserFetcher = new BrowserFetcher();
var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true, ExecutablePath = Globals.ChromeExecutable });

var page = await browser.NewPageAsync();
await page.GoToAsync(pageURL);
await page.PdfAsync(fullPath, new PdfOptions() { Format = PaperFormat.Letter, PrintBackground = true, Scale = 0.8M, MarginOptions = new MarginOptions() { Top = "40px", Right = "30px", Bottom = "20px", Left = "30px" } });

await browser.CloseAsync();

Expected behavior:

Expecting a PDF to be created in a specified directory.

Actual behavior:

Exception error timeout.

Versions

We are using PuppeteerSharp version 20.0.2 Nuget Package.
.NET Framework 4.8

That's a problem with Chrome 127+. The issue is documented here

Could you check if adding Args = new[] { "--no-sandbox" } helps?

Adding Args = new[] { "--no-sandbox" } to the Launch Options did it ! Thank You Man!

For anyone wondering, in case you need reference here it is:

var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true, ExecutablePath = Globals.ChromeExecutable, Args = new[] { "--no-sandbox" } });

I have the same issue but --no-sandbox only helped in my development environment (Windows 10), but I still have the same issue when generating PDFs in the release environment (Windows Server 2022)