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

41 lines
1.1 KiB
C#
Raw Normal View History

2024-02-10 18:14:18 +00:00
using Microsoft.Extensions.Logging;
2024-01-03 19:40:41 +00:00
namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
public partial class PlaywrightWebDriver
{
2024-02-10 18:14:18 +00:00
public async Task<bool> LaunchBrowser(string? url)
2024-01-03 19:40:41 +00:00
{
2024-01-06 03:24:13 +00:00
await _instance.InitInstance();
2024-01-03 19:40:41 +00:00
if (!string.IsNullOrEmpty(url))
{
var page = _instance.Context.Pages.LastOrDefault();
if (page == null)
2024-01-06 22:24:22 +00:00
{
page = await _instance.Context.NewPageAsync();
}
if (!string.IsNullOrEmpty(url))
{
2024-02-10 18:14:18 +00:00
try
{
2024-02-10 18:14:18 +00:00
var response = await page.GotoAsync(url, new PageGotoOptions
{
Timeout = 15 * 1000
});
await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);
return response.Status == 200;
}
catch(Exception ex)
{
_logger.LogError(ex.Message);
}
return false;
}
2024-01-03 19:40:41 +00:00
}
2024-02-10 18:14:18 +00:00
return true;
2024-01-03 19:40:41 +00:00
}
}