hardkoded / puppeteer-sharp

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

await e.Request.ContinueAsync(Payload) will cause the page hanging, How can I solve it? #2776

Open phoenix1630 opened 3 weeks ago

phoenix1630 commented 3 weeks ago

Use await e.Request.ContinueAsync(Payload) will cause the page to freeze and remain in a "pending" state, but using await e.Request.ContinueAsync() can be used normally

My Code:

        page.Request += async (sender, e) =>
        {
            // 检查请求的类型和 URL,确定是否是 fetch 请求
            if (e.Request.ResourceType == ResourceType.Xhr || e.Request.Url.Contains("ProListInMyCart"))
            {
                var request = e.Request;
                var headers = request.Headers;
                headers["HeaderKey"] = "新HeaderValue";
                headers.Add("NewKey", "NewKey0");

                await e.Request.ContinueAsync(new Payload() //导致一直"pending"
                {
                    HasPostData = request.HasPostData,
                    Headers = request.Headers,
                    Method = request.Method,
                    PostData = request.PostData.ToString(),
                    Url = request.Url
                });

                //await e.Request.ContinueAsync(); //正常使用
            }
        }
kblok commented 2 weeks ago

You need to ContinueAsync outside the if block as well.