I am trying to navigate a page and then I would like to access some page elements but I got those errors which I sated below. I shared my code below, you can try it. How can I solve this issue?
Puppeteersharp Version: 2.0.3 Operation System: Windows 10 .Net Library: .Net Core 3.1
class Program
{
static async Task Main(string[] args)
{
try
{
var page = await GetPageInstance(GetOptions());
try
{
await page.GoToAsync("https://www.kijk.nl/", new NavigationOptions { WaitUntil = new WaitUntilNavigation[] { WaitUntilNavigation.Load, WaitUntilNavigation.Networkidle2 } });
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
var possibleCookieAcceptElements = await page.QuerySelectorAllAsync("button");
Console.Read();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private static LaunchOptions GetOptions()
{
return new LaunchOptions
{
Headless = false,
Timeout = 0,
ExecutablePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
Args = new string[] {
"--no-sandbox",
"--disable-notifications",
"--disable-dev-shm-usage",
"--disable-setuid-sandbox",
"--lang=en-US,en-GB,en",
},
Devtools = false,
IgnoreHTTPSErrors = true,
DumpIO = false
};
}
public static async Task<Page> GetPageInstance(LaunchOptions options)
{
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
var browser = await Puppeteer.LaunchAsync(options);
var page = await browser.NewPageAsync();
return page;
}
}
Error Message that I got for the inner catch block:
Navigation failed because browser has disconnected! (NetworkManager failed to process Network.requestWillBeSent. Value cannot be null. (Parameter 'key'). at System.Collections.Concurrent.ConcurrentDictionary2.ThrowKeyNullException() at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at PuppeteerSharp.Helpers.MultiMap2.Add(TKey key, TValue value) at PuppeteerSharp.Helpers.AsyncDictionaryHelper`2.GetItemAsync(TKey key) at PuppeteerSharp.NetworkManager.OnRequestAsync(RequestWillBeSentPayload e, String interceptionId) at PuppeteerSharp.NetworkManager.OnRequestWillBeSentAsync(RequestWillBeSentPayload e) at PuppeteerSharp.NetworkManager.Client_MessageReceived(Object sender, MessageEventArgs e))
Error Message that I got for the outer catch block:
Protocol error (Runtime.evaluate): Session closed. Most likely the Page has been closed.Close reason: NetworkManager failed to process Network.requestWillBeSent. Value cannot be null. (Parameter 'key'). at System.Collections.Concurrent.ConcurrentDictionary2.ThrowKeyNullException() at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at PuppeteerSharp.Helpers.MultiMap2.Add(TKey key, TValue value) at PuppeteerSharp.Helpers.AsyncDictionaryHelper`2.GetItemAsync(TKey key) at PuppeteerSharp.NetworkManager.OnRequestAsync(RequestWillBeSentPayload e, String interceptionId) at PuppeteerSharp.NetworkManager.OnRequestWillBeSentAsync(RequestWillBeSentPayload e) at PuppeteerSharp.NetworkManager.Client_MessageReceived(Object sender, MessageEventArgs e)