hardkoded / puppeteer-sharp

Headless Chrome .NET API
https://www.puppeteersharp.com
MIT License
3.25k stars 435 forks source link

ConnectAsync function is stuck when connecting to the wsEndpoint #2098

Open yeucodonvn opened 1 year ago

yeucodonvn commented 1 year ago

Infomation

PuppeteerSharp: 9.0.2 windows 10 x64 visual studio 2022

Description

When I initialize a browser using the command browser = await PuppeteerSharp.Puppeteer.ConnectAsync(options), the command does not stop running until I have to stop the debugging process E.g. this is Connect function

private IBrowser browser = null;
private IPage page = null;
public async Task<bool> Connect(string wsEnpoint)
    {
        try
        {
            //wsEnpoint = "ws://127.0.0.1:2000/devtools/browser/10ae2bcd-f539-49d6-983e-e5294f3c8b52";
            var options = new ConnectOptions()
            {
                BrowserWSEndpoint = wsEnpoint,
            IgnoreHTTPSErrors = true         
            };

            browser = await PuppeteerSharp.Puppeteer.ConnectAsync(options);

            // Create a new page and go to Bing Maps

            page = browser.NewPageAsync().Result;
            qr = new PuppeteerQuery(page);
            return true;
        }
        catch (Exception ex)
        {
            cl.Log(ex);
            return false;
        }
    }

this is

private async Task loop()
{
ParallelOptions po = new ParallelOptions();
po.CancellationToken = cts.Token;

po.MaxDegreeOfParallelism = Convert.ToInt32(MyIni.Read("threadnum"));
Parallel.ForEach(listacc, po, async (acc, state, i) =>
{
         ChromeBr y = new ChromeBr ();
         bool build_stt = await y.Build(wws);
         if (build_stt)
         {
             await y.start();
         }
}
}

Expected behavior:

[What you expect to happen]

Actual behavior:

[What actually happens]

Versions

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

kblok commented 1 year ago

What do you mean with the command does not stop running?

yeucodonvn commented 1 year ago

What do you mean with the command does not stop running?

I run it with visual studio debug, and the program keeps at that line, I put try catch but the command doesn't stop so I can't catch any exception

kblok commented 1 year ago

Can you isolate the code into something I can run locally?