hardkoded / puppeteer-sharp

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

Not working under Windows Service #2582

Open TejasPatadiya10 opened 2 months ago

TejasPatadiya10 commented 2 months ago

If we use puppeteer-sharp with console app its working fine

but when we use it with Windows Service we are getting below exception with LaunchAsync

System.AggregateException: One or more errors occurred. (Failed to create connection) ---> PuppeteerSharp.ProcessException: Failed to create connection ---> PuppeteerSharp.TargetClosedException: Protocol error(Target.setDiscoverTargets): Target closed. (The remote party closed the WebSocket connection without completing the close handshake.) at PuppeteerSharp.Helpers.TaskHelper.WithTimeout[T](Task1 task, TimeSpan timeout, Func2 exceptionFactory) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Helpers/TaskHelper.cs:line 183 at PuppeteerSharp.Connection.SendAsync(String method, Object args, Boolean waitForCallback, CommandOptions options) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Connection.cs:line 138 at PuppeteerSharp.ChromeTargetManager.InitializeAsync() in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/ChromeTargetManager.cs:line 61 at PuppeteerSharp.Browser.CreateAsync(SupportedBrowser browserToCreate, Connection connection, String[] contextIds, Boolean ignoreHTTPSErrors, ViewPortOptions defaultViewPort, LauncherBase launcher, Func2 targetFilter, Func2 isPageTargetCallback, Action1 initAction) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Browser.cs:line 304 at PuppeteerSharp.Browser.CreateAsync(SupportedBrowser browserToCreate, Connection connection, String[] contextIds, Boolean ignoreHTTPSErrors, ViewPortOptions defaultViewPort, LauncherBase launcher, Func2 targetFilter, Func2 isPageTargetCallback, Action1 initAction) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Browser.cs:line 309 at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Launcher.cs:line 74 --- End of inner exception stack trace --- at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Launcher.cs:line 92 at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Launcher.cs:line 98

We have make sure that we are using it with proper awaits as its working fine with console app,

Besides this if we are using --no-sandbox then its working fine with windows service. but we read the documentation and came to know that using this args is not recommended.

so please suggest any other way to run it under windows service.

gabmilg commented 3 weeks ago

We have a similar issue (when app is running as a service) but with PDF generation: await page.PdfStreamAsync(...) throws: System.TimeoutException: Timeout of 180000 ms exceeded at PuppeteerSharp.Helpers.TaskHelper.WithTimeout[T](Task1 task, TimeSpan timeout, Func2 exceptionFactory) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Helpers/TaskHelper.cs:line 185 at PuppeteerSharp.Cdp.CdpCDPSession.SendAsync(String method, Object args, Boolean waitForCallback, CommandOptions options) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Cdp/CdpCDPSession.cs:line 112 at PuppeteerSharp.CDPSession.SendAsync[T](String method, Object args, CommandOptions options) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/CDPSession.cs:line 44 at PuppeteerSharp.Cdp.CdpPage.PdfInternalAsync(String file, PdfOptions options) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Cdp/CdpPage.cs:line 829 at PuppeteerSharp.Page.PdfStreamAsync(PdfOptions options) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Page.cs:line 390

gabmilg commented 3 weeks ago

After some research it appears that this was broken since v15.0 : The Issue: PDF generation throws Timeout Exception when application is running as windows service.