Add ExcludeResponseUrls to PageActionArgs

This commit is contained in:
Haiping Chen 2024-08-04 22:46:41 -05:00
parent af833048fd
commit a16602a4fd
3 changed files with 9 additions and 4 deletions

View file

@ -15,6 +15,10 @@ public class PageActionArgs
/// This value has to be set to true if you want to get the page XHR/ Fetch responses
/// </summary>
public bool OpenNewTab { get; set; } = false;
/// <summary>
/// Exclude urls for XHR/ Fetch responses
/// </summary>
public string[]? ExcludeResponseUrls { get; set; }
public bool UseExistingPage { get; set; } = false;
public bool WaitForNetworkIdle { get; set; } = true;

View file

@ -113,7 +113,7 @@ public class PlaywrightInstance : IDisposable
return _contexts[ctxId];
}
public async Task<IPage> NewPage(MessageInfo message)
public async Task<IPage> NewPage(MessageInfo message, string[]? excludeResponseUrls = null)
{
var context = await GetContext(message.ContextId);
var page = await context.NewPageAsync();
@ -128,7 +128,8 @@ public class PlaywrightInstance : IDisposable
if (e.Status != 204 &&
e.Headers.ContainsKey("content-type") &&
e.Headers["content-type"].Contains("application/json") &&
(e.Request.ResourceType == "fetch" || e.Request.ResourceType == "xhr"))
(e.Request.ResourceType == "fetch" || e.Request.ResourceType == "xhr") &&
(excludeResponseUrls == null || !excludeResponseUrls.Any(url => e.Url.ToLower().Contains(url))))
{
Serilog.Log.Information($"{e.Request.Method}: {e.Url}");
JsonElement? json = null;

View file

@ -10,7 +10,7 @@ public partial class PlaywrightWebDriver
{
var page = args.UseExistingPage ?
_instance.GetPage(message.ContextId, pattern: args.Url) :
await _instance.NewPage(message);
await _instance.NewPage(message, excludeResponseUrls: args.ExcludeResponseUrls);
if (args.UseExistingPage && page != null && page.Url != "about:blank")
{
@ -23,7 +23,7 @@ public partial class PlaywrightWebDriver
if (args.UseExistingPage && args.OpenNewTab && page != null && page.Url == "about:blank")
{
page = await _instance.NewPage(message);
page = await _instance.NewPage(message, excludeResponseUrls: args.ExcludeResponseUrls);
}
var response = await page.GotoAsync(args.Url, new PageGotoOptions