Remove openIfNotExist from LaunchBrowser

This commit is contained in:
Haiping Chen 2024-05-28 22:44:49 -05:00
parent 9213c7fa5b
commit e9ae471a65
5 changed files with 22 additions and 6 deletions

View file

@ -4,7 +4,7 @@ namespace BotSharp.Abstraction.Browsing;
public interface IWebBrowser
{
Task<BrowserActionResult> LaunchBrowser(string contextId, string? url, bool openIfNotExist = true);
Task<BrowserActionResult> LaunchBrowser(string contextId, string? url);
Task<BrowserActionResult> ScreenshotAsync(string contextId, string path);
Task<BrowserActionResult> ScrollPageAsync(BrowserActionParams actionParams);

View file

@ -5,13 +5,29 @@ public partial class PlaywrightWebDriver
public async Task<BrowserActionResult> GoToPage(string contextId, string url, bool openNewTab = false)
{
var result = new BrowserActionResult();
var context = await _instance.InitInstance(contextId);
try
{
// Check if the page is already open
foreach (var p in context.Pages)
{
if (p.Url == url)
{
result.Body = await p.ContentAsync();
result.IsSuccess = true;
await p.BringToFrontAsync();
return result;
}
}
var page = openNewTab ? await _instance.NewPage(contextId) :
_instance.GetPage(contextId);
var response = await page.GotoAsync(url);
await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
await page.WaitForLoadStateAsync(LoadState.NetworkIdle, new PageWaitForLoadStateOptions
{
Timeout = 1000 * 60 * 5
});
if (response.Status == 200)
{

View file

@ -2,7 +2,7 @@ namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
public partial class PlaywrightWebDriver
{
public async Task<BrowserActionResult> LaunchBrowser(string contextId, string? url, bool openIfNotExist = true)
public async Task<BrowserActionResult> LaunchBrowser(string contextId, string? url)
{
var result = new BrowserActionResult()
{

View file

@ -87,8 +87,8 @@ public partial class PlaywrightWebDriver
await locator.EvaluateAsync("element => element.style.opacity = '1.0'");
}*/
var text = await locator.InnerTextAsync();
result.Body = text;
var html = await locator.InnerHTMLAsync();
result.Body = html;
result.IsSuccess = true;
}
else if (count > 1)

View file

@ -2,7 +2,7 @@ namespace BotSharp.Plugin.WebDriver.Drivers.SeleniumDriver;
public partial class SeleniumWebDriver
{
public async Task<BrowserActionResult> LaunchBrowser(string contextId, string? url, bool openIfNotExist = true)
public async Task<BrowserActionResult> LaunchBrowser(string contextId, string? url)
{
var result = new BrowserActionResult()
{