puppeteer-sharp icon indicating copy to clipboard operation
puppeteer-sharp copied to clipboard

ConnectAsync function is stuck when connecting to the wsEndpoint

Open yeucodonvn opened this issue 2 years ago • 4 comments

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

  • Which version of PuppeteerSharp are you using?
  • Which .NET runtime and version are you targeting? E.g. .NET framework 4.6.1 or .NET Core 2.0.

Additional Information

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

yeucodonvn avatar Mar 03 '23 14:03 yeucodonvn

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

kblok avatar Mar 03 '23 14:03 kblok

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

yeucodonvn avatar Mar 03 '23 14:03 yeucodonvn

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

kblok avatar Mar 24 '23 12:03 kblok

I have the same issue connecting to chromium V9x of Raspbian Buster. Hangs forever on ConnectAsync, no exception, except I close the browser. V11x of Bulseye and Windows Chrome/Edge worked, probably even never. Chrome DevTools can connect to V9x Buster. Obviously Buster is old now... will see

iwl avatar Feb 15 '25 02:02 iwl

I Encountered a similiar issue with an instance of Electron and dug a bit deeper. It seems to me that there are some instances in the _targetsIdsForInit of the ChromeTargetManager that are left unanswered as there is no response by the browser - or in my case electron - to the cdp command Target.setAutoAttach which is used to determine whether the initialization has been finished. So from the perspective of the target manager the initialization process did not run to completion. what is even more confusing to me, is that this only seems to be the case for page targets and when they are filtered out it works without any issue, eventhough at least from what the debugger shows me the TargetInfo has the Attached property set to true. But it is totally possible that I am just missing something here.

DSinMeliodas avatar Oct 02 '25 18:10 DSinMeliodas