When I load a web page that contains async functions using PuppeteerSharp, the code within the async functions never runs (or is not awaited, I'm not sure which)
C# code:
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultChromiumRevision);
var url = $"http://127.0.0.1:8080/?code={code}&id={id}";
var file = "C:\\temp\\test3.jpg";
var launchOptions = new LaunchOptions()
{
Headless = true
};
var navOptions = new NavigationOptions
{
WaitUntil = new [] { WaitUntilNavigation.Networkidle0 }
};
using (var browser = await Puppeteer.LaunchAsync(launchOptions))
using (var page = await browser.NewPageAsync())
{
await page.GoToAsync(url, navOptions);
await page.WaitForSelectorAsync(".complete"); // This times out
await page.ScreenshotAsync(file);
}
Javascript code:
onmount = () => {
const params = new URLSearchParams(document.location.search);
const code = params.get('code');
// search is an async function (not included here for brevity)
search(code).then(result => {
this.el.classList.add('complete'); // not executed
this.updateTitle(result.name);
});
};
The async javascript works as expected in the browser, but not via Puppeteer / Chromium
Does anyone know why this might be?
When I ran puppeteer as non headless and inspected the page, I was getting an ERR_CERT_AUTHORITY_INVALID Error caused by an api call. All sorted now.