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

Not working under Windows Service

Open TejasPatadiya10 opened this issue 1 year ago • 2 comments

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.

TejasPatadiya10 avatar Apr 03 '24 13:04 TejasPatadiya10

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 avatar Jun 06 '24 18:06 gabmilg

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.

gabmilg avatar Jun 07 '24 14:06 gabmilg

I am also having issues with this. After updating from 17.0.0, our app has stalled on the same method, page.PdfStreamAsync. However, I have only seen this issue when code is run on the server. When doing local development in Visual Studio, v18.0.2 appears to be working fine.

bkbartonDesign avatar Jul 03 '24 16:07 bkbartonDesign

Ok. I'm rolling the browser back

kblok avatar Jul 03 '24 16:07 kblok

Can confirm this is broken on v126 of Chromium when running as a Windows Service. Using --no-sandbox does fix this and unfortunately seems the way to go if you need to use a fixed BrowserExecutable.

KyrumX avatar Jul 22 '24 14:07 KyrumX

Browser was rolled back

kblok avatar Jul 22 '24 14:07 kblok

Hey folks! I'm looking for volunteers to test PuppeteerSharp 18.1.0-beta1. This new version is using Chrome 127 which provides a new way to setup the browser by calling its setup.exe file.

kblok avatar Aug 05 '24 16:08 kblok

Same problem here with 19.1 and edge browser (unfortunatelly chrome is no option here

ChristophKrause avatar Aug 21 '24 11:08 ChristophKrause

Same problem here with 19.1 and edge browser (unfortunatelly chrome is no option here

How are you installing the browser?

kblok avatar Aug 21 '24 12:08 kblok

I use preinstalled edge

ChristophKrause avatar Aug 21 '24 19:08 ChristophKrause