0

I am following the sample "PupppeterSharpAspNetFrameworkSample" (4.7.2). However I cannot get it work. Is is possible to please provide some code or a link on how this word work in a .net core api 2.2?

public class BrowserClient
{
    private static readonly string HostPath = HostingEnvironment.MapPath("~/App_Data/");

    public static async Task<string> GetTextAsync(string url)
    {
        var browserFetcher = new BrowserFetcher(new BrowserFetcherOptions()
        {
            Path = HostPath
        });
        await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision).ConfigureAwait(false);

        using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions()
        {
            Headless = true,
            ExecutablePath = browserFetcher.GetExecutablePath(BrowserFetcher.DefaultRevision)
        }).ConfigureAwait(false))
        using(var page = await browser.NewPageAsync().ConfigureAwait(false))
        {
            var response = await page.GoToAsync(url).ConfigureAwait(false);
            return await response.TextAsync().ConfigureAwait(false);
        }
    }
}

}

The error it throws is

{"Message":"An error has occurred.","ExceptionMessage":"Failed to create connection","ExceptionType":"PuppeteerSharp.ChromiumProcessException","StackTrace":"   at PuppeteerSharp.Launcher.<LaunchAsync>d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at PuppeteerSharp.Launcher.<LaunchAsync>d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()\r\n   at PupppeterSharpAspNetFrameworkSample.Services.BrowserClient.<GetTextAsync>d__1.MoveNext() in D:\\development\\screenscraping\\puppeteer-sharp\\samples\\PupppeterSharpAspNetFrameworkSample\\PupppeterSharpAspNetFrameworkSample\\Services\\BrowserClient.cs:line 20\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__1`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()","InnerException":{"Message":"An error has occurred.","ExceptionMessage":"Protocol error(Target.setDiscoverTargets): Target closed. (An internal WebSocket error occurred. Please see the innerException, if present, for more details. )","ExceptionType":"PuppeteerSharp.TargetClosedException","StackTrace":"   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()\r\n   at PuppeteerSharp.Connection.<SendAsync>d__34.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()\r\n   at PuppeteerSharp.Browser.<CreateAsync>d__73.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()\r\n   at PuppeteerSharp.Launcher.<LaunchAsync>d__7.MoveNext()"}}
rizan
  • 339
  • 1
  • 3
  • 16
  • 1
    Do you have an `~/App_Data/` in your Core app? – hardkoded May 20 '19 at 14:32
  • Which line is failing? And could you provide us with a more readable stacktrace rather than some JSON output. – Henk Mollema May 20 '19 at 14:34
  • @hardkoded yes there is an ~/App_Data folder, however I noticed this error "\\puppeteer-sharp\\samples\\PupppeterSharpAspNetFrameworkSample\\PupppeterSharpAspNetFrameworkSample\\App_Data\\download-Win64-656675.zip' because it is being used by another process" – rizan May 20 '19 at 17:18
  • It's working now - if I run it out of the vs debugger - it works. thanks for the assistance. – rizan May 20 '19 at 17:23

0 Answers0