I've got a PuppeteerSharp function in my app that automates this website: https://dtucalculator.azurewebsites.net/
The goal is to fill out the form, by providing a CPU core value and a CSV with performance data (generated prior to this function) and then submit the form, capturing the resulting report as a PDF.
The function looks a little bit like this:
//Browserless Browser
var connectOptions = new ConnectOptions() { BrowserWSEndpoint = "wss://chrome.browserless.io?token=APITOKEN" };
var browser = await Puppeteer.ConnectAsync(connectOptions);
//Local Browser
//await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
//browser = await Puppeteer.LaunchAsync(new LaunchOptions() { Headless = true });
var page = (await browser.PagesAsync())[0];
var viewPortOptions = new ViewPortOptions
{
Height = 1080,
Width = 1920
};
await page.SetViewportAsync(viewPortOptions);
var options = new NavigationOptions
{
Timeout = 0,
WaitUntil = new[] { WaitUntilNavigation.Networkidle2 }
};
await page.GoToAsync("https://dtucalculator.azurewebsites.net/", options);
ElementHandle coresInput = await page.WaitForSelectorAsync("#cores");
await page.TypeAsync("#cores", (CoresPerSocket * SocketCount).ToString());
ElementHandle fileUploadInput = await page.WaitForSelectorAsync("#fileUpload");
await fileUploadInput.UploadFileAsync(filePath);
try
{
await page.ClickAsync(".btn-success");
}
catch (Exception ex)
{
//Log Error here
}
Thread.Sleep(150);
await page.ClickAsync("#details");
Thread.Sleep(1500);
byte[] pdfBytes = await page.PdfDataAsync(new PdfOptions
{
Format = PaperFormat.A4,
MarginOptions = new MarginOptions { Left = "1cm", Right = "1cm", Top = "1cm", Bottom = "1cm" },
});
await page.CloseAsync();
await browser.CloseAsync();
return pdfBytes;
The function works perfectly when I use the local browser, but errors when I use the Browserless connection. The Browserless connection is required when my app is deployed into my Azure app service.
The Target Crashed Exception is produced when PuppeteerSharp clicks on the calculate button, seen wrapped in the try-catch. The details I get from the error message are as follows:
Page failed to process Inspector.targetCrashed. Exception of type 'PuppeteerSharp.TargetCrashedException' was thrown.. at PuppeteerSharp.Page.OnTargetCrashed() at PuppeteerSharp.Page.Client_MessageReceived(Object sender, MessageEventArgs e)
and
Protocol error(Runtime.callFunctionOn): Target closed. (Page failed to process Inspector.targetCrashed. Exception of type 'PuppeteerSharp.TargetCrashedException' was thrown.. at PuppeteerSharp.Page.OnTargetCrashed() at PuppeteerSharp.Page.Client_MessageReceived(Object sender, MessageEventArgs e))
I've contacted Browserless and they don't believe that the issue lies with them - so I am stumped as to what is causing this issue, given the different behaviour between to the two browser sources. Has anyone encountered an issue like this or understand more about what the underlying cause might be?