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

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

Open phoenix1630 opened this issue 1 year ago • 1 comments

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(); //正常使用
            }
        }

phoenix1630 avatar Sep 07 '24 09:09 phoenix1630

You need to ContinueAsync outside the if block as well.

kblok avatar Sep 13 '24 23:09 kblok