Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout of 1000 ms exceeded trying to EvaluateFunctionAsync #2659

Open
lofti198 opened this issue Jun 16, 2024 · 3 comments
Open

Timeout of 1000 ms exceeded trying to EvaluateFunctionAsync #2659

lofti198 opened this issue Jun 16, 2024 · 3 comments

Comments

@lofti198
Copy link

.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, Func2 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;
}");

@kblok
Copy link
Member

kblok commented Jun 16, 2024

Thank you for the report. I'm on vacation right now. I'll take a look at it on Monday!

@lofti198
Copy link
Author

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[] { }

};

@kblok
Copy link
Member

kblok commented Jun 16, 2024

That helps a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants