Timeout of 1000 ms exceeded trying to EvaluateFunctionAsync
lofti198 opened this issue · comments
.NET 8 console app, PuppeteerSharp 17.0.0. Loading this webpage https://www.olx.uz/d/obyavlenie/novyy-teplyy-svitshot-ls-vaikiki-ID34mqR.html . Trying to evaluate js, however getting strange exception (js checked in dev console and is correct):
Protocol error(Runtime.callFunctionOn): Target closed. (Connection failed to process Network.requestWillBeSent. Timeout of 1000 ms exceeded. at PuppeteerSharp.Helpers.TaskHelper.WithTimeout[T](Task1 task, TimeSpan timeout, Func
2 exceptionFactory) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Helpers/TaskHelper.cs:line 180
at PuppeteerSharp.Cdp.FrameManager.<>c__DisplayClass58_0.<<Client_MessageReceived>b__0>d.MoveNext() in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Cdp/FrameManager.cs:line 206)
my code below
using var browserFetcher = new BrowserFetcher();
await browserFetcher.DownloadAsync();
var launchOptions = new LaunchOptions
{
// UserDataDir = "C:\\Users\\38097\\Documents\\1Projects\\Puppeteer tests\\cache",
Headless = false,
IgnoredDefaultArgs= new[] {"--disable-extensions"},
SlowMo = 5,
Args = new string[] { }
};
var browser = await Puppeteer.LaunchAsync(launchOptions);
try
{
var page = await browser.NewPageAsync();
// If proxy with authentication
await page.SetViewportAsync(new ViewPortOptions
{
Width = 1920,
Height = 1080
});
await page.GoToAsync("https://www.olx.uz/d/obyavlenie/novyy-teplyy-svitshot-ls-vaikiki-ID34mqR.html",
new NavigationOptions
{
WaitUntil = new WaitUntilNavigation[]
{ WaitUntilNavigation.DOMContentLoaded},
Timeout = timeoutSec * 1000
});
await page.EvaluateFunctionAsync(@"() =>{//alert('hello');
const buttons = document.querySelectorAll('button');
for (let button of buttons)
{
const span = button.querySelector('span');
if (span && span.textContent.trim() === 'Показать телефон')
{
console.log('button found, gonna scroll')
button.scrollIntoView();
button.click();
break;
}
else
{
}
}
return true;
}");
Thank you for the report. I'm on vacation right now. I'll take a look at it on Monday!
Thank you have a great vacation!
!UPDATE! just found that commenting SlowMo fixes issue. However it seems that using it is sometimes important to imitate real user behavior (for example loading websites with cloudflar):
var launchOptions = new LaunchOptions
{
Headless = false,
IgnoredDefaultArgs= new[] {"--disable-extensions"},
// SlowMo = 5,
Args = new string[] { }
};
That helps a lot!