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

35 lines
1.1 KiB
C#
Raw Normal View History

2024-02-01 03:29:13 +00:00
namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
public partial class PlaywrightWebDriver
{
2024-03-08 13:17:36 +00:00
public async Task<BrowserActionResult> GoToPage(string conversationId, string url)
2024-02-01 03:29:13 +00:00
{
2024-03-08 13:17:36 +00:00
var result = new BrowserActionResult();
2024-02-10 18:14:18 +00:00
try
{
var response = await _instance.GetPage(conversationId).GotoAsync(url);
await _instance.GetPage(conversationId).WaitForLoadStateAsync(LoadState.DOMContentLoaded);
await _instance.GetPage(conversationId).WaitForLoadStateAsync(LoadState.NetworkIdle);
2024-02-10 18:14:18 +00:00
2024-03-08 13:17:36 +00:00
if (response.Status == 200)
{
var page = _instance.GetPage(conversationId);
result.Body = await page.ContentAsync();
result.IsSuccess = true;
}
else
{
2024-04-08 15:09:08 +00:00
result.Message = response.StatusText;
2024-03-08 13:17:36 +00:00
}
2024-02-10 18:14:18 +00:00
}
catch (Exception ex)
{
2024-04-08 15:09:08 +00:00
result.Message = ex.Message;
2024-03-08 13:17:36 +00:00
result.StackTrace = ex.StackTrace;
2024-02-10 18:14:18 +00:00
_logger.LogError(ex.Message);
}
2024-03-08 13:17:36 +00:00
return result;
2024-02-01 03:29:13 +00:00
}
}