hardkoded / puppeteer-sharp

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

ClickAsync Timeout #2779

Closed merco closed 2 months ago

merco commented 2 months ago

I've a page with

page.ClickAsync("#__button12" );

The script runs ok but it takes very long time to complete. So i'm getting this error:

immagine

Is there a way to avoid timeout?

kblok commented 2 months ago

That's odd. That's the browser not responding. If you run that in headful mode, do you see the browser getting stuck? high CPU usage?

merco commented 2 months ago

in headful mode runs without problems

merco commented 2 months ago

Other error in headless mode

immagine

kblok commented 2 months ago

Other error in headless mode

immagine

It looks like an error on a Console event listener you have?

merco commented 2 months ago

It looks like an error on a Console event listener you have?

I'm using always the same input and yes I have a Page_Console event handler but why sometimes runs ok and sometimes not? Even with the same input?

immagine

kblok commented 2 months ago

It looks like an error on a Console event listener you have?

I'm using always the same input and yes I have a Page_Console event handler but why sometimes runs ok and sometimes not? Even with the same input?

immagine

Do you have a dictionary where you are collecting info? Maybe a race condition? Console events don't come always at the same time.

kblok commented 2 months ago

Can you also check if, by removing the event, the click stops getting stuck? Maybe is the listener that's breaking the flow.

merco commented 2 months ago

Oh yes I have list and dict .. how can avoid events not in same time?

void Page_Console(object? sender, ConsoleEventArgs e)
{
     if (e.Message.Type == ConsoleType.Log)
    {
        if (e.Message.Text.StartsWith("scene._scene.traverse.end"))
        {
            structMode = false;
            return;
       }

        if (structMode)
        {
            if (rootNode==null)
            {
                rootNode= new NodeObj();
                rootNode = Newtonsoft.Json.JsonConvert.DeserializeObject<NodeObj>(e.Message.Text);
                lastNode= rootNode; 
            } else
            {
                NodeObj thisNode = Newtonsoft.Json.JsonConvert.DeserializeObject<NodeObj>(e.Message.Text);
                NodeObj pNode = NodeList[thisNode.ParentId];
                pNode.Items.Add(thisNode);
                lastNode = thisNode;

            }

            if (MeshList.ContainsKey(lastNode.Id))
            {
                lastNode.Mesh= MeshList[lastNode.Id];
            }
            JSObjectIndex = JSObjectIndex + 1;
            Console.WriteLine("Traversing scene " + JSObjectIndex.ToString() + "/" + JSObjectCount.ToString());
            PushNode(lastNode);
            return;
        }

        if (e.Message.Text.StartsWith("Processing file") && e.Message.Text.Contains("finished"))
        {
            loaded3D = true;
            return;
        }
        if (e.Message.Text.StartsWith("scene._scene.traverse.start"))
        {
            structMode = true;
            JSObjectCount = System.Convert.ToInt64( e.Message.Text.Replace("scene._scene.traverse.start:", ""));
            return;

        }

        if (e.Message.Text.StartsWith("{\"AAXX\":\"C@MER@\""))
        {
            CameraObj deserializedCam = Newtonsoft.Json.JsonConvert.DeserializeObject<CameraObj>(e.Message.Text);
            CameraList.Add(deserializedCam);
            Console.WriteLine("Lettura Camera " + deserializedCam.Name);
        }
        if (e.Message.Text.StartsWith("{\"AAXX\":\"ME$H\""))
        {

            MeshObj deserializedProduct = Newtonsoft.Json.JsonConvert.DeserializeObject<MeshObj>(e.Message.Text);
            MeshList.Add(deserializedProduct.Id,deserializedProduct);
            Console.WriteLine("Lettura Mesh " + deserializedProduct.PROG);

        }

    }

}
kblok commented 2 months ago

.. how can avoid events not in same time?

You can't trust the order in which the browser sends messages.

merco commented 2 months ago

Same code in debug IDE (VS2022) runs wothout errors, and same code in release mode (SOMETIMES ) works (SOMETIMES also with headless=true)

after some changes in code... remains

immagine

I'm using c# project to read from console.log objects that are serialized in the click event of an html button.

merco commented 2 months ago

How can I increase this timeout ?

immagine

kblok commented 2 months ago

You can increase it by setting the ProtocolTimeout