Skip to content

Commit a16602a

Browse files
committed
Add ExcludeResponseUrls to PageActionArgs
1 parent af83304 commit a16602a

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public class PageActionArgs
1515
/// This value has to be set to true if you want to get the page XHR/ Fetch responses
1616
/// </summary>
1717
public bool OpenNewTab { get; set; } = false;
18+
/// <summary>
19+
/// Exclude urls for XHR/ Fetch responses
20+
/// </summary>
21+
public string[]? ExcludeResponseUrls { get; set; }
1822
public bool UseExistingPage { get; set; } = false;
1923

2024
public bool WaitForNetworkIdle { get; set; } = true;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public async Task<IBrowserContext> InitContext(string ctxId, BrowserActionArgs a
113113
return _contexts[ctxId];
114114
}
115115

116-
public async Task<IPage> NewPage(MessageInfo message)
116+
public async Task<IPage> NewPage(MessageInfo message, string[]? excludeResponseUrls = null)
117117
{
118118
var context = await GetContext(message.ContextId);
119119
var page = await context.NewPageAsync();
@@ -128,7 +128,8 @@ public async Task<IPage> NewPage(MessageInfo message)
128128
if (e.Status != 204 &&
129129
e.Headers.ContainsKey("content-type") &&
130130
e.Headers["content-type"].Contains("application/json") &&
131-
(e.Request.ResourceType == "fetch" || e.Request.ResourceType == "xhr"))
131+
(e.Request.ResourceType == "fetch" || e.Request.ResourceType == "xhr") &&
132+
(excludeResponseUrls == null || !excludeResponseUrls.Any(url => e.Url.ToLower().Contains(url))))
132133
{
133134
Serilog.Log.Information($"{e.Request.Method}: {e.Url}");
134135
JsonElement? json = null;

src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.GoToPage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public async Task<BrowserActionResult> GoToPage(MessageInfo message, PageActionA
1010
{
1111
var page = args.UseExistingPage ?
1212
_instance.GetPage(message.ContextId, pattern: args.Url) :
13-
await _instance.NewPage(message);
13+
await _instance.NewPage(message, excludeResponseUrls: args.ExcludeResponseUrls);
1414

1515
if (args.UseExistingPage && page != null && page.Url != "about:blank")
1616
{
@@ -23,7 +23,7 @@ public async Task<BrowserActionResult> GoToPage(MessageInfo message, PageActionA
2323

2424
if (args.UseExistingPage && args.OpenNewTab && page != null && page.Url == "about:blank")
2525
{
26-
page = await _instance.NewPage(message);
26+
page = await _instance.NewPage(message, excludeResponseUrls: args.ExcludeResponseUrls);
2727
}
2828

2929
var response = await page.GotoAsync(args.Url, new PageGotoOptions

0 commit comments

Comments
 (0)