Merge pull request #944 from visagang/features/vguruparan

Add customization for web driver.
This commit is contained in:
Haiping 2025-03-14 14:49:42 -05:00 committed by GitHub
commit c028593ce4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 26 additions and 5 deletions

View file

@ -16,7 +16,10 @@ public class PageActionArgs
/// <summary>
/// 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;
[JsonPropertyName("open_new_tab")]
public bool OpenNewTab { get; set; } = true;
[JsonPropertyName("open_blank_page")]
public bool OpenBlankPage { get; set; } = true;
public bool EnableResponseCallback { get; set; } = false;
@ -47,4 +50,6 @@ public class PageActionArgs
public int WaitTime { get; set; }
public bool ReadInnerHTMLAsBody { get; set; } = false;
[JsonPropertyName("keep_browser_open")]
public bool KeepBrowserOpen { get; set; } = false;
}

View file

@ -15,7 +15,14 @@ public partial class PlaywrightWebDriver
if (page != null)
{
if (page.Url != "about:blank")
if (!args.OpenBlankPage)
{
if (!_instance.Pages[message.ContextId].Contains(page))
{
_instance.Pages[message.ContextId].Add(page);
}
}
if (args.OpenBlankPage && page.Url != "about:blank")
{
await page.EvaluateAsync(@"() => {
window.open('', '_blank');
@ -48,7 +55,6 @@ public partial class PlaywrightWebDriver
// Active current tab
await page.BringToFrontAsync();
var response = await page.GotoAsync(args.Url, new PageGotoOptions
{
Timeout = args.Timeout > 0 ? args.Timeout : 30000

View file

@ -27,7 +27,6 @@ public class UtilWebGoToPageFn : IFunctionCallback
args.Timeout = _webDriver.DefaultTimeout;
args.WaitForNetworkIdle = false;
args.WaitTime = _webDriver.DefaultWaitTime;
args.OpenNewTab = true;
var conv = _services.GetRequiredService<IConversationService>();
@ -38,7 +37,10 @@ public class UtilWebGoToPageFn : IFunctionCallback
MessageId = message.MessageId,
ContextId = message.CurrentAgentId,
};
await browser.CloseCurrentPage(msg);
if (!args.KeepBrowserOpen)
{
await browser.CloseCurrentPage(msg);
}
var result = await browser.GoToPage(msg, args);
if (!result.IsSuccess)
{

View file

@ -7,6 +7,14 @@
"url": {
"type": "string",
"description": "Web URL"
},
"open_new_tab": {
"type": "boolean",
"description": "Open new tab"
},
"open_blank_page": {
"type": "boolean",
"description": "Open blank page"
}
},
"required": [ "url" ]