Merge pull request #953 from visagang/features/vguruparan

Update web driver functionalities
This commit is contained in:
Haiping 2025-03-18 15:20:09 -05:00 committed by GitHub
commit a3aeab5a83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 4 deletions

View file

@ -20,7 +20,7 @@ public class PageActionArgs
public bool OpenNewTab { get; set; } = true;
[JsonPropertyName("open_blank_page")]
public bool OpenBlankPage { get; set; } = true;
[JsonPropertyName("enable_response_callback")]
public bool EnableResponseCallback { get; set; } = false;
/// <summary>

View file

@ -7,9 +7,20 @@ public class WebPageResponseData
public string ResponseData { get; set; } = null!;
public bool ResponseInMemory { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public string Method { get; set; }
public List<WebPageCookieData> Cookies { get; set; }
public int ResponseCode { get; set; }
public override string ToString()
{
return $"{Url} {ResponseData.Length}";
}
}
public class WebPageCookieData
{
public string Name { get; set; } = null!;
public string Value { get; set; } = null!;
public string Domain { get; set; } = null!;
public string Path { get; set; } = null!;
public float Expires { get; set; }
}

View file

@ -1,5 +1,6 @@
using Azure;
using BotSharp.Abstraction.Browsing.Settings;
using Microsoft.Playwright;
using System.IO;
namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
@ -131,7 +132,6 @@ public class PlaywrightInstance : IDisposable
{
return page;
}
page.Request += async (sender, e) =>
{
await HandleFetchRequest(e, message, args);
@ -154,7 +154,7 @@ public class PlaywrightInstance : IDisposable
public async Task HandleFetchResponse(IResponse response, MessageInfo message, PageActionArgs args)
{
if (response.Status != 204 &&
if (response.Status != 204 && response.Status != 302 &&
response.Headers.ContainsKey("content-type") &&
(response.Request.ResourceType == "fetch" || response.Request.ResourceType == "xhr") &&
(args.ExcludeResponseUrls == null || !args.ExcludeResponseUrls.Any(url => response.Url.ToLower().Contains(url))) &&
@ -164,11 +164,23 @@ public class PlaywrightInstance : IDisposable
try
{
var context = await GetContext(message.ContextId);
var cookies = await context.CookiesAsync(new string[] { response.Url });
var result = new WebPageResponseData
{
Url = response.Url.ToLower(),
PostData = response.Request?.PostData ?? string.Empty,
ResponseInMemory = args.ResponseInMemory
ResponseInMemory = args.ResponseInMemory,
Method = response.Request.Method,
ResponseCode = response.Status,
Cookies = cookies.Select(x => new WebPageCookieData
{
Name = x.Name,
Value = x.Value,
Domain = x.Domain,
Path = x.Path,
Expires = x.Expires
}).ToList()
};
var html = await response.TextAsync();

View file

@ -15,6 +15,10 @@
"open_blank_page": {
"type": "boolean",
"description": "Open blank page"
},
"enable_response_callback": {
"type": "boolean",
"description": "Enable response callback"
}
},
"required": [ "url" ]