Skip to content

Update web driver functionalities #953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Azure;
using BotSharp.Abstraction.Browsing.Settings;
using Microsoft.Playwright;
using System.IO;

namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
Expand Down Expand Up @@ -131,7 +132,6 @@ public async Task<IPage> NewPage(MessageInfo message, PageActionArgs args)
{
return page;
}

page.Request += async (sender, e) =>
{
await HandleFetchRequest(e, message, args);
Expand All @@ -154,7 +154,7 @@ public async Task HandleFetchRequest(IRequest request, MessageInfo message, Page

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))) &&
Expand All @@ -164,11 +164,23 @@ public async Task HandleFetchResponse(IResponse response, MessageInfo message, P

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"open_blank_page": {
"type": "boolean",
"description": "Open blank page"
},
"enable_response_callback": {
"type": "boolean",
"description": "Enable response callback"
}
},
"required": [ "url" ]
Expand Down
Loading