Skip to content

Commit 9a9c1a3

Browse files
author
Haiping Chen
committed
Merge branch 'master' of https://github.com/hchen2020/BotSharp
2 parents ace2e90 + c028593 commit 9a9c1a3

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ public class PageActionArgs
1616
/// <summary>
1717
/// This value has to be set to true if you want to get the page XHR/ Fetch responses
1818
/// </summary>
19-
public bool OpenNewTab { get; set; } = false;
19+
[JsonPropertyName("open_new_tab")]
20+
public bool OpenNewTab { get; set; } = true;
21+
[JsonPropertyName("open_blank_page")]
22+
public bool OpenBlankPage { get; set; } = true;
2023

2124
public bool EnableResponseCallback { get; set; } = false;
2225

@@ -47,4 +50,6 @@ public class PageActionArgs
4750
public int WaitTime { get; set; }
4851

4952
public bool ReadInnerHTMLAsBody { get; set; } = false;
53+
[JsonPropertyName("keep_browser_open")]
54+
public bool KeepBrowserOpen { get; set; } = false;
5055
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ public async Task<BrowserActionResult> GoToPage(MessageInfo message, PageActionA
1515

1616
if (page != null)
1717
{
18-
if (page.Url != "about:blank")
18+
if (!args.OpenBlankPage)
19+
{
20+
if (!_instance.Pages[message.ContextId].Contains(page))
21+
{
22+
_instance.Pages[message.ContextId].Add(page);
23+
}
24+
}
25+
if (args.OpenBlankPage && page.Url != "about:blank")
1926
{
2027
await page.EvaluateAsync(@"() => {
2128
window.open('', '_blank');
@@ -48,7 +55,6 @@ await page.EvaluateAsync(@"() => {
4855

4956
// Active current tab
5057
await page.BringToFrontAsync();
51-
5258
var response = await page.GotoAsync(args.Url, new PageGotoOptions
5359
{
5460
Timeout = args.Timeout > 0 ? args.Timeout : 30000

src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebGoToPageFn.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public async Task<bool> Execute(RoleDialogModel message)
2727
args.Timeout = _webDriver.DefaultTimeout;
2828
args.WaitForNetworkIdle = false;
2929
args.WaitTime = _webDriver.DefaultWaitTime;
30-
args.OpenNewTab = true;
3130

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

@@ -38,7 +37,10 @@ public async Task<bool> Execute(RoleDialogModel message)
3837
MessageId = message.MessageId,
3938
ContextId = message.CurrentAgentId,
4039
};
41-
await browser.CloseCurrentPage(msg);
40+
if (!args.KeepBrowserOpen)
41+
{
42+
await browser.CloseCurrentPage(msg);
43+
}
4244
var result = await browser.GoToPage(msg, args);
4345
if (!result.IsSuccess)
4446
{

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
"url": {
88
"type": "string",
99
"description": "Web URL"
10+
},
11+
"open_new_tab": {
12+
"type": "boolean",
13+
"description": "Open new tab"
14+
},
15+
"open_blank_page": {
16+
"type": "boolean",
17+
"description": "Open blank page"
1018
}
1119
},
1220
"required": [ "url" ]

0 commit comments

Comments
 (0)