Skip to content

Add customization for web driver. #944

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 3 commits into from
Mar 14, 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 @@ -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;

Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ public async Task<BrowserActionResult> GoToPage(MessageInfo message, PageActionA

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');
Expand Down Expand Up @@ -48,7 +55,6 @@ await page.EvaluateAsync(@"() => {

// Active current tab
await page.BringToFrontAsync();

var response = await page.GotoAsync(args.Url, new PageGotoOptions
{
Timeout = args.Timeout > 0 ? args.Timeout : 30000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public async Task<bool> Execute(RoleDialogModel message)
args.Timeout = _webDriver.DefaultTimeout;
args.WaitForNetworkIdle = false;
args.WaitTime = _webDriver.DefaultWaitTime;
args.OpenNewTab = true;

var conv = _services.GetRequiredService<IConversationService>();

Expand All @@ -38,7 +37,10 @@ public async Task<bool> Execute(RoleDialogModel message)
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
Loading