support xhr response.

This commit is contained in:
Haiping Chen 2024-07-20 19:57:54 -05:00
parent 37fbd6d636
commit e103cb86cb
2 changed files with 4 additions and 4 deletions

View file

@ -21,4 +21,4 @@ public class PageActionArgs
public DataFetched? OnDataFetched { get; set; }
}
public delegate void DataFetched(string url, string data);
public delegate void DataFetched(string url, string postData, string responsData);

View file

@ -109,9 +109,9 @@ public class PlaywrightInstance : IDisposable
{
if (e.Headers.ContainsKey("content-type") &&
e.Headers["content-type"].Contains("application/json") &&
e.Request.ResourceType == "fetch")
(e.Request.ResourceType == "fetch" || e.Request.ResourceType == "xhr"))
{
Serilog.Log.Information($"fetched: {e.Url}");
Serilog.Log.Information($"{e.Request.Method}: {e.Url}");
JsonElement? json = null;
try
{
@ -123,7 +123,7 @@ public class PlaywrightInstance : IDisposable
{
Serilog.Log.Warning($"Response status: {e.Status} {e.StatusText}, OK: {e.Ok}");
}
fetched(e.Url.ToLower(), JsonSerializer.Serialize(json));
fetched(e.Url.ToLower(), e.Request?.PostData ?? string.Empty, JsonSerializer.Serialize(json));
}
catch(Exception ex)
{