From e103cb86cb33b5b68909143e8e9de345e170d88a Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Sat, 20 Jul 2024 19:57:54 -0500 Subject: [PATCH] support xhr response. --- .../BotSharp.Abstraction/Browsing/Models/PageActionArgs.cs | 2 +- .../Drivers/PlaywrightDriver/PlaywrightInstance.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/PageActionArgs.cs b/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/PageActionArgs.cs index 8bf09cb1..0698194e 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/PageActionArgs.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/PageActionArgs.cs @@ -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); diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs index a1716929..ef487366 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs @@ -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) {