Skip to content

Commit a3aeab5

Browse files
authored
Merge pull request #953 from visagang/features/vguruparan
Update web driver functionalities
2 parents 0bba5a9 + 0b53c14 commit a3aeab5

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

src/Infrastructure/BotSharp.Abstraction/Browsing/Models/PageActionArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class PageActionArgs
2020
public bool OpenNewTab { get; set; } = true;
2121
[JsonPropertyName("open_blank_page")]
2222
public bool OpenBlankPage { get; set; } = true;
23-
23+
[JsonPropertyName("enable_response_callback")]
2424
public bool EnableResponseCallback { get; set; } = false;
2525

2626
/// <summary>

src/Infrastructure/BotSharp.Abstraction/Browsing/Models/WebPageResponseData.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,20 @@ public class WebPageResponseData
77
public string ResponseData { get; set; } = null!;
88
public bool ResponseInMemory { get; set; }
99
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
10+
public string Method { get; set; }
11+
public List<WebPageCookieData> Cookies { get; set; }
12+
public int ResponseCode { get; set; }
1013

1114
public override string ToString()
1215
{
1316
return $"{Url} {ResponseData.Length}";
1417
}
1518
}
19+
public class WebPageCookieData
20+
{
21+
public string Name { get; set; } = null!;
22+
public string Value { get; set; } = null!;
23+
public string Domain { get; set; } = null!;
24+
public string Path { get; set; } = null!;
25+
public float Expires { get; set; }
26+
}

src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Azure;
22
using BotSharp.Abstraction.Browsing.Settings;
3+
using Microsoft.Playwright;
34
using System.IO;
45

56
namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
@@ -131,7 +132,6 @@ public async Task<IPage> NewPage(MessageInfo message, PageActionArgs args)
131132
{
132133
return page;
133134
}
134-
135135
page.Request += async (sender, e) =>
136136
{
137137
await HandleFetchRequest(e, message, args);
@@ -154,7 +154,7 @@ public async Task HandleFetchRequest(IRequest request, MessageInfo message, Page
154154

155155
public async Task HandleFetchResponse(IResponse response, MessageInfo message, PageActionArgs args)
156156
{
157-
if (response.Status != 204 &&
157+
if (response.Status != 204 && response.Status != 302 &&
158158
response.Headers.ContainsKey("content-type") &&
159159
(response.Request.ResourceType == "fetch" || response.Request.ResourceType == "xhr") &&
160160
(args.ExcludeResponseUrls == null || !args.ExcludeResponseUrls.Any(url => response.Url.ToLower().Contains(url))) &&
@@ -164,11 +164,23 @@ public async Task HandleFetchResponse(IResponse response, MessageInfo message, P
164164

165165
try
166166
{
167+
var context = await GetContext(message.ContextId);
168+
var cookies = await context.CookiesAsync(new string[] { response.Url });
167169
var result = new WebPageResponseData
168170
{
169171
Url = response.Url.ToLower(),
170172
PostData = response.Request?.PostData ?? string.Empty,
171-
ResponseInMemory = args.ResponseInMemory
173+
ResponseInMemory = args.ResponseInMemory,
174+
Method = response.Request.Method,
175+
ResponseCode = response.Status,
176+
Cookies = cookies.Select(x => new WebPageCookieData
177+
{
178+
Name = x.Name,
179+
Value = x.Value,
180+
Domain = x.Domain,
181+
Path = x.Path,
182+
Expires = x.Expires
183+
}).ToList()
172184
};
173185

174186
var html = await response.TextAsync();

src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-go_to_page.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
"open_blank_page": {
1616
"type": "boolean",
1717
"description": "Open blank page"
18+
},
19+
"enable_response_callback": {
20+
"type": "boolean",
21+
"description": "Enable response callback"
1822
}
1923
},
2024
"required": [ "url" ]

0 commit comments

Comments
 (0)